fix(language-service): improve performance of updateModuleAnalysis() (#15543)

This commit is contained in:
Chuck Jazdzewski
2017-03-28 13:32:46 -07:00
committed by Victor Berchet
parent d438b88f19
commit 6269d28bb0
3 changed files with 61 additions and 13 deletions

View File

@ -59,6 +59,7 @@ export class StaticSymbolResolver {
// Note: this will only contain StaticSymbols without members!
private importAs = new Map<StaticSymbol, StaticSymbol>();
private symbolResourcePaths = new Map<StaticSymbol, string>();
private symbolFromFile = new Map<string, StaticSymbol[]>();
constructor(
private host: StaticSymbolResolverHost, private staticSymbolCache: StaticSymbolCache,
@ -143,6 +144,25 @@ export class StaticSymbolResolver {
this.importAs.set(sourceSymbol, targetSymbol);
}
/**
* Invalidate all information derived from the given file.
*
* @param fileName the file to invalidate
*/
invalidateFile(fileName: string) {
this.metadataCache.delete(fileName);
this.resolvedFilePaths.delete(fileName);
const symbols = this.symbolFromFile.get(fileName);
if (symbols) {
this.symbolFromFile.delete(fileName);
for (const symbol of symbols) {
this.resolvedSymbols.delete(symbol);
this.importAs.delete(symbol);
this.symbolResourcePaths.delete(symbol);
}
}
}
private _resolveSymbolMembers(staticSymbol: StaticSymbol): ResolvedStaticSymbol {
const members = staticSymbol.members;
const baseResolvedSymbol =
@ -281,6 +301,7 @@ export class StaticSymbolResolver {
}
resolvedSymbols.forEach(
(resolvedSymbol) => this.resolvedSymbols.set(resolvedSymbol.symbol, resolvedSymbol));
this.symbolFromFile.set(filePath, resolvedSymbols.map(resolvedSymbol => resolvedSymbol.symbol));
}
private createResolvedSymbol(