Skip to content
Permalink
Browse files

perf(language-service): keep analyzedModules cache when source files …

…don't change (#32562)

This change will improve performance of language service when working in external templates.

PR Close #32562
  • Loading branch information...
andrius-pra authored and matsko committed Sep 9, 2019
1 parent 53dbff6 commit 4f033235b12f60149e3271dd4241bbc6f7b922f9
@@ -275,12 +275,14 @@ export class TypeScriptServiceHost implements LanguageServiceHost {

// Invalidate file that have changed in the static symbol resolver
const seen = new Set<string>();
let hasChanges = false;
for (const sourceFile of program.getSourceFiles()) {
const fileName = sourceFile.fileName;
seen.add(fileName);
const version = this.tsLsHost.getScriptVersion(fileName);
const lastVersion = this.fileVersions.get(fileName);
if (version !== lastVersion) {
hasChanges = true;
this.fileVersions.set(fileName, version);
this.staticSymbolResolver.invalidateFile(fileName);
}
@@ -295,7 +297,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {

this.lastProgram = program;

return false;
return missing.length === 0 && !hasChanges;
}

/**
@@ -148,4 +148,14 @@ describe('TypeScriptServiceHost', () => {
expect(newModules.ngModuleByPipeOrDirective.has(helloComp)).toBe(true);
expect(newModules.ngModuleByPipeOrDirective.has(appComp)).toBe(false);
});

it('should not clear caches when external template changes', () => {
const tsLSHost = new MockTypescriptHost(['/app/main.ts'], toh);
const tsLS = ts.createLanguageService(tsLSHost);
const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS);
const oldModules = ngLSHost.getAnalyzedModules();
tsLSHost.override('/app/test.ng', '<div></div>');
const newModules = ngLSHost.getAnalyzedModules();
expect(newModules).toBe(oldModules);
});
});

0 comments on commit 4f03323

Please sign in to comment.
You can’t perform that action at this time.