Add fancy buttons to the vscode status message
This commit is contained in:
parent
0d19ccb3df
commit
2cb60343ed
3 changed files with 31 additions and 12 deletions
|
@ -93,6 +93,14 @@ export function triggerParameterHints(_: CtxInit): Cmd {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function openLogs(ctx: CtxInit): Cmd {
|
||||||
|
return async () => {
|
||||||
|
if (ctx.client.outputChannel) {
|
||||||
|
ctx.client.outputChannel.show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function matchingBrace(ctx: CtxInit): Cmd {
|
export function matchingBrace(ctx: CtxInit): Cmd {
|
||||||
return async () => {
|
return async () => {
|
||||||
const editor = ctx.activeRustEditor;
|
const editor = ctx.activeRustEditor;
|
||||||
|
|
|
@ -282,18 +282,18 @@ export class Ctx {
|
||||||
setServerStatus(status: ServerStatusParams | { health: "stopped" }) {
|
setServerStatus(status: ServerStatusParams | { health: "stopped" }) {
|
||||||
let icon = "";
|
let icon = "";
|
||||||
const statusBar = this.statusBar;
|
const statusBar = this.statusBar;
|
||||||
|
statusBar.tooltip = new vscode.MarkdownString("", true);
|
||||||
|
statusBar.tooltip.isTrusted = true;
|
||||||
switch (status.health) {
|
switch (status.health) {
|
||||||
case "ok":
|
case "ok":
|
||||||
statusBar.tooltip = (status.message ?? "Ready") + "\nClick to stop server.";
|
statusBar.tooltip.appendText(status.message ?? "Ready");
|
||||||
statusBar.command = "rust-analyzer.stopServer";
|
|
||||||
statusBar.color = undefined;
|
statusBar.color = undefined;
|
||||||
statusBar.backgroundColor = undefined;
|
statusBar.backgroundColor = undefined;
|
||||||
break;
|
break;
|
||||||
case "warning":
|
case "warning":
|
||||||
statusBar.tooltip =
|
if (status.message) {
|
||||||
(status.message ? status.message + "\n" : "") + "Click to reload.";
|
statusBar.tooltip.appendText(status.message);
|
||||||
|
}
|
||||||
statusBar.command = "rust-analyzer.reloadWorkspace";
|
|
||||||
statusBar.color = new vscode.ThemeColor("statusBarItem.warningForeground");
|
statusBar.color = new vscode.ThemeColor("statusBarItem.warningForeground");
|
||||||
statusBar.backgroundColor = new vscode.ThemeColor(
|
statusBar.backgroundColor = new vscode.ThemeColor(
|
||||||
"statusBarItem.warningBackground"
|
"statusBarItem.warningBackground"
|
||||||
|
@ -301,22 +301,32 @@ export class Ctx {
|
||||||
icon = "$(warning) ";
|
icon = "$(warning) ";
|
||||||
break;
|
break;
|
||||||
case "error":
|
case "error":
|
||||||
statusBar.tooltip =
|
if (status.message) {
|
||||||
(status.message ? status.message + "\n" : "") + "Click to reload.";
|
statusBar.tooltip.appendText(status.message);
|
||||||
|
}
|
||||||
statusBar.command = "rust-analyzer.reloadWorkspace";
|
|
||||||
statusBar.color = new vscode.ThemeColor("statusBarItem.errorForeground");
|
statusBar.color = new vscode.ThemeColor("statusBarItem.errorForeground");
|
||||||
statusBar.backgroundColor = new vscode.ThemeColor("statusBarItem.errorBackground");
|
statusBar.backgroundColor = new vscode.ThemeColor("statusBarItem.errorBackground");
|
||||||
icon = "$(error) ";
|
icon = "$(error) ";
|
||||||
break;
|
break;
|
||||||
case "stopped":
|
case "stopped":
|
||||||
statusBar.tooltip = "Server is stopped.\nClick to start.";
|
statusBar.tooltip.appendText("Server is stopped");
|
||||||
statusBar.command = "rust-analyzer.startServer";
|
statusBar.tooltip.appendMarkdown(
|
||||||
|
"\n\n[Start server](command:rust-analyzer.startServer)"
|
||||||
|
);
|
||||||
statusBar.color = undefined;
|
statusBar.color = undefined;
|
||||||
statusBar.backgroundColor = undefined;
|
statusBar.backgroundColor = undefined;
|
||||||
statusBar.text = `$(stop-circle) rust-analyzer`;
|
statusBar.text = `$(stop-circle) rust-analyzer`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (statusBar.tooltip.value) {
|
||||||
|
statusBar.tooltip.appendText("\n\n");
|
||||||
|
}
|
||||||
|
statusBar.tooltip.appendMarkdown("[Stop server](command:rust-analyzer.stopServer)");
|
||||||
|
statusBar.tooltip.appendMarkdown(
|
||||||
|
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)"
|
||||||
|
);
|
||||||
|
statusBar.tooltip.appendMarkdown("\n\n[Restart server](command:rust-analyzer.startServer)");
|
||||||
|
statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
|
||||||
if (!status.quiescent) icon = "$(sync~spin) ";
|
if (!status.quiescent) icon = "$(sync~spin) ";
|
||||||
statusBar.text = `${icon}rust-analyzer`;
|
statusBar.text = `${icon}rust-analyzer`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,5 +188,6 @@ function createCommands(): Record<string, CommandFactory> {
|
||||||
runSingle: { enabled: commands.runSingle },
|
runSingle: { enabled: commands.runSingle },
|
||||||
showReferences: { enabled: commands.showReferences },
|
showReferences: { enabled: commands.showReferences },
|
||||||
triggerParameterHints: { enabled: commands.triggerParameterHints },
|
triggerParameterHints: { enabled: commands.triggerParameterHints },
|
||||||
|
openLogs: { enabled: commands.openLogs },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue