about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-07 12:51:28 +0000
committerbors <bors@rust-lang.org>2024-06-07 12:51:28 +0000
commitc50175323606c63ff37558c487e846d746b0ee6f (patch)
tree267edc49aef82beadc688f5ff6c3cd50b96a4f8c
parentf711c68f989ad7e0798f97a5bf870349f5a60f3f (diff)
parentfc92e5c87aa093b5edd32604112c26d42a490341 (diff)
downloadrust-c50175323606c63ff37558c487e846d746b0ee6f.tar.gz
rust-c50175323606c63ff37558c487e846d746b0ee6f.zip
Auto merge of #17359 - Veykril:status-bar, r=Veykril
Add version info to status bar item
-rw-r--r--src/tools/rust-analyzer/editors/code/src/commands.ts8
-rw-r--r--src/tools/rust-analyzer/editors/code/src/ctx.ts62
2 files changed, 46 insertions, 24 deletions
diff --git a/src/tools/rust-analyzer/editors/code/src/commands.ts b/src/tools/rust-analyzer/editors/code/src/commands.ts
index 849fae5cf24..9f4930c94a2 100644
--- a/src/tools/rust-analyzer/editors/code/src/commands.ts
+++ b/src/tools/rust-analyzer/editors/code/src/commands.ts
@@ -9,7 +9,6 @@ import {
     applySnippetTextEdits,
     type SnippetTextDocumentEdit,
 } from "./snippets";
-import { spawnSync } from "child_process";
 import { type RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run";
 import { AstInspector } from "./ast_inspector";
 import {
@@ -415,10 +414,9 @@ export function serverVersion(ctx: CtxInit): Cmd {
             void vscode.window.showWarningMessage(`rust-analyzer server is not running`);
             return;
         }
-        const { stdout } = spawnSync(ctx.serverPath, ["--version"], { encoding: "utf8" });
-        const versionString = stdout.slice(`rust-analyzer `.length).trim();
-
-        void vscode.window.showInformationMessage(`rust-analyzer version: ${versionString}`);
+        void vscode.window.showInformationMessage(
+            `rust-analyzer version: ${ctx.serverVersion} [${ctx.serverPath}]`,
+        );
     };
 }
 
diff --git a/src/tools/rust-analyzer/editors/code/src/ctx.ts b/src/tools/rust-analyzer/editors/code/src/ctx.ts
index 474e18b722f..bf0b84ec358 100644
--- a/src/tools/rust-analyzer/editors/code/src/ctx.ts
+++ b/src/tools/rust-analyzer/editors/code/src/ctx.ts
@@ -25,6 +25,8 @@ import { bootstrap } from "./bootstrap";
 import type { RustAnalyzerExtensionApi } from "./main";
 import type { JsonProject } from "./rust_project";
 import { prepareTestExplorer } from "./test_explorer";
+import { spawn } from "node:child_process";
+import { text } from "node:stream/consumers";
 
 // We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
 // only those are in use. We use "Empty" to represent these scenarios
@@ -71,6 +73,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
     readonly statusBar: vscode.StatusBarItem;
     config: Config;
     readonly workspace: Workspace;
+    readonly version: string;
 
     private _client: lc.LanguageClient | undefined;
     private _serverPath: string | undefined;
@@ -85,6 +88,15 @@ export class Ctx implements RustAnalyzerExtensionApi {
     private _dependencies: RustDependenciesProvider | undefined;
     private _treeView: vscode.TreeView<Dependency | DependencyFile | DependencyId> | undefined;
     private lastStatus: ServerStatusParams | { health: "stopped" } = { health: "stopped" };
+    private _serverVersion: string;
+
+    get serverPath(): string | undefined {
+        return this._serverPath;
+    }
+
+    get serverVersion(): string | undefined {
+        return this._serverVersion;
+    }
 
     get client() {
         return this._client;
@@ -104,6 +116,8 @@ export class Ctx implements RustAnalyzerExtensionApi {
         workspace: Workspace,
     ) {
         extCtx.subscriptions.push(this);
+        this.version = extCtx.extension.packageJSON.version ?? "<unknown>";
+        this._serverVersion = "<not running>";
         this.config = new Config(extCtx);
         this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
         if (this.config.testExplorer) {
@@ -186,6 +200,19 @@ export class Ctx implements RustAnalyzerExtensionApi {
                     throw new Error(message);
                 },
             );
+            text(spawn(this._serverPath, ["--version"]).stdout.setEncoding("utf-8")).then(
+                (data) => {
+                    const prefix = `rust-analyzer `;
+                    this._serverVersion = data
+                        .slice(data.startsWith(prefix) ? prefix.length : 0)
+                        .trim();
+                    this.refreshServerStatus();
+                },
+                (_) => {
+                    this._serverVersion = "<unknown>";
+                    this.refreshServerStatus();
+                },
+            );
             const newEnv = Object.assign({}, process.env, this.config.serverExtraEnv);
             const run: lc.Executable = {
                 command: this._serverPath,
@@ -372,10 +399,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
         return this.extCtx.subscriptions;
     }
 
-    get serverPath(): string | undefined {
-        return this._serverPath;
-    }
-
     setWorkspaces(workspaces: JsonProject[]) {
         this.config.discoveredWorkspaces = workspaces;
     }
@@ -475,23 +498,24 @@ export class Ctx implements RustAnalyzerExtensionApi {
         if (statusBar.tooltip.value) {
             statusBar.tooltip.appendMarkdown("\n\n---\n\n");
         }
-        statusBar.tooltip.appendMarkdown("\n\n[Open Logs](command:rust-analyzer.openLogs)");
-        statusBar.tooltip.appendMarkdown(
-            `\n\n[${
-                this.config.checkOnSave ? "Disable" : "Enable"
-            } Check on Save](command:rust-analyzer.toggleCheckOnSave)`,
-        );
-        statusBar.tooltip.appendMarkdown(
-            "\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)",
-        );
-        statusBar.tooltip.appendMarkdown(
-            "\n\n[Rebuild Proc Macros](command:rust-analyzer.rebuildProcMacros)",
-        );
+
+        const toggleCheckOnSave = this.config.checkOnSave ? "Disable" : "Enable";
         statusBar.tooltip.appendMarkdown(
-            "\n\n[Restart server](command:rust-analyzer.restartServer)",
+            `[Extension Info](command:analyzer.serverVersion "Show version and server binary info"): Version ${this.version}, Server Version ${this._serverVersion}` +
+                "\n\n---\n\n" +
+                '[$(terminal) Open Logs](command:rust-analyzer.openLogs "Open the server logs")' +
+                "\n\n" +
+                `[$(settings) ${toggleCheckOnSave} Check on Save](command:rust-analyzer.toggleCheckOnSave "Temporarily ${toggleCheckOnSave.toLowerCase()} check on save functionality")` +
+                "\n\n" +
+                '[$(refresh) Reload Workspace](command:rust-analyzer.reloadWorkspace "Reload and rediscover workspaces")' +
+                "\n\n" +
+                '[$(symbol-property) Rebuild Build Dependencies](command:rust-analyzer.rebuildProcMacros "Rebuild build scripts and proc-macros")' +
+                "\n\n" +
+                '[$(stop-circle) Stop server](command:rust-analyzer.stopServer "Stop the server")' +
+                "\n\n" +
+                '[$(debug-restart) Restart server](command:rust-analyzer.restartServer "Restart the server")',
         );
-        statusBar.tooltip.appendMarkdown("\n\n[Stop server](command:rust-analyzer.stopServer)");
-        if (!status.quiescent) icon = "$(sync~spin) ";
+        if (!status.quiescent) icon = "$(loading~spin) ";
         statusBar.text = `${icon}rust-analyzer`;
     }