Skip to content

Commit

Permalink
feature: add bsp status (#1427)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek authored Sep 29, 2023
1 parent d264297 commit c54c8be
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
*.vsix
yarn-error.log
.metals/
*.DS_Store

# sourcegraph
index.scip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export interface MetalsInitializationOptions {
copyWorksheetOutputProvider?: boolean;
commandInHtmlFormat?: "vscode" | "sublime";
doctorVisibilityProvider?: boolean;
bspStatusBarProvider?: "on" | "off" | "log-message" | "show-message";
}
6 changes: 6 additions & 0 deletions packages/metals-languageclient/src/interfaces/MetalsStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ export interface MetalsStatusParams {
tooltip?: string;
/** If set, execute this command when the user clicks on the status bar item. */
command?: string;
/** Is this metals or bsp status. */
statusType?: "bsp" | "metals";
/** Level: info, warn, error. */
level?: "info" | "warn" | "error";
/** Tooltip for the command. */
commandTooltip?: string;
}
40 changes: 31 additions & 9 deletions packages/metals-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
tests as vscodeTextExplorer,
debug,
DebugSessionCustomEvent,
ThemeColor,
} from "vscode";
import {
LanguageClient,
Expand Down Expand Up @@ -312,6 +313,7 @@ function launchMetals(
testExplorerProvider: true,
commandInHtmlFormat: "vscode",
doctorVisibilityProvider: true,
bspStatusBarProvider: "on",
};

const clientOptions: LanguageClientOptions = {
Expand Down Expand Up @@ -707,26 +709,46 @@ function launchMetals(
context.subscriptions.push(executeClientCommandDisposable);
// The server updates the client with a brief text message about what
// it is currently doing, for example "Compiling..".
const item = window.createStatusBarItem(StatusBarAlignment.Right, 100);
item.command = ClientCommands.ToggleLogs;
item.hide();
const metalsItem = window.createStatusBarItem(
StatusBarAlignment.Right,
100
);
const bspItem = window.createStatusBarItem(StatusBarAlignment.Right, 100);
metalsItem.command = ClientCommands.ToggleLogs;
metalsItem.hide();
bspItem.hide();
const metalsStatusDisposable = client.onNotification(
MetalsStatus.type,
(params) => {
const item = params.statusType === "bsp" ? bspItem : metalsItem;
item.text = params.text;
if (params.show) {
item.show();
} else if (params.hide) {
item.hide();
}
if (params.tooltip) {
item.tooltip = params.tooltip;
}
if (params.command) {
item.command = params.command;

const commandTooltip = params.commandTooltip
? "\nPress to " + params.commandTooltip.toLowerCase()
: "";

item.tooltip = params.tooltip
? params.tooltip + commandTooltip
: undefined;

if (params.level == "error") {
item.backgroundColor = new ThemeColor(
"statusBarItem.errorBackground"
);
} else if (params.level == "warn") {
item.backgroundColor = new ThemeColor(
"statusBarItem.warningBackground"
);
} else {
item.command = undefined;
item.backgroundColor = undefined;
}

item.command = params.command;
}
);
context.subscriptions.push(metalsStatusDisposable);
Expand Down

0 comments on commit c54c8be

Please sign in to comment.