Skip to content

Commit d60e8c1

Browse files
committed
Refactor handling for go-langserver installation
Remove the code that handled this in the language server installation, and be careful to only install the tool specified by the user. Also, remove some unused import lines in the goLanguageServer.ts file. Fixes microsoft/vscode-go#3028. Change-Id: I813c39f7d4997b63f7a87c1551de23df2808259c GitHub-Last-Rev: 9aa7363 GitHub-Pull-Request: #2 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/222417 Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent c6967b3 commit d60e8c1

File tree

3 files changed

+31
-47
lines changed

3 files changed

+31
-47
lines changed

src/goInstallTools.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
277277
outputChannel.appendLine(''); // Blank line for spacing
278278
const failures = res.filter((x) => x != null);
279279
if (failures.length === 0) {
280-
if (containsString(missing, 'go-langserver') || containsString(missing, 'gopls')) {
281-
outputChannel.appendLine('Reload VS Code window to use the Go language server');
280+
if (containsString(missing, 'gopls')) {
281+
outputChannel.appendLine('Reload VS Code window to use the Go language server.');
282282
}
283283
outputChannel.appendLine('All tools successfully installed. You are ready to Go :).');
284284
return;
@@ -320,7 +320,6 @@ export async function promptForMissingTool(toolName: string) {
320320
return;
321321
}
322322
}
323-
324323
const installOptions = ['Install'];
325324
let missing = await getMissingTools(goVersion);
326325
if (!containsTool(missing, tool)) {

src/goLanguageServer.ts

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,10 @@ import {
1515
FormattingOptions,
1616
HandleDiagnosticsSignature,
1717
LanguageClient,
18-
ProvideCompletionItemsSignature,
19-
ProvideDefinitionSignature,
2018
ProvideDocumentFormattingEditsSignature,
21-
ProvideDocumentHighlightsSignature,
2219
ProvideDocumentLinksSignature,
23-
ProvideDocumentSymbolsSignature,
24-
ProvideHoverSignature,
25-
ProvideReferencesSignature,
26-
ProvideRenameEditsSignature,
27-
ProvideSignatureHelpSignature,
28-
ProvideWorkspaceSymbolsSignature,
2920
RevealOutputChannelOn
3021
} from 'vscode-languageclient';
31-
import { ProvideImplementationSignature } from 'vscode-languageclient/lib/implementation';
32-
import { ProvideTypeDefinitionSignature } from 'vscode-languageclient/lib/typeDefinition';
3322
import WebRequest = require('web-request');
3423
import { GoDefinitionProvider } from './goDeclaration';
3524
import { GoHoverProvider } from './goExtraInfo';
@@ -291,13 +280,11 @@ export function parseLanguageServerConfig(): LanguageServerConfig {
291280
}
292281

293282
/**
294-
* Get the absolute path to the language server to be used.
295-
* If the required tool is not available, then user is prompted to install it.
296-
* This supports the language servers from both Google and Sourcegraph with the
297-
* former getting a precedence over the latter
283+
* If the user has enabled the language server, return the absolute path to the
284+
* correct binary. If the required tool is not available, prompt the user to
285+
* install it. Only gopls is officially supported.
298286
*/
299287
export function getLanguageServerToolPath(): string {
300-
// If language server is not enabled, return
301288
const goConfig = getGoConfig();
302289
if (!goConfig['useLanguageServer']) {
303290
return;
@@ -311,39 +298,42 @@ export function getLanguageServerToolPath(): string {
311298
return;
312299
}
313300

314-
// Get the path to gopls or any alternative that the user might have set for gopls.
315-
const goplsBinaryPath = getBinPath('gopls');
316-
if (path.isAbsolute(goplsBinaryPath)) {
317-
return goplsBinaryPath;
318-
}
319-
320-
// Get the path to go-langserver or any alternative that the user might have set for go-langserver.
321-
const golangserverBinaryPath = getBinPath('go-langserver');
322-
if (path.isAbsolute(golangserverBinaryPath)) {
323-
return golangserverBinaryPath;
324-
}
325-
326-
// If no language server path has been found, notify the user.
301+
// Determine which language server the user has selected.
302+
// gopls is the default choice.
327303
let languageServerOfChoice = 'gopls';
328304
if (goConfig['alternateTools']) {
329305
const goplsAlternate = goConfig['alternateTools']['gopls'];
330-
const golangserverAlternate = goConfig['alternateTools']['go-langserver'];
331-
if (typeof goplsAlternate === 'string') {
306+
307+
// Check if the user has set the deprecated "go-langserver" setting.
308+
if (goConfig['alternateTools']['go-langserver']) {
309+
vscode.window.showErrorMessage(`The "go.alternateTools" setting for "go-langserver" has been deprecated.
310+
Please set "gopls" instead, and then reload the VS Code window.`);
311+
return;
312+
}
313+
if (goplsAlternate) {
314+
if (typeof goplsAlternate !== 'string') {
315+
vscode.window.showErrorMessage(`Unexpected type for "go.alternateTools" setting for "gopls": ${typeof goplsAlternate}.`);
316+
return;
317+
}
332318
languageServerOfChoice = getToolFromToolPath(goplsAlternate);
333-
} else if (typeof golangserverAlternate === 'string') {
334-
languageServerOfChoice = getToolFromToolPath(golangserverAlternate);
335319
}
336320
}
337-
// Only gopls and go-langserver are supported.
338-
if (languageServerOfChoice !== 'gopls' && languageServerOfChoice !== 'go-langserver') {
321+
// Get the path to the language server binary.
322+
const languageServerBinPath = getBinPath(languageServerOfChoice);
323+
if (path.isAbsolute(languageServerBinPath)) {
324+
return languageServerBinPath;
325+
}
326+
327+
// Installation of gopls is supported. Other language servers must be installed manually.
328+
if (languageServerOfChoice !== 'gopls') {
339329
vscode.window.showErrorMessage(
340-
`Cannot find the language server ${languageServerOfChoice}. Please install it and reload this VS Code window`
330+
`Cannot find the language server ${languageServerOfChoice}. Please install it and reload this VS Code window.`
341331
);
342332
return;
343333
}
334+
344335
// Otherwise, prompt the user to install the language server.
345336
promptForMissingTool(languageServerOfChoice);
346-
vscode.window.showInformationMessage('Reload VS Code window after installing the Go language server.');
347337
}
348338

349339
function allFoldersHaveSameGopath(): boolean {

src/goTools.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ export function getConfiguredTools(goVersion: GoVersion): Tool[] {
121121
// Add the linter that was chosen by the user.
122122
maybeAddTool(goConfig['lintTool']);
123123

124-
// Add the language server for Go versions > 1.10 if user has choosen to do so
124+
// Add the language server for Go versions > 1.10 if user has choosen to do so.
125+
// Respect the go.alternateTools setting.
125126
if (goConfig['useLanguageServer'] && goVersion.gt('1.10')) {
126127
maybeAddTool('gopls');
127128
}
@@ -260,12 +261,6 @@ const allToolsInformation: { [key: string]: Tool } = {
260261
isImportant: true,
261262
description: 'Linter'
262263
},
263-
'go-langserver': {
264-
name: 'go-langserver',
265-
importPath: 'github.com/sourcegraph/go-langserver',
266-
isImportant: false,
267-
description: 'Language Server from Sourcegraph'
268-
},
269264
'gopls': {
270265
name: 'gopls',
271266
importPath: 'golang.org/x/tools/gopls',

0 commit comments

Comments
 (0)