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
This commit is contained in:
parent
53dbff66d7
commit
4f033235b1
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user