From 274df5488530e7445553a680b1d56dd8573b99e8 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 28 Oct 2022 23:10:10 +0200 Subject: [PATCH] feat: Clicking the status bar item stops and starts the server --- editors/code/src/ctx.ts | 13 ++++++++++--- editors/code/src/main.ts | 4 +--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 044a9470aa..8592950e10 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -204,13 +204,13 @@ export class Ctx { } } - setServerStatus(status: ServerStatusParams) { + setServerStatus(status: ServerStatusParams | { health: "stopped" }) { let icon = ""; const statusBar = this.statusBar; switch (status.health) { case "ok": - statusBar.tooltip = status.message ?? "Ready"; - statusBar.command = undefined; + statusBar.tooltip = (status.message ?? "Ready") + "Click to stop."; + statusBar.command = "rust-analyzer.stopServer"; statusBar.color = undefined; statusBar.backgroundColor = undefined; break; @@ -234,6 +234,13 @@ export class Ctx { statusBar.backgroundColor = new vscode.ThemeColor("statusBarItem.errorBackground"); icon = "$(error) "; break; + case "stopped": + statusBar.tooltip = "Server is stopped. Click to start."; + statusBar.command = "rust-analyzer.startServer"; + statusBar.color = undefined; + statusBar.backgroundColor = undefined; + statusBar.text = `$(stop-circle) rust-analyzer`; + return; } if (!status.quiescent) icon = "$(sync~spin) "; statusBar.text = `${icon}rust-analyzer`; diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 8c3a676ffb..5970533472 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -120,9 +120,7 @@ function createCommands(): Record { // FIXME: We should re-use the client, that is ctx.deactivate() if none of the configs have changed await ctx.stop(); ctx.setServerStatus({ - health: "ok", - quiescent: true, - message: "server is not running", + health: "stopped", }); }, },