Skip to content

Commit 2cb6034

Browse files
committed
Add fancy buttons to the vscode status message
1 parent 0d19ccb commit 2cb6034

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

editors/code/src/commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ export function triggerParameterHints(_: CtxInit): Cmd {
9393
};
9494
}
9595

96+
export function openLogs(ctx: CtxInit): Cmd {
97+
return async () => {
98+
if (ctx.client.outputChannel) {
99+
ctx.client.outputChannel.show();
100+
}
101+
};
102+
}
103+
96104
export function matchingBrace(ctx: CtxInit): Cmd {
97105
return async () => {
98106
const editor = ctx.activeRustEditor;

editors/code/src/ctx.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,41 +282,51 @@ export class Ctx {
282282
setServerStatus(status: ServerStatusParams | { health: "stopped" }) {
283283
let icon = "";
284284
const statusBar = this.statusBar;
285+
statusBar.tooltip = new vscode.MarkdownString("", true);
286+
statusBar.tooltip.isTrusted = true;
285287
switch (status.health) {
286288
case "ok":
287-
statusBar.tooltip = (status.message ?? "Ready") + "\nClick to stop server.";
288-
statusBar.command = "rust-analyzer.stopServer";
289+
statusBar.tooltip.appendText(status.message ?? "Ready");
289290
statusBar.color = undefined;
290291
statusBar.backgroundColor = undefined;
291292
break;
292293
case "warning":
293-
statusBar.tooltip =
294-
(status.message ? status.message + "\n" : "") + "Click to reload.";
295-
296-
statusBar.command = "rust-analyzer.reloadWorkspace";
294+
if (status.message) {
295+
statusBar.tooltip.appendText(status.message);
296+
}
297297
statusBar.color = new vscode.ThemeColor("statusBarItem.warningForeground");
298298
statusBar.backgroundColor = new vscode.ThemeColor(
299299
"statusBarItem.warningBackground"
300300
);
301301
icon = "$(warning) ";
302302
break;
303303
case "error":
304-
statusBar.tooltip =
305-
(status.message ? status.message + "\n" : "") + "Click to reload.";
306-
307-
statusBar.command = "rust-analyzer.reloadWorkspace";
304+
if (status.message) {
305+
statusBar.tooltip.appendText(status.message);
306+
}
308307
statusBar.color = new vscode.ThemeColor("statusBarItem.errorForeground");
309308
statusBar.backgroundColor = new vscode.ThemeColor("statusBarItem.errorBackground");
310309
icon = "$(error) ";
311310
break;
312311
case "stopped":
313-
statusBar.tooltip = "Server is stopped.\nClick to start.";
314-
statusBar.command = "rust-analyzer.startServer";
312+
statusBar.tooltip.appendText("Server is stopped");
313+
statusBar.tooltip.appendMarkdown(
314+
"\n\n[Start server](command:rust-analyzer.startServer)"
315+
);
315316
statusBar.color = undefined;
316317
statusBar.backgroundColor = undefined;
317318
statusBar.text = `$(stop-circle) rust-analyzer`;
318319
return;
319320
}
321+
if (statusBar.tooltip.value) {
322+
statusBar.tooltip.appendText("\n\n");
323+
}
324+
statusBar.tooltip.appendMarkdown("[Stop server](command:rust-analyzer.stopServer)");
325+
statusBar.tooltip.appendMarkdown(
326+
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)"
327+
);
328+
statusBar.tooltip.appendMarkdown("\n\n[Restart server](command:rust-analyzer.startServer)");
329+
statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
320330
if (!status.quiescent) icon = "$(sync~spin) ";
321331
statusBar.text = `${icon}rust-analyzer`;
322332
}

editors/code/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,6 @@ function createCommands(): Record<string, CommandFactory> {
188188
runSingle: { enabled: commands.runSingle },
189189
showReferences: { enabled: commands.showReferences },
190190
triggerParameterHints: { enabled: commands.triggerParameterHints },
191+
openLogs: { enabled: commands.openLogs },
191192
};
192193
}

0 commit comments

Comments
 (0)