@@ -36,7 +36,7 @@ import {
3636 ResponseError ,
3737 RevealOutputChannelOn
3838} from 'vscode-languageclient' ;
39- import { LanguageClient , ServerOptions } from 'vscode-languageclient/node' ;
39+ import { Executable , LanguageClient , ServerOptions } from 'vscode-languageclient/node' ;
4040import { getGoConfig , getGoplsConfig , extensionInfo } from '../config' ;
4141import { toolExecutionEnvironment } from '../goEnv' ;
4242import { GoDocumentFormattingEditProvider , usingCustomFormatTool } from './legacy/goFormat' ;
@@ -336,36 +336,6 @@ export function toServerInfo(res?: InitializeResult): ServerInfo | undefined {
336336 return info ;
337337}
338338
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-
369339export class GoLanguageClient extends LanguageClient implements vscode . Disposable {
370340 constructor (
371341 id : string ,
@@ -409,8 +379,18 @@ type VulncheckEvent = {
409379// The returned language client need to be started before use.
410380export async function buildLanguageClient (
411381 goCtx : GoExtensionContext ,
412- cfg : BuildLanguageClientOption
382+ cfg : LanguageServerConfig
413383) : 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+
414394 await getLocalGoplsVersion ( cfg ) ; // populate and cache cfg.version
415395 const goplsWorkspaceConfig = await adjustGoplsWorkspaceConfiguration ( cfg , getGoplsConfig ( ) , 'gopls' , undefined ) ;
416396
@@ -424,15 +404,20 @@ export async function buildLanguageClient(
424404 const pendingVulncheckProgressToken = new Map < ProgressToken , any > ( ) ;
425405 const onDidChangeVulncheckResultEmitter = new vscode . EventEmitter < VulncheckEvent > ( ) ;
426406
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+
427416 // cfg is captured by closures for later use during error report.
428417 const c = new GoLanguageClient (
429418 'go' , // id
430419 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 ,
436421 {
437422 initializationOptions : goplsWorkspaceConfig ,
438423 documentSelector : GoDocumentSelector ,
@@ -442,8 +427,8 @@ export async function buildLanguageClient(
442427 ( uri . scheme ? uri : uri . with ( { scheme : 'file' } ) ) . toString ( ) ,
443428 protocol2Code : ( uri : string ) => vscode . Uri . parse ( uri )
444429 } ,
445- outputChannel : cfg . outputChannel ,
446- traceOutputChannel : cfg . traceOutputChannel ,
430+ outputChannel : goCtx . serverOutputChannel ,
431+ traceOutputChannel : goCtx . serverTraceChannel ,
447432 revealOutputChannelOn : RevealOutputChannelOn . Never ,
448433 initializationFailedHandler : ( error : ResponseError < InitializeError > ) : boolean => {
449434 initializationError = error ;
0 commit comments