Skip to content

Commit 9aa29b1

Browse files
authored
Merge pull request BlockstreamResearch#168 from distributed-lab/vscode/command
Add "Restart Server" command to VSCode extension
2 parents b6ef79b + 068d2c6 commit 9aa29b1

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

vscode/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "simplicityhl",
33
"displayName": "SimplicityHL Language Support",
44
"description": "Syntax highlighting and autocompletion for SimplicityHL (Simfony) language",
5-
"version": "0.2.0",
5+
"version": "0.2.1",
66
"publisher": "Blockstream",
77
"repository": {
88
"type": "git",
@@ -69,7 +69,14 @@
6969
"description": "Do not show missing LSP executable warning."
7070
}
7171
}
72-
}
72+
},
73+
"commands": [
74+
{
75+
"command": "simplicityhl.restartServer",
76+
"title": "Restart server",
77+
"category": "SimplicityHL"
78+
}
79+
]
7380
},
7481
"license": "MIT",
7582
"scripts": {

vscode/src/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ export class LspClient {
5959
}
6060
return this.client.stop();
6161
}
62+
63+
public async restart(): Promise<void> {
64+
if (!this.client) {
65+
window.showWarningMessage("LSP client not initialized. Cannot restart.");
66+
return;
67+
}
68+
69+
try {
70+
await this.client.stop();
71+
await this.client.start();
72+
window.showInformationMessage("SimplicityHL Language Server restarted successfully!");
73+
} catch (e) {
74+
window.showErrorMessage(`Failed to restart LSP: ${e}`);
75+
}
76+
}
6277
}

vscode/src/commands.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ExtensionContext, commands } from "vscode";
2+
import { LspClient } from "./client";
3+
4+
export function registerRestartCommand(
5+
context: ExtensionContext,
6+
lspClient: LspClient
7+
) {
8+
const command = commands.registerCommand(
9+
"simplicityhl.restartServer",
10+
async () => {
11+
await lspClient.restart();
12+
}
13+
);
14+
15+
context.subscriptions.push(command);
16+
}

vscode/src/extension.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { LspClient } from "./client";
2+
import { registerRestartCommand } from "./commands"
3+
import { ExtensionContext } from "vscode"
4+
25
let client: LspClient;
3-
export function activate() {
6+
7+
export function activate(context: ExtensionContext) {
48
client = new LspClient();
59
void client.start();
10+
11+
registerRestartCommand(context, client);
612
}
713
export function deactivate(): Thenable<void> | undefined {
814
if (!client) {

0 commit comments

Comments
 (0)