Flush scripts cache when the document changes

This commit is contained in:
Erich Gamma 2018-07-26 13:57:37 +02:00
parent 62ba096511
commit 7697ef6711
2 changed files with 16 additions and 3 deletions

View file

@ -17,7 +17,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
const hoverProvider = registerHoverProvider(context);
configureHttpRequest();
vscode.workspace.onDidChangeConfiguration((e) => {
let d = vscode.workspace.onDidChangeConfiguration((e) => {
configureHttpRequest();
if (e.affectsConfiguration('npm.exclude')) {
invalidateTasksCache();
@ -31,6 +31,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}
}
});
context.subscriptions.push(d);
d = vscode.workspace.onDidChangeTextDocument((e) => {
invalidateHoverScriptsCache(e.document);
});
context.subscriptions.push(d);
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
}

View file

@ -18,8 +18,14 @@ const localize = nls.loadMessageBundle();
let cachedDocument: Uri | undefined = undefined;
let cachedScriptsMap: Map<string, [number, number, string]> | undefined = undefined;
export function invalidateHoverScriptsCache() {
cachedDocument = undefined;
export function invalidateHoverScriptsCache(document?: TextDocument) {
if (!document) {
cachedDocument = undefined;
return;
}
if (document.uri === cachedDocument) {
cachedDocument = undefined;
}
}
export class NpmScriptHoverProvider implements HoverProvider {