@@ -25,6 +25,7 @@ import {
25
25
ExecuteCommandSignature ,
26
26
HandleDiagnosticsSignature ,
27
27
InitializeError ,
28
+ InitializeResult ,
28
29
Message ,
29
30
ProvideCodeLensesSignature ,
30
31
ProvideCompletionItemsSignature ,
@@ -94,12 +95,24 @@ export interface LanguageServerConfig {
94
95
// Global variables used for management of the language client.
95
96
// They are global so that the server can be easily restarted with
96
97
// new configurations.
98
+ // TODO: refactor it. These can be encapsulated in a single LanguageServer class
99
+ // that keeps track of the state of the active language server instance.
97
100
export let languageClient : LanguageClient ;
98
101
let languageServerDisposable : vscode . Disposable ;
99
102
export let latestConfig : LanguageServerConfig ;
100
103
export let serverOutputChannel : vscode . OutputChannel ;
101
104
export let languageServerIsRunning = false ;
102
105
106
+ // serverInfo is the information from the server received during initialization.
107
+ export let serverInfo : ServerInfo = undefined ;
108
+
109
+ interface ServerInfo {
110
+ Name : string ;
111
+ Version ?: string ;
112
+ GoVersion ?: string ;
113
+ Commands ?: string [ ] ;
114
+ }
115
+
103
116
const languageServerStartMutex = new Mutex ( ) ;
104
117
105
118
let serverTraceChannel : vscode . OutputChannel ;
@@ -451,9 +464,36 @@ async function startLanguageServer(ctx: vscode.ExtensionContext, config: Languag
451
464
languageServerDisposable = languageClient . start ( ) ;
452
465
ctx . subscriptions . push ( languageServerDisposable ) ;
453
466
await languageClient . onReady ( ) ;
467
+ serverInfo = toServerInfo ( languageClient . initializeResult ) ;
468
+
469
+ console . log ( `Server: ${ JSON . stringify ( serverInfo , null , 2 ) } ` ) ;
454
470
return true ;
455
471
}
456
472
473
+ function toServerInfo ( res ?: InitializeResult ) : ServerInfo | undefined {
474
+ if ( ! res ) return undefined ;
475
+
476
+ const info : ServerInfo = {
477
+ Commands : res . capabilities ?. executeCommandProvider ?. commands || [ ] ,
478
+ Name : res . serverInfo ?. name || 'unknown'
479
+ } ;
480
+
481
+ try {
482
+ interface serverVersionJSON {
483
+ GoVersion ?: string ;
484
+ Version ?: string ;
485
+ // before gopls 0.8.0
486
+ version ?: string ;
487
+ }
488
+ const v = < serverVersionJSON > ( res . serverInfo ?. version ? JSON . parse ( res . serverInfo . version ) : { } ) ;
489
+ info . Version = v . Version || v . version ;
490
+ info . GoVersion = v . GoVersion ;
491
+ } catch ( e ) {
492
+ // gopls is not providing any info, that's ok.
493
+ }
494
+ return info ;
495
+ }
496
+
457
497
export interface BuildLanguageClientOption extends LanguageServerConfig {
458
498
outputChannel ?: vscode . OutputChannel ;
459
499
traceOutputChannel ?: vscode . OutputChannel ;
0 commit comments