From ae95eefd8f2ecb2bfda368a3c19a7d29a5c3a0a7 Mon Sep 17 00:00:00 2001 From: LEE Juchan Date: Wed, 14 May 2025 00:35:36 +0900 Subject: [PATCH] Add workspace clean command to invalidate classpath cache --- package.json | 5 +++++ src/languageSetup.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/package.json b/package.json index de08255..0f81342 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,11 @@ "command": "kotlin.overrideMember", "title": "Override member(s)", "category": "Kotlin" + }, + { + "command": "kotlin.clean.workspace", + "title": "Clean Kotlin Language Server workspace", + "category": "Kotlin" } ], "menus": { diff --git a/src/languageSetup.ts b/src/languageSetup.ts index a2afbd3..54a21ef 100644 --- a/src/languageSetup.ts +++ b/src/languageSetup.ts @@ -131,6 +131,24 @@ export async function activateLanguageServer({ context, status, config, javaInst }); }); + vscode.commands.registerCommand("kotlin.clean.workspace", async (force?: boolean) => { + if (!force) { + const message = 'Are you sure you want to clean the Kotlin language server workspace?'; + const cancel = 'Cancel'; + const doIt = 'Reload and delete'; + const selection = await vscode.window.showWarningMessage(message, cancel, doIt); + if (selection !== doIt) { // user cancelled + return; + } + } + + // remove the workspace + fs.rmdirSync(storagePath, { recursive: true }); + + // reload the window + vscode.commands.executeCommand("workbench.action.reloadWindow"); + }); + // Activating run/debug code lens if the debug adapter is enabled // and we are using 'kotlin-language-server' (other language servers // might not support the non-standard 'kotlin/mainClass' request)