From 03204d75b315280e927e9729c11ca13cfa8b1684 Mon Sep 17 00:00:00 2001 From: l3ops Date: Wed, 9 Nov 2022 10:24:26 +0100 Subject: [PATCH] feat(vscode): display the version of the language server in the status bar --- editors/vscode/package-lock.json | 4 +- editors/vscode/src/main.ts | 6 +- editors/vscode/src/statusBar.ts | 14 +++- editors/vscode/src/status_bar.ts | 115 ------------------------------- 4 files changed, 17 insertions(+), 122 deletions(-) delete mode 100644 editors/vscode/src/status_bar.ts diff --git a/editors/vscode/package-lock.json b/editors/vscode/package-lock.json index 1e44b46bf16..418eacec030 100644 --- a/editors/vscode/package-lock.json +++ b/editors/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "rome", - "version": "0.16.1", + "version": "0.18.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rome", - "version": "0.16.1", + "version": "0.18.0", "license": "MIT", "devDependencies": { "@types/node": "^18.0.0", diff --git a/editors/vscode/src/main.ts b/editors/vscode/src/main.ts index 0a8c886fb3c..a94fc98f955 100644 --- a/editors/vscode/src/main.ts +++ b/editors/vscode/src/main.ts @@ -16,13 +16,12 @@ import { StreamInfo, } from "vscode-languageclient/node"; import { isAbsolute, join } from "path"; -import { existsSync, readFileSync } from "fs"; +import { existsSync } from "fs"; import { setContextValue } from "./utils"; import { Session } from "./session"; import { syntaxTree } from "./commands/syntaxTree"; import { Commands } from "./commands"; import { StatusBar } from "./statusBar"; -import { updateSettingsRequest } from "./lsp_requests"; let client: LanguageClient; @@ -90,13 +89,14 @@ export async function activate(context: ExtensionContext) { context.subscriptions.push( client.onDidChangeState((evt) => { - statusBar.setServerState(evt.newState); + statusBar.setServerState(client, evt.newState); }), ); const handleActiveTextEditorChanged = (textEditor?: TextEditor) => { if (!textEditor) { statusBar.setActive(false); + return; } const { document } = textEditor; diff --git a/editors/vscode/src/statusBar.ts b/editors/vscode/src/statusBar.ts index 33d99b7fe2f..99169ebea16 100644 --- a/editors/vscode/src/statusBar.ts +++ b/editors/vscode/src/statusBar.ts @@ -1,5 +1,6 @@ import { StatusBarAlignment, StatusBarItem, ThemeColor, window } from "vscode"; import { State } from "vscode-languageclient"; +import { LanguageClient } from "vscode-languageclient/node"; import { Commands } from "./commands"; /** @@ -24,6 +25,7 @@ export class StatusBar { private serverState: State = State.Starting; private isActive: boolean = false; + private serverVersion: string = ""; constructor() { this.statusBarItem = window.createStatusBarItem( @@ -37,8 +39,15 @@ export class StatusBar { this.update(); } - public setServerState(state: State) { + public setServerState(client: LanguageClient, state: State) { this.serverState = state; + + if (state === State.Running) { + this.serverVersion = client.initializeResult?.serverInfo?.version ?? ""; + } else { + this.serverVersion = ""; + } + this.update(); } @@ -61,7 +70,8 @@ export class StatusBar { status = Status.Error; } - this.statusBarItem.text = `$(${status}) Rome`; + this.statusBarItem.text = + `$(${status}) Rome ${this.serverVersion}`.trimEnd(); switch (status) { case Status.Pending: { diff --git a/editors/vscode/src/status_bar.ts b/editors/vscode/src/status_bar.ts deleted file mode 100644 index d14359a07dd..00000000000 --- a/editors/vscode/src/status_bar.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { StatusBarAlignment, StatusBarItem, ThemeColor, window } from "vscode"; -import { State } from "vscode-languageclient"; -import { Commands } from "./commands"; - -enum Status { - Pending = "refresh", - Ready = "check", - Inactive = "eye-closed", - Warning = "warning", - Error = "error", -} - -export class StatusBar { - private statusBarItem: StatusBarItem; - - private serverState: State = State.Starting; - private isActive: boolean = false; - - constructor() { - this.statusBarItem = window.createStatusBarItem( - "rome.status", - StatusBarAlignment.Right, - -1, - ); - - this.statusBarItem.name = "Rome"; - this.statusBarItem.command = Commands.ServerStatus; - this.update(); - } - - public setServerState(state: State) { - this.serverState = state; - this.update(); - } - - public setActive(isActive: boolean) { - this.isActive = isActive; - this.update(); - } - - private update() { - let status: Status; - if (this.serverState === State.Running) { - if (this.isActive) { - status = Status.Ready; - } else { - status = Status.Inactive; - } - } else if (this.serverState === State.Starting) { - status = Status.Pending; - } else { - status = Status.Error; - } - - this.statusBarItem.text = `$(${status}) Rome`; - - switch (status) { - case Status.Pending: { - this.statusBarItem.tooltip = "Rome is initializing ..."; - break; - } - case Status.Ready: { - this.statusBarItem.tooltip = "Rome is active"; - break; - } - case Status.Inactive: { - this.statusBarItem.tooltip = - "The current file is not supported or ignored by Rome"; - break; - } - // @ts-expect-error Reserved for future use - case Status.Warning: { - this.statusBarItem.tooltip = undefined; - break; - } - case Status.Error: { - this.statusBarItem.tooltip = "Rome encountered a fatal error"; - break; - } - } - - switch (status) { - case Status.Error: { - this.statusBarItem.color = new ThemeColor( - "statusBarItem.errorForeground", - ); - this.statusBarItem.backgroundColor = new ThemeColor( - "statusBarItem.errorBackground", - ); - break; - } - // @ts-expect-error Reserved for future use - case Status.Warning: { - this.statusBarItem.color = new ThemeColor( - "statusBarItem.warningForeground", - ); - this.statusBarItem.backgroundColor = new ThemeColor( - "statusBarItem.warningBackground", - ); - break; - } - default: { - this.statusBarItem.color = undefined; - this.statusBarItem.backgroundColor = undefined; - break; - } - } - - this.statusBarItem.show(); - } - - public hide() { - this.statusBarItem.hide(); - } -}