Skip to content

Commit e9409b1

Browse files
committed
extension/src/language: remove interface wrapping LanguageServerConfig
buildLanguageClientOption is confusing because it's wrapping over LanguageServerConfig with additional channel information. Explicitly annotate the type of serverOptions with additional documentation. Remove no effect flag from gopls "-mode=stdio". For #3697 Change-Id: I7a04ce0ff2e76bb960bfda714c83c5b6823854cc Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/654435 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Madeline Kalil <[email protected]> Reviewed-by: Peter Weinberger <[email protected]> kokoro-CI: kokoro <[email protected]>
1 parent 3a91503 commit e9409b1

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

extension/src/commands/startLanguageServer.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { GoExtensionContext } from '../context';
1111
import { outputChannel, updateLanguageServerIconGoStatusBar } from '../goStatus';
1212
import {
1313
buildLanguageClient,
14-
buildLanguageClientOption,
1514
buildLanguageServerConfig,
1615
errorKind,
1716
RestartReason,
@@ -85,7 +84,7 @@ export const startLanguageServer: CommandFactory = (ctx, goCtx) => {
8584
return;
8685
}
8786

88-
goCtx.languageClient = await buildLanguageClient(goCtx, buildLanguageClientOption(goCtx, cfg));
87+
goCtx.languageClient = await buildLanguageClient(goCtx, cfg);
8988
await goCtx.languageClient.start();
9089
goCtx.serverInfo = toServerInfo(goCtx.languageClient.initializeResult);
9190
goCtx.telemetryService = new TelemetryService(

extension/src/language/goLanguageServer.ts

+24-39
Original file line numberDiff line numberDiff line change
@@ -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';
4040
import { getGoConfig, getGoplsConfig, extensionInfo } from '../config';
4141
import { toolExecutionEnvironment } from '../goEnv';
4242
import { 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-
369339
export 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.
410380
export 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;

extension/test/gopls/goplsTestEnv.utils.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { LanguageClient } from 'vscode-languageclient/node';
1212
import { getGoConfig } from '../../src/config';
1313
import {
1414
buildLanguageClient,
15-
BuildLanguageClientOption,
15+
LanguageServerConfig,
1616
buildLanguageServerConfig,
1717
toServerInfo
1818
} from '../../src/language/goLanguageServer';
@@ -108,14 +108,16 @@ export class Env {
108108
if (!goConfig) {
109109
goConfig = getGoConfig();
110110
}
111-
const cfg: BuildLanguageClientOption = await buildLanguageServerConfig(
111+
const cfg: LanguageServerConfig = await buildLanguageServerConfig(
112112
Object.create(goConfig, {
113113
useLanguageServer: { value: true },
114114
languageServerFlags: { value: ['-rpc.trace'] } // enable rpc tracing to monitor progress reports
115115
})
116116
);
117-
cfg.outputChannel = this.fakeOutputChannel; // inject our fake output channel.
118117
this.goCtx.latestConfig = cfg;
118+
// Inject fake output channel.
119+
this.goCtx.serverOutputChannel = this.fakeOutputChannel;
120+
this.goCtx.serverTraceChannel = this.fakeOutputChannel;
119121
this.languageClient = await buildLanguageClient(this.goCtx, cfg);
120122
if (!this.languageClient) {
121123
throw new Error('Language client not initialized.');

0 commit comments

Comments
 (0)