Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Commit

Permalink
Fix/file not indexed (#58)
Browse files Browse the repository at this point in the history
* fix indexing errors (undefined on new files)

* changelog

* refactoring
  • Loading branch information
buehler committed Sep 21, 2016
1 parent d78edc3 commit 2b36a02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
#### Fixed
- Code completions does show when user types ([#55](https://github.com/buehler/typescript-hero/issues/55))
- Default exports and imports are working ([#40](https://github.com/buehler/typescript-hero/issues/40))
- New created files are correctly indexed now ([#46](https://github.com/buehler/typescript-hero/issues/46))

## [0.7.0]
#### Added
Expand Down
44 changes: 18 additions & 26 deletions src/caches/ResolveIndex.ts
Expand Up @@ -91,21 +91,10 @@ export class ResolveIndex {

public rebuildForFile(filePath: string): Promise<void> {
let rebuildResource = '/' + workspace.asRelativePath(filePath).replace(/[.]tsx?/g, ''),
rebuildFiles = [rebuildResource];
Object
.keys(this.parsedResources)
.filter(o => o.startsWith('/'))
.forEach(key => {
let resource = this.parsedResources[key] as TsFile;
if (this.doesExportResource(resource, rebuildResource)) {
rebuildFiles.push(key);
}
});
rebuildFiles = [<Uri>{ fsPath: filePath }, ...this.getExportedResources(rebuildResource)];

return this.parser
.parseFiles(rebuildFiles.map(o => this.parsedResources[o] as TsFile).map(o => {
return <Uri>{ fsPath: o.filePath };
}))
.parseFiles(rebuildFiles)
.then(parsed => this.parseResources(parsed))
.then(resources => {
for (let key in resources) {
Expand All @@ -120,21 +109,10 @@ export class ResolveIndex {

public removeForFile(filePath: string): Promise<void> {
let removeResource = '/' + workspace.asRelativePath(filePath).replace(/[.]tsx?/g, ''),
rebuildFiles = [];
Object
.keys(this.parsedResources)
.filter(o => o.startsWith('/'))
.forEach(key => {
let resource = this.parsedResources[key] as TsFile;
if (this.doesExportResource(resource, removeResource)) {
rebuildFiles.push(key);
}
});
rebuildFiles = this.getExportedResources(removeResource);

return this.parser
.parseFiles(rebuildFiles.map(o => this.parsedResources[o] as TsFile).map(o => {
return <Uri>{ fsPath: o.filePath };
}))
.parseFiles(rebuildFiles)
.then(parsed => this.parseResources(parsed))
.then(resources => {
delete this.parsedResources[removeResource];
Expand Down Expand Up @@ -335,6 +313,20 @@ export class ResolveIndex {
});
}

private getExportedResources(resourceToCheck: string): Uri[] {
let resources = [];
Object
.keys(this.parsedResources)
.filter(o => o.startsWith('/'))
.forEach(key => {
let resource = this.parsedResources[key] as TsFile;
if (this.doesExportResource(resource, resourceToCheck)) {
resources.push(<Uri>{ fsPath: resource.filePath });
}
});
return resources;
}

private doesExportResource(resource: TsFile, resourcePath: string): boolean {
let exportsResource = false;

Expand Down

0 comments on commit 2b36a02

Please sign in to comment.