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: 9aa7363eae5ba645b8b9f1e01d6261e8c841c4c6
GitHub-Pull-Request: golang/vscode-go#2
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/222417
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts
index bbe06d3..9f4e3ff 100644
--- a/src/goInstallTools.ts
+++ b/src/goInstallTools.ts
@@ -277,8 +277,8 @@
 			outputChannel.appendLine(''); // Blank line for spacing
 			const failures = res.filter((x) => 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 @@
 			return;
 		}
 	}
-
 	const installOptions = ['Install'];
 	let missing = await getMissingTools(goVersion);
 	if (!containsTool(missing, tool)) {
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index 5afa43f..0679313 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -15,21 +15,10 @@
 	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 @@
 }
 
 /**
- * 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 @@
 		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 73ae270..0121a4a 100644
--- a/src/goTools.ts
+++ b/src/goTools.ts
@@ -121,7 +121,8 @@
 	// 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 @@
 		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',