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)