fix(language-service): Clear caches when program changes (#21337)
This commit fixes a bug whereby the caches are not cleared when the program changes. This subsequently produces the incorrect error of 'Component ... is not included in a module ...'. PR Close #19405 PR Close #21337
This commit is contained in:

committed by
Alex Eagle

parent
d5393c7f91
commit
cc9419d1ca
@ -140,7 +140,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
}
|
||||
|
||||
getAnalyzedModules(): NgAnalyzedModules {
|
||||
this.validate();
|
||||
this.updateAnalyzedModules();
|
||||
return this.ensureAnalyzedModules();
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
|
||||
private validate() {
|
||||
const program = this.program;
|
||||
if (this._staticSymbolResolver && this.lastProgram != program) {
|
||||
if (this.lastProgram !== program) {
|
||||
// Invalidate file that have changed in the static symbol resolver
|
||||
const invalidateFile = (fileName: string) =>
|
||||
this._staticSymbolResolver.invalidateFile(fileName);
|
||||
@ -253,14 +253,18 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
||||
const lastVersion = this.fileVersions.get(fileName);
|
||||
if (version != lastVersion) {
|
||||
this.fileVersions.set(fileName, version);
|
||||
invalidateFile(fileName);
|
||||
if (this._staticSymbolResolver) {
|
||||
invalidateFile(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove file versions that are no longer in the file and invalidate them.
|
||||
const missing = Array.from(this.fileVersions.keys()).filter(f => !seen.has(f));
|
||||
missing.forEach(f => this.fileVersions.delete(f));
|
||||
missing.forEach(invalidateFile);
|
||||
if (this._staticSymbolResolver) {
|
||||
missing.forEach(invalidateFile);
|
||||
}
|
||||
|
||||
this.lastProgram = program;
|
||||
}
|
||||
@ -634,4 +638,4 @@ function convertChain(chain: FormattedMessageChain): DiagnosticMessageChain {
|
||||
|
||||
function errorToDiagnosticWithChain(error: FormattedError, span: Span): DeclarationError {
|
||||
return {message: error.chain ? convertChain(error.chain) : error.message, span};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user