diff --git a/extensions/npm/src/npmMain.ts b/extensions/npm/src/npmMain.ts index a92f554b7592418a9ecd5c15ef4992016079a0f2..fc0f8a5c557307186913e24e28ccfe3fafb479c7 100644 --- a/extensions/npm/src/npmMain.ts +++ b/extensions/npm/src/npmMain.ts @@ -13,6 +13,14 @@ import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHov let treeDataProvider: NpmScriptsTreeDataProvider | undefined; +function invalidateScriptCaches() { + invalidateHoverScriptsCache(); + invalidateTasksCache(); + if (treeDataProvider) { + treeDataProvider.refresh(); + } +} + export async function activate(context: vscode.ExtensionContext): Promise { configureHttpRequest(); context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => { @@ -45,6 +53,10 @@ export async function activate(context: vscode.ExtensionContext): Promise context.subscriptions.push(vscode.commands.registerCommand('npm.runSelectedScript', runSelectedScript)); context.subscriptions.push(vscode.commands.registerCommand('npm.runScriptFromFolder', selectAndRunScriptFromFolder)); + context.subscriptions.push(vscode.commands.registerCommand('npm.refresh', () => { + invalidateScriptCaches(); + })); + } function canRunNpmInCurrentWorkspace() { @@ -55,15 +67,6 @@ function canRunNpmInCurrentWorkspace() { } function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined { - - function invalidateScriptCaches() { - invalidateHoverScriptsCache(); - invalidateTasksCache(); - if (treeDataProvider) { - treeDataProvider.refresh(); - } - } - if (vscode.workspace.workspaceFolders) { let watcher = vscode.workspace.createFileSystemWatcher('**/package.json'); watcher.onDidChange((_e) => invalidateScriptCaches()); diff --git a/extensions/npm/src/npmView.ts b/extensions/npm/src/npmView.ts index c7c7835fa047054dcb621a5d46bba01ec2098f01..c1145d0806bce5c35e897747b40e07ec70f7b430 100644 --- a/extensions/npm/src/npmView.ts +++ b/extensions/npm/src/npmView.ts @@ -129,7 +129,6 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider { subscriptions.push(commands.registerCommand('npm.runScript', this.runScript, this)); subscriptions.push(commands.registerCommand('npm.debugScript', this.debugScript, this)); subscriptions.push(commands.registerCommand('npm.openScript', this.openScript, this)); - subscriptions.push(commands.registerCommand('npm.refresh', this.refresh, this)); subscriptions.push(commands.registerCommand('npm.runInstall', this.runInstall, this)); }