diff --git a/vscode/package.json b/vscode/package.json index ed95c10b..130f4a3b 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -2,7 +2,7 @@ "name": "simplicityhl", "displayName": "SimplicityHL Language Support", "description": "Syntax highlighting and autocompletion for SimplicityHL (Simfony) language", - "version": "0.2.0", + "version": "0.2.1", "publisher": "Blockstream", "repository": { "type": "git", @@ -69,7 +69,14 @@ "description": "Do not show missing LSP executable warning." } } - } + }, + "commands": [ + { + "command": "simplicityhl.restartServer", + "title": "Restart server", + "category": "SimplicityHL" + } + ] }, "license": "MIT", "scripts": { diff --git a/vscode/src/client.ts b/vscode/src/client.ts index 2b4e24b8..975c75b3 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -59,4 +59,19 @@ export class LspClient { } return this.client.stop(); } + + public async restart(): Promise { + if (!this.client) { + window.showWarningMessage("LSP client not initialized. Cannot restart."); + return; + } + + try { + await this.client.stop(); + await this.client.start(); + window.showInformationMessage("SimplicityHL Language Server restarted successfully!"); + } catch (e) { + window.showErrorMessage(`Failed to restart LSP: ${e}`); + } + } } diff --git a/vscode/src/commands.ts b/vscode/src/commands.ts new file mode 100644 index 00000000..5b305056 --- /dev/null +++ b/vscode/src/commands.ts @@ -0,0 +1,16 @@ +import { ExtensionContext, commands } from "vscode"; +import { LspClient } from "./client"; + +export function registerRestartCommand( + context: ExtensionContext, + lspClient: LspClient +) { + const command = commands.registerCommand( + "simplicityhl.restartServer", + async () => { + await lspClient.restart(); + } + ); + + context.subscriptions.push(command); +} diff --git a/vscode/src/extension.ts b/vscode/src/extension.ts index 7cc58bfd..f92b1436 100644 --- a/vscode/src/extension.ts +++ b/vscode/src/extension.ts @@ -1,8 +1,14 @@ import { LspClient } from "./client"; +import { registerRestartCommand } from "./commands" +import { ExtensionContext } from "vscode" + let client: LspClient; -export function activate() { + +export function activate(context: ExtensionContext) { client = new LspClient(); void client.start(); + + registerRestartCommand(context, client); } export function deactivate(): Thenable | undefined { if (!client) {