@@ -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' ;
3322import WebRequest = require( 'web-request' ) ;
3423import { GoDefinitionProvider } from './goDeclaration' ;
3524import { 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 */
299287export 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
349339function allFoldersHaveSameGopath ( ) : boolean {
0 commit comments