mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-09-20 22:42:02 +00:00
Add version info to status bar item
This commit is contained in:
parent
7c5d496ef8
commit
0ee8a4f472
2 changed files with 46 additions and 24 deletions
|
@ -9,7 +9,6 @@ import {
|
||||||
applySnippetTextEdits,
|
applySnippetTextEdits,
|
||||||
type SnippetTextDocumentEdit,
|
type SnippetTextDocumentEdit,
|
||||||
} from "./snippets";
|
} from "./snippets";
|
||||||
import { spawnSync } from "child_process";
|
|
||||||
import { type RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run";
|
import { type RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run";
|
||||||
import { AstInspector } from "./ast_inspector";
|
import { AstInspector } from "./ast_inspector";
|
||||||
import {
|
import {
|
||||||
|
@ -415,10 +414,9 @@ export function serverVersion(ctx: CtxInit): Cmd {
|
||||||
void vscode.window.showWarningMessage(`rust-analyzer server is not running`);
|
void vscode.window.showWarningMessage(`rust-analyzer server is not running`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { stdout } = spawnSync(ctx.serverPath, ["--version"], { encoding: "utf8" });
|
void vscode.window.showInformationMessage(
|
||||||
const versionString = stdout.slice(`rust-analyzer `.length).trim();
|
`rust-analyzer version: ${ctx.serverVersion} [${ctx.serverPath}]`,
|
||||||
|
);
|
||||||
void vscode.window.showInformationMessage(`rust-analyzer version: ${versionString}`);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ import { bootstrap } from "./bootstrap";
|
||||||
import type { RustAnalyzerExtensionApi } from "./main";
|
import type { RustAnalyzerExtensionApi } from "./main";
|
||||||
import type { JsonProject } from "./rust_project";
|
import type { JsonProject } from "./rust_project";
|
||||||
import { prepareTestExplorer } from "./test_explorer";
|
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
|
// 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
|
// 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;
|
readonly statusBar: vscode.StatusBarItem;
|
||||||
config: Config;
|
config: Config;
|
||||||
readonly workspace: Workspace;
|
readonly workspace: Workspace;
|
||||||
|
readonly version: string;
|
||||||
|
|
||||||
private _client: lc.LanguageClient | undefined;
|
private _client: lc.LanguageClient | undefined;
|
||||||
private _serverPath: string | undefined;
|
private _serverPath: string | undefined;
|
||||||
|
@ -85,6 +88,15 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
private _dependencies: RustDependenciesProvider | undefined;
|
private _dependencies: RustDependenciesProvider | undefined;
|
||||||
private _treeView: vscode.TreeView<Dependency | DependencyFile | DependencyId> | undefined;
|
private _treeView: vscode.TreeView<Dependency | DependencyFile | DependencyId> | undefined;
|
||||||
private lastStatus: ServerStatusParams | { health: "stopped" } = { health: "stopped" };
|
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() {
|
get client() {
|
||||||
return this._client;
|
return this._client;
|
||||||
|
@ -104,6 +116,8 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
) {
|
) {
|
||||||
extCtx.subscriptions.push(this);
|
extCtx.subscriptions.push(this);
|
||||||
|
this.version = extCtx.extension.packageJSON.version ?? "<unknown>";
|
||||||
|
this._serverVersion = "<not running>";
|
||||||
this.config = new Config(extCtx);
|
this.config = new Config(extCtx);
|
||||||
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||||
if (this.config.testExplorer) {
|
if (this.config.testExplorer) {
|
||||||
|
@ -186,6 +200,19 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
throw new Error(message);
|
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 newEnv = Object.assign({}, process.env, this.config.serverExtraEnv);
|
||||||
const run: lc.Executable = {
|
const run: lc.Executable = {
|
||||||
command: this._serverPath,
|
command: this._serverPath,
|
||||||
|
@ -372,10 +399,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
return this.extCtx.subscriptions;
|
return this.extCtx.subscriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
get serverPath(): string | undefined {
|
|
||||||
return this._serverPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
setWorkspaces(workspaces: JsonProject[]) {
|
setWorkspaces(workspaces: JsonProject[]) {
|
||||||
this.config.discoveredWorkspaces = workspaces;
|
this.config.discoveredWorkspaces = workspaces;
|
||||||
}
|
}
|
||||||
|
@ -475,23 +498,24 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
if (statusBar.tooltip.value) {
|
if (statusBar.tooltip.value) {
|
||||||
statusBar.tooltip.appendMarkdown("\n\n---\n\n");
|
statusBar.tooltip.appendMarkdown("\n\n---\n\n");
|
||||||
}
|
}
|
||||||
statusBar.tooltip.appendMarkdown("\n\n[Open Logs](command:rust-analyzer.openLogs)");
|
|
||||||
|
const toggleCheckOnSave = this.config.checkOnSave ? "Disable" : "Enable";
|
||||||
statusBar.tooltip.appendMarkdown(
|
statusBar.tooltip.appendMarkdown(
|
||||||
`\n\n[${
|
`[Extension Info](command:analyzer.serverVersion "Show version and server binary info"): Version ${this.version}, Server Version ${this._serverVersion}` +
|
||||||
this.config.checkOnSave ? "Disable" : "Enable"
|
"\n\n---\n\n" +
|
||||||
} Check on Save](command:rust-analyzer.toggleCheckOnSave)`,
|
'[$(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(
|
if (!status.quiescent) icon = "$(loading~spin) ";
|
||||||
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)",
|
|
||||||
);
|
|
||||||
statusBar.tooltip.appendMarkdown(
|
|
||||||
"\n\n[Rebuild Proc Macros](command:rust-analyzer.rebuildProcMacros)",
|
|
||||||
);
|
|
||||||
statusBar.tooltip.appendMarkdown(
|
|
||||||
"\n\n[Restart server](command:rust-analyzer.restartServer)",
|
|
||||||
);
|
|
||||||
statusBar.tooltip.appendMarkdown("\n\n[Stop server](command:rust-analyzer.stopServer)");
|
|
||||||
if (!status.quiescent) icon = "$(sync~spin) ";
|
|
||||||
statusBar.text = `${icon}rust-analyzer`;
|
statusBar.text = `${icon}rust-analyzer`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue