@@ -25,6 +25,8 @@ import { bootstrap } from "./bootstrap";
2525import type { RustAnalyzerExtensionApi } from "./main" ;
2626import type { JsonProject } from "./rust_project" ;
2727import { prepareTestExplorer } from "./test_explorer" ;
28+ import { spawn } from "node:child_process" ;
29+ import { text } from "node:stream/consumers" ;
2830
2931// We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
3032// only those are in use. We use "Empty" to represent these scenarios
@@ -71,6 +73,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
7173 readonly statusBar : vscode . StatusBarItem ;
7274 config : Config ;
7375 readonly workspace : Workspace ;
76+ readonly version : string ;
7477
7578 private _client : lc . LanguageClient | undefined ;
7679 private _serverPath : string | undefined ;
@@ -85,6 +88,15 @@ export class Ctx implements RustAnalyzerExtensionApi {
8588 private _dependencies : RustDependenciesProvider | undefined ;
8689 private _treeView : vscode . TreeView < Dependency | DependencyFile | DependencyId > | undefined ;
8790 private lastStatus : ServerStatusParams | { health : "stopped" } = { health : "stopped" } ;
91+ private _serverVersion : string ;
92+
93+ get serverPath ( ) : string | undefined {
94+ return this . _serverPath ;
95+ }
96+
97+ get serverVersion ( ) : string | undefined {
98+ return this . _serverVersion ;
99+ }
88100
89101 get client ( ) {
90102 return this . _client ;
@@ -104,6 +116,8 @@ export class Ctx implements RustAnalyzerExtensionApi {
104116 workspace : Workspace ,
105117 ) {
106118 extCtx . subscriptions . push ( this ) ;
119+ this . version = extCtx . extension . packageJSON . version ?? "<unknown>" ;
120+ this . _serverVersion = "<not running>" ;
107121 this . config = new Config ( extCtx ) ;
108122 this . statusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
109123 if ( this . config . testExplorer ) {
@@ -186,6 +200,19 @@ export class Ctx implements RustAnalyzerExtensionApi {
186200 throw new Error ( message ) ;
187201 } ,
188202 ) ;
203+ text ( spawn ( this . _serverPath , [ "--version" ] ) . stdout . setEncoding ( "utf-8" ) ) . then (
204+ ( data ) => {
205+ const prefix = `rust-analyzer ` ;
206+ this . _serverVersion = data
207+ . slice ( data . startsWith ( prefix ) ? prefix . length : 0 )
208+ . trim ( ) ;
209+ this . refreshServerStatus ( ) ;
210+ } ,
211+ ( _ ) => {
212+ this . _serverVersion = "<unknown>" ;
213+ this . refreshServerStatus ( ) ;
214+ } ,
215+ ) ;
189216 const newEnv = Object . assign ( { } , process . env , this . config . serverExtraEnv ) ;
190217 const run : lc . Executable = {
191218 command : this . _serverPath ,
@@ -372,10 +399,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
372399 return this . extCtx . subscriptions ;
373400 }
374401
375- get serverPath ( ) : string | undefined {
376- return this . _serverPath ;
377- }
378-
379402 setWorkspaces ( workspaces : JsonProject [ ] ) {
380403 this . config . discoveredWorkspaces = workspaces ;
381404 }
@@ -475,23 +498,24 @@ export class Ctx implements RustAnalyzerExtensionApi {
475498 if ( statusBar . tooltip . value ) {
476499 statusBar . tooltip . appendMarkdown ( "\n\n---\n\n" ) ;
477500 }
478- statusBar . tooltip . appendMarkdown ( "\n\n[Open Logs](command:rust-analyzer.openLogs)" ) ;
479- statusBar . tooltip . appendMarkdown (
480- `\n\n[${
481- this . config . checkOnSave ? "Disable" : "Enable"
482- } Check on Save](command:rust-analyzer.toggleCheckOnSave)`,
483- ) ;
484- statusBar . tooltip . appendMarkdown (
485- "\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)" ,
486- ) ;
487- statusBar . tooltip . appendMarkdown (
488- "\n\n[Rebuild Proc Macros](command:rust-analyzer.rebuildProcMacros)" ,
489- ) ;
501+
502+ const toggleCheckOnSave = this . config . checkOnSave ? "Disable" : "Enable" ;
490503 statusBar . tooltip . appendMarkdown (
491- "\n\n[Restart server](command:rust-analyzer.restartServer)" ,
504+ `[Extension Info](command:analyzer.serverVersion "Show version and server binary info"): Version ${ this . version } , Server Version ${ this . _serverVersion } ` +
505+ "\n\n---\n\n" +
506+ '[$(terminal) Open Logs](command:rust-analyzer.openLogs "Open the server logs")' +
507+ "\n\n" +
508+ `[$(settings) ${ toggleCheckOnSave } Check on Save](command:rust-analyzer.toggleCheckOnSave "Temporarily ${ toggleCheckOnSave . toLowerCase ( ) } check on save functionality")` +
509+ "\n\n" +
510+ '[$(refresh) Reload Workspace](command:rust-analyzer.reloadWorkspace "Reload and rediscover workspaces")' +
511+ "\n\n" +
512+ '[$(symbol-property) Rebuild Build Dependencies](command:rust-analyzer.rebuildProcMacros "Rebuild build scripts and proc-macros")' +
513+ "\n\n" +
514+ '[$(stop-circle) Stop server](command:rust-analyzer.stopServer "Stop the server")' +
515+ "\n\n" +
516+ '[$(debug-restart) Restart server](command:rust-analyzer.restartServer "Restart the server")' ,
492517 ) ;
493- statusBar . tooltip . appendMarkdown ( "\n\n[Stop server](command:rust-analyzer.stopServer)" ) ;
494- if ( ! status . quiescent ) icon = "$(sync~spin) " ;
518+ if ( ! status . quiescent ) icon = "$(loading~spin) " ;
495519 statusBar . text = `${ icon } rust-analyzer` ;
496520 }
497521
0 commit comments