feat(vscode): display the version of the language server in the status bar
MODIFY
editors/vscode/package-lock.json
editors/vscode/package-lock.json
{
"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",

MODIFY
editors/vscode/src/main.ts
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;

MODIFY
editors/vscode/src/statusBar.ts
editors/vscode/src/statusBar.ts
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: {

DELETE
editors/vscode/src/status_bar.ts
-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();
- }
-}

feat(vscode): display the version of the language server in the status bar (#3616)