Remove files that are not in program from cache of unresolved imports

This commit is contained in:
Sheetal Nandi
2022-07-27 12:16:33 -07:00
parent 71ebed9c00
commit 4d127faa25

View File

@@ -1194,7 +1194,6 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
if (!fileExists) {
this.resolutionCache.invalidateResolutionOfFile(info.path);
}
this.cachedUnresolvedImportsPerFile.delete(info.path);
if (detachFromProject) {
info.detachFromProject(this);
@@ -2082,6 +2081,12 @@ function getUnresolvedImports(program: Program, cachedUnresolvedImportsPerFile:
const ambientModules = program.getTypeChecker().getAmbientModules().map(mod => stripQuotes(mod.getName()));
const result = sortAndDeduplicate(flatMap(sourceFiles, sourceFile =>
extractUnresolvedImportsFromSourceFile(sourceFile, ambientModules, cachedUnresolvedImportsPerFile)));
// Remove files from the cache if they arent in program
if (cachedUnresolvedImportsPerFile.size !== program.getSourceFiles().length) {
cachedUnresolvedImportsPerFile.forEach((_value, key) => {
if (!program.getSourceFileByPath(key)) cachedUnresolvedImportsPerFile.delete(key);
});
}
tracing?.pop();
return result;
}