From 8c6600fbd7ef1a23700673dca5e945ed2e1c7c27 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Tue, 20 Aug 2024 13:25:14 -0400 Subject: [PATCH] Add language server menu option for clearing cached packages --- src/LanguageServerManager.spec.ts | 2 +- src/commands/ClearNpmPackageCacheCommand.ts | 4 ++-- src/commands/LanguageServerInfoCommand.ts | 9 +++++++++ src/commands/VscodeCommand.ts | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/LanguageServerManager.spec.ts b/src/LanguageServerManager.spec.ts index 913811b7..af419aa5 100644 --- a/src/LanguageServerManager.spec.ts +++ b/src/LanguageServerManager.spec.ts @@ -401,7 +401,7 @@ describe('LanguageServerManager', () => { describe('clearNpmPackageCache', () => { it('clears the cache', async () => { - fsExtra.ensureFileSync(`${storageDir}/test.txt`); + fsExtra.ensureFileSync(`${storageDir}/packages/test.txt`); expect(fsExtra.pathExistsSync(`${storageDir}/packages/test.txt`)).to.be.true; await languageServerManager.clearNpmPackageCache(); diff --git a/src/commands/ClearNpmPackageCacheCommand.ts b/src/commands/ClearNpmPackageCacheCommand.ts index 4a60ab69..2f30ee9b 100644 --- a/src/commands/ClearNpmPackageCacheCommand.ts +++ b/src/commands/ClearNpmPackageCacheCommand.ts @@ -1,11 +1,11 @@ import * as vscode from 'vscode'; import type { LanguageServerManager } from '../LanguageServerManager'; +import { VscodeCommand } from './VscodeCommand'; export class ClearNpmPackageCacheCommand { - public static commandName = 'extension.brightscript.clearNpmPackageCache'; public register(context: vscode.ExtensionContext, languageServerManager: LanguageServerManager) { - context.subscriptions.push(vscode.commands.registerCommand(ClearNpmPackageCacheCommand.commandName, async () => { + context.subscriptions.push(vscode.commands.registerCommand(VscodeCommand.clearNpmPackageCache, async () => { await languageServerManager.clearNpmPackageCache(); })); } diff --git a/src/commands/LanguageServerInfoCommand.ts b/src/commands/LanguageServerInfoCommand.ts index b11feb15..f9418834 100644 --- a/src/commands/LanguageServerInfoCommand.ts +++ b/src/commands/LanguageServerInfoCommand.ts @@ -7,6 +7,8 @@ import * as childProcess from 'child_process'; import { firstBy } from 'thenby'; import * as dayjs from 'dayjs'; import * as relativeTime from 'dayjs/plugin/relativeTime'; +import { util } from '../util'; +import { VscodeCommand } from './VscodeCommand'; dayjs.extend(relativeTime); export class LanguageServerInfoCommand { @@ -26,6 +28,13 @@ export class LanguageServerInfoCommand { label: `View language server logs`, description: ``, command: this.focusLanguageServerOutputChannel.bind(this) + }, { + label: `Delete cached brighterscript versions`, + description: ``, + command: async () => { + await vscode.commands.executeCommand(VscodeCommand.clearNpmPackageCache); + await vscode.window.showInformationMessage('All cached brighterscript versions have been removed'); + } }]; let selection = await vscode.window.showQuickPick(commands, { placeHolder: `BrighterScript Project Info` }); diff --git a/src/commands/VscodeCommand.ts b/src/commands/VscodeCommand.ts index 2b1c9aa4..15bb8d8f 100644 --- a/src/commands/VscodeCommand.ts +++ b/src/commands/VscodeCommand.ts @@ -19,5 +19,6 @@ export enum VscodeCommand { rokuAppOverlaysViewRemoveAllOverlays = 'extension.brightscript.rokuAppOverlaysView.removeAllOverlays', rokuFileSystemViewRefresh = 'extension.brightscript.rokuFileSystemView.refresh', disconnectFromDevice = 'extension.brightscript.disconnectFromDevice', - openSceneGraphInspectorInPanel = 'extension.brightscript.openSceneGraphInspectorInPanel' + openSceneGraphInspectorInPanel = 'extension.brightscript.openSceneGraphInspectorInPanel', + clearNpmPackageCache = 'extension.brightscript.clearNpmPackageCache' }