fix(language-service): Recompute analyzed modules only when source files change (#33806)
This commit fixes a bug brought up by @andrius-pra whereby the language service host would recompute the analyzed modules even when none of the source files changes. This is due to a bug in our unit test that precludes non-TS files from incrementing the project version. Consequently, when the external template is updated, the program remains the same. With the bug fixed, the next step is to figure out if any source files have been added / changed / removed since the last computation. The previously analyzed could be safely retained only when none of these operations happen. PR Close #33806
This commit is contained in:

committed by
Alex Rickabaugh

parent
0688a28be3
commit
9882a8215a
@ -114,9 +114,7 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
|
||||
|
||||
override(fileName: string, content: string) {
|
||||
this.scriptVersion.set(fileName, (this.scriptVersion.get(fileName) || 0) + 1);
|
||||
if (fileName.endsWith('.ts')) {
|
||||
this.projectVersion++;
|
||||
}
|
||||
this.projectVersion++;
|
||||
if (content) {
|
||||
this.overrides.set(fileName, content);
|
||||
this.overrideDirectory.add(path.dirname(fileName));
|
||||
|
@ -50,7 +50,7 @@ describe('TypeScriptServiceHost', () => {
|
||||
expect(analyzedModules.files.length).toBe(0);
|
||||
expect(analyzedModules.ngModules.length).toBe(0);
|
||||
expect(analyzedModules.ngModuleByPipeOrDirective.size).toBe(0);
|
||||
expect(analyzedModules.symbolsMissingModule).toEqual([]);
|
||||
expect(analyzedModules.symbolsMissingModule).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should clear the caches if new script is added', () => {
|
||||
@ -166,8 +166,14 @@ describe('TypeScriptServiceHost', () => {
|
||||
const tsLS = ts.createLanguageService(tsLSHost);
|
||||
const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS);
|
||||
const oldModules = ngLSHost.getAnalyzedModules();
|
||||
const oldProgram = ngLSHost.program;
|
||||
tsLSHost.override('/app/test.ng', '<div></div>');
|
||||
const newModules = ngLSHost.getAnalyzedModules();
|
||||
const newProgram = ngLSHost.program;
|
||||
// Assert that the program has changed because external template was updated
|
||||
expect(newProgram).not.toBe(oldProgram);
|
||||
// But, analyzed modules should remain the same because none of the source
|
||||
// files have changed.
|
||||
expect(newModules).toBe(oldModules);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user