From 5c86f6ac92b38382272369b6c0753869e0c02a8b Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 4 Feb 2020 17:06:53 -0500 Subject: [PATCH 1/6] refactor handling for go-langserver installation --- src/goInstallTools.ts | 1 - src/goLanguageServer.ts | 61 ++++++++++++++++++----------------------- src/goTools.ts | 9 ++++-- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 93b42e9a17..d0202fefe0 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -314,7 +314,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 57633269ac..c747d4a91d 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 (Google) and go-langserver (Sourcegraph) are supported. */ export function getLanguageServerToolPath(): string { - // If language server is not enabled, return const goConfig = getGoConfig(); if (!goConfig['useLanguageServer']) { return; @@ -311,39 +298,43 @@ 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']; + + // Check if the user has set the deprecated "go-langserver" setting. const golangserverAlternate = goConfig['alternateTools']['go-langserver']; - if (typeof goplsAlternate === 'string') { + if (golangserverAlternate) { + vscode.window.showErrorMessage(`The "go.alternateTools" setting for "go-langserver" has been deprecated. Please use "gopls" instead.`); + 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. + // Get the path to the language server binary. + const languageServerBinPath = getBinPath(languageServerOfChoice); + if (path.isAbsolute(languageServerBinPath)) { + return languageServerBinPath; + } + + // Installation of gopls and go-langserver is supported. + // Other language servers must be installed manually. if (languageServerOfChoice !== 'gopls' && languageServerOfChoice !== 'go-langserver') { 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 9b3078037d..33e3cf8cc5 100644 --- a/src/goTools.ts +++ b/src/goTools.ts @@ -121,9 +121,14 @@ 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'); + if (goConfig['alternateTools']['gopls']) { + maybeAddTool(goConfig['alternateTools']['gopls']); + } else { + maybeAddTool('gopls'); + } } if (goLiveErrorsEnabled()) { From acd5d2bb90ed1da76e55fc91e6b50af52e06ffc2 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 4 Feb 2020 23:32:04 -0500 Subject: [PATCH 2/6] mention reload in the error message --- src/goLanguageServer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts index c747d4a91d..fb744d89a5 100644 --- a/src/goLanguageServer.ts +++ b/src/goLanguageServer.ts @@ -307,7 +307,8 @@ export function getLanguageServerToolPath(): string { // Check if the user has set the deprecated "go-langserver" setting. const golangserverAlternate = goConfig['alternateTools']['go-langserver']; if (golangserverAlternate) { - vscode.window.showErrorMessage(`The "go.alternateTools" setting for "go-langserver" has been deprecated. Please use "gopls" instead.`); + 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) { From 76207eae60b77c57164d8f64b2a0e61aea253633 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Wed, 5 Feb 2020 14:00:33 -0500 Subject: [PATCH 3/6] update comment --- src/goLanguageServer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts index fb744d89a5..3353381635 100644 --- a/src/goLanguageServer.ts +++ b/src/goLanguageServer.ts @@ -282,7 +282,7 @@ export function parseLanguageServerConfig(): LanguageServerConfig { /** * 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 (Google) and go-langserver (Sourcegraph) are supported. + * install it. Only gopls is officially supported. */ export function getLanguageServerToolPath(): string { const goConfig = getGoConfig(); From f0ad023ba02412757bee4ac53c6fe2a711ad4c94 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 11 Feb 2020 16:38:56 -0500 Subject: [PATCH 4/6] remove support for go-langserver --- src/goLanguageServer.ts | 2 +- src/goTools.ts | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts index 3353381635..6d8413bba6 100644 --- a/src/goLanguageServer.ts +++ b/src/goLanguageServer.ts @@ -327,7 +327,7 @@ Please set "gopls" instead, and then reload the VS Code window.`); // Installation of gopls and go-langserver is supported. // Other language servers must be installed manually. - if (languageServerOfChoice !== 'gopls' && languageServerOfChoice !== 'go-langserver') { + if (languageServerOfChoice !== 'gopls') { vscode.window.showErrorMessage( `Cannot find the language server ${languageServerOfChoice}. Please install it and reload this VS Code window.` ); diff --git a/src/goTools.ts b/src/goTools.ts index 33e3cf8cc5..d5707b1d91 100644 --- a/src/goTools.ts +++ b/src/goTools.ts @@ -124,11 +124,7 @@ export function getConfiguredTools(goVersion: GoVersion): Tool[] { // 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')) { - if (goConfig['alternateTools']['gopls']) { - maybeAddTool(goConfig['alternateTools']['gopls']); - } else { - maybeAddTool('gopls'); - } + maybeAddTool('gopls'); } if (goLiveErrorsEnabled()) { From 873d6c58df6bcb89042640e909ee6f422931e917 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 11 Feb 2020 16:39:53 -0500 Subject: [PATCH 5/6] remove support for installing go-langserver --- src/goTools.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/goTools.ts b/src/goTools.ts index d5707b1d91..cd2cc380cc 100644 --- a/src/goTools.ts +++ b/src/goTools.ts @@ -261,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', From 137073b7bd793c14c2000774a3cdbe97cff082bf Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 11 Feb 2020 16:43:49 -0500 Subject: [PATCH 6/6] remove more go-langserver checks --- src/goInstallTools.ts | 4 ++-- src/goLanguageServer.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index d0202fefe0..8f92aadb05 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -271,8 +271,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; diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts index 6d8413bba6..a2fdc2fe8f 100644 --- a/src/goLanguageServer.ts +++ b/src/goLanguageServer.ts @@ -305,8 +305,7 @@ export function getLanguageServerToolPath(): string { const goplsAlternate = goConfig['alternateTools']['gopls']; // Check if the user has set the deprecated "go-langserver" setting. - const golangserverAlternate = goConfig['alternateTools']['go-langserver']; - if (golangserverAlternate) { + 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; @@ -325,8 +324,7 @@ Please set "gopls" instead, and then reload the VS Code window.`); return languageServerBinPath; } - // Installation of gopls and go-langserver is supported. - // Other language servers must be installed manually. + // 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.`