diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index bbe06d3b8a..9f4e3ff33e 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -277,8 +277,8 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise x != null); if (failures.length === 0) { - if (containsString(missing, 'go-langserver') || containsString(missing, 'gopls')) { - outputChannel.appendLine('Reload VS Code window to use the Go language server'); + if (containsString(missing, 'gopls')) { + outputChannel.appendLine('Reload VS Code window to use the Go language server.'); } outputChannel.appendLine('All tools successfully installed. You are ready to Go :).'); return; @@ -320,7 +320,6 @@ export async function promptForMissingTool(toolName: string) { return; } } - const installOptions = ['Install']; let missing = await getMissingTools(goVersion); if (!containsTool(missing, tool)) { diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts index 5afa43fcf7..06793132a7 100644 --- a/src/goLanguageServer.ts +++ b/src/goLanguageServer.ts @@ -15,21 +15,10 @@ import { FormattingOptions, HandleDiagnosticsSignature, LanguageClient, - ProvideCompletionItemsSignature, - ProvideDefinitionSignature, ProvideDocumentFormattingEditsSignature, - ProvideDocumentHighlightsSignature, ProvideDocumentLinksSignature, - ProvideDocumentSymbolsSignature, - ProvideHoverSignature, - ProvideReferencesSignature, - ProvideRenameEditsSignature, - ProvideSignatureHelpSignature, - ProvideWorkspaceSymbolsSignature, RevealOutputChannelOn } from 'vscode-languageclient'; -import { ProvideImplementationSignature } from 'vscode-languageclient/lib/implementation'; -import { ProvideTypeDefinitionSignature } from 'vscode-languageclient/lib/typeDefinition'; import WebRequest = require('web-request'); import { GoDefinitionProvider } from './goDeclaration'; import { GoHoverProvider } from './goExtraInfo'; @@ -291,13 +280,11 @@ export function parseLanguageServerConfig(): LanguageServerConfig { } /** - * Get the absolute path to the language server to be used. - * If the required tool is not available, then user is prompted to install it. - * This supports the language servers from both Google and Sourcegraph with the - * former getting a precedence over the latter + * If the user has enabled the language server, return the absolute path to the + * correct binary. If the required tool is not available, prompt the user to + * install it. Only gopls is officially supported. */ export function getLanguageServerToolPath(): string { - // If language server is not enabled, return const goConfig = getGoConfig(); if (!goConfig['useLanguageServer']) { return; @@ -311,39 +298,42 @@ export function getLanguageServerToolPath(): string { return; } - // Get the path to gopls or any alternative that the user might have set for gopls. - const goplsBinaryPath = getBinPath('gopls'); - if (path.isAbsolute(goplsBinaryPath)) { - return goplsBinaryPath; - } - - // Get the path to go-langserver or any alternative that the user might have set for go-langserver. - const golangserverBinaryPath = getBinPath('go-langserver'); - if (path.isAbsolute(golangserverBinaryPath)) { - return golangserverBinaryPath; - } - - // If no language server path has been found, notify the user. + // Determine which language server the user has selected. + // gopls is the default choice. let languageServerOfChoice = 'gopls'; if (goConfig['alternateTools']) { const goplsAlternate = goConfig['alternateTools']['gopls']; - const golangserverAlternate = goConfig['alternateTools']['go-langserver']; - if (typeof goplsAlternate === 'string') { + + // Check if the user has set the deprecated "go-langserver" setting. + if (goConfig['alternateTools']['go-langserver']) { + vscode.window.showErrorMessage(`The "go.alternateTools" setting for "go-langserver" has been deprecated. +Please set "gopls" instead, and then reload the VS Code window.`); + return; + } + if (goplsAlternate) { + if (typeof goplsAlternate !== 'string') { + vscode.window.showErrorMessage(`Unexpected type for "go.alternateTools" setting for "gopls": ${typeof goplsAlternate}.`); + return; + } languageServerOfChoice = getToolFromToolPath(goplsAlternate); - } else if (typeof golangserverAlternate === 'string') { - languageServerOfChoice = getToolFromToolPath(golangserverAlternate); } } - // Only gopls and go-langserver are supported. - if (languageServerOfChoice !== 'gopls' && languageServerOfChoice !== 'go-langserver') { + // Get the path to the language server binary. + const languageServerBinPath = getBinPath(languageServerOfChoice); + if (path.isAbsolute(languageServerBinPath)) { + return languageServerBinPath; + } + + // Installation of gopls is supported. Other language servers must be installed manually. + if (languageServerOfChoice !== 'gopls') { vscode.window.showErrorMessage( - `Cannot find the language server ${languageServerOfChoice}. Please install it and reload this VS Code window` + `Cannot find the language server ${languageServerOfChoice}. Please install it and reload this VS Code window.` ); return; } + // Otherwise, prompt the user to install the language server. promptForMissingTool(languageServerOfChoice); - vscode.window.showInformationMessage('Reload VS Code window after installing the Go language server.'); } function allFoldersHaveSameGopath(): boolean { diff --git a/src/goTools.ts b/src/goTools.ts index 73ae27032a..0121a4aea4 100644 --- a/src/goTools.ts +++ b/src/goTools.ts @@ -121,7 +121,8 @@ export function getConfiguredTools(goVersion: GoVersion): Tool[] { // Add the linter that was chosen by the user. maybeAddTool(goConfig['lintTool']); - // Add the language server for Go versions > 1.10 if user has choosen to do so + // Add the language server for Go versions > 1.10 if user has choosen to do so. + // Respect the go.alternateTools setting. if (goConfig['useLanguageServer'] && goVersion.gt('1.10')) { maybeAddTool('gopls'); } @@ -260,12 +261,6 @@ const allToolsInformation: { [key: string]: Tool } = { isImportant: true, description: 'Linter' }, - 'go-langserver': { - name: 'go-langserver', - importPath: 'github.com/sourcegraph/go-langserver', - isImportant: false, - description: 'Language Server from Sourcegraph' - }, 'gopls': { name: 'gopls', importPath: 'golang.org/x/tools/gopls',