@@ -36,7 +36,7 @@ import {
36
36
ResponseError ,
37
37
RevealOutputChannelOn
38
38
} from 'vscode-languageclient' ;
39
- import { LanguageClient , ServerOptions } from 'vscode-languageclient/node' ;
39
+ import { Executable , LanguageClient , ServerOptions } from 'vscode-languageclient/node' ;
40
40
import { getGoConfig , getGoplsConfig , extensionInfo } from '../config' ;
41
41
import { toolExecutionEnvironment } from '../goEnv' ;
42
42
import { GoDocumentFormattingEditProvider , usingCustomFormatTool } from './legacy/goFormat' ;
@@ -336,36 +336,6 @@ export function toServerInfo(res?: InitializeResult): ServerInfo | undefined {
336
336
return info ;
337
337
}
338
338
339
- export interface BuildLanguageClientOption extends LanguageServerConfig {
340
- outputChannel ?: vscode . OutputChannel ;
341
- traceOutputChannel ?: vscode . OutputChannel ;
342
- }
343
-
344
- // buildLanguageClientOption returns the default, extra configuration
345
- // used in building a new LanguageClient instance. Options specified
346
- // in LanguageServerConfig
347
- export function buildLanguageClientOption (
348
- goCtx : GoExtensionContext ,
349
- cfg : LanguageServerConfig
350
- ) : BuildLanguageClientOption {
351
- // Reuse the same output channel for each instance of the server.
352
- if ( cfg . enabled ) {
353
- if ( ! goCtx . serverOutputChannel ) {
354
- goCtx . serverOutputChannel = vscode . window . createOutputChannel ( cfg . serverName + ' (server)' ) ;
355
- }
356
- if ( ! goCtx . serverTraceChannel ) {
357
- goCtx . serverTraceChannel = vscode . window . createOutputChannel ( cfg . serverName ) ;
358
- }
359
- }
360
- return Object . assign (
361
- {
362
- outputChannel : goCtx . serverOutputChannel ,
363
- traceOutputChannel : goCtx . serverTraceChannel
364
- } ,
365
- cfg
366
- ) ;
367
- }
368
-
369
339
export class GoLanguageClient extends LanguageClient implements vscode . Disposable {
370
340
constructor (
371
341
id : string ,
@@ -409,8 +379,18 @@ type VulncheckEvent = {
409
379
// The returned language client need to be started before use.
410
380
export async function buildLanguageClient (
411
381
goCtx : GoExtensionContext ,
412
- cfg : BuildLanguageClientOption
382
+ cfg : LanguageServerConfig
413
383
) : Promise < GoLanguageClient > {
384
+ // Reuse the same output channel for each instance of the server.
385
+ if ( cfg . enabled ) {
386
+ if ( ! goCtx . serverOutputChannel ) {
387
+ goCtx . serverOutputChannel = vscode . window . createOutputChannel ( cfg . serverName + ' (server)' ) ;
388
+ }
389
+ if ( ! goCtx . serverTraceChannel ) {
390
+ goCtx . serverTraceChannel = vscode . window . createOutputChannel ( cfg . serverName ) ;
391
+ }
392
+ }
393
+
414
394
await getLocalGoplsVersion ( cfg ) ; // populate and cache cfg.version
415
395
const goplsWorkspaceConfig = await adjustGoplsWorkspaceConfiguration ( cfg , getGoplsConfig ( ) , 'gopls' , undefined ) ;
416
396
@@ -424,15 +404,20 @@ export async function buildLanguageClient(
424
404
const pendingVulncheckProgressToken = new Map < ProgressToken , any > ( ) ;
425
405
const onDidChangeVulncheckResultEmitter = new vscode . EventEmitter < VulncheckEvent > ( ) ;
426
406
407
+ // VSCode-Go prepares the information needed to start the language server.
408
+ // vscode-languageclient-node.LanguageClient will spin up the language
409
+ // server based on the provided information below.
410
+ const serverOption : Executable = {
411
+ command : cfg . path ,
412
+ args : cfg . flags ,
413
+ options : { env : cfg . env }
414
+ } ;
415
+
427
416
// cfg is captured by closures for later use during error report.
428
417
const c = new GoLanguageClient (
429
418
'go' , // id
430
419
cfg . serverName , // name e.g. gopls
431
- {
432
- command : cfg . path ,
433
- args : [ '-mode=stdio' , ...cfg . flags ] ,
434
- options : { env : cfg . env }
435
- } as ServerOptions ,
420
+ serverOption as ServerOptions ,
436
421
{
437
422
initializationOptions : goplsWorkspaceConfig ,
438
423
documentSelector : GoDocumentSelector ,
@@ -442,8 +427,8 @@ export async function buildLanguageClient(
442
427
( uri . scheme ? uri : uri . with ( { scheme : 'file' } ) ) . toString ( ) ,
443
428
protocol2Code : ( uri : string ) => vscode . Uri . parse ( uri )
444
429
} ,
445
- outputChannel : cfg . outputChannel ,
446
- traceOutputChannel : cfg . traceOutputChannel ,
430
+ outputChannel : goCtx . serverOutputChannel ,
431
+ traceOutputChannel : goCtx . serverTraceChannel ,
447
432
revealOutputChannelOn : RevealOutputChannelOn . Never ,
448
433
initializationFailedHandler : ( error : ResponseError < InitializeError > ) : boolean => {
449
434
initializationError = error ;
0 commit comments