Skip to content

Commit

Permalink
feat: add restarting language server command (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn authored Mar 24, 2024
1 parent 48f8a6b commit c52dc29
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@
"editor.insertSpaces": true,
"editor.tabSize": 2
}
}
},
"commands": [
{
"title": "Restart Language Server",
"category": "Nix IDE",
"command": "nix-ide.restartLanguageServer"
}
]
},
"devDependencies": {
"@commitlint/cli": "*",
Expand Down
13 changes: 13 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,16 @@ export async function activate(context: ExtensionContext): Promise<void> {
export function deactivate(): Thenable<void> | undefined {
return client ? client.stop() : undefined;
}

export async function restart(context: ExtensionContext): Promise<void> {
const disposable = window.setStatusBarMessage(
"$(loading~spin) Restarting Nix language server",
);
try {
client ? await client.restart() : await activate(context);
} catch (error) {
client?.error("Failed to restart Nix language server", error, "force");
} finally {
disposable.dispose();
}
}
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import * as client from "./client";
*/
export async function activate(context: ExtensionContext): Promise<void> {
if (config.LSPEnabled) {
context.subscriptions.push(
vscode.commands.registerCommand("nix-ide.restartLanguageServer", () =>
client.restart(context),
),
);
await client.activate(context);
} else {
await startLinting(context);
Expand Down

0 comments on commit c52dc29

Please sign in to comment.