@@ -15,21 +15,10 @@ import {
15
15
FormattingOptions ,
16
16
HandleDiagnosticsSignature ,
17
17
LanguageClient ,
18
- ProvideCompletionItemsSignature ,
19
- ProvideDefinitionSignature ,
20
18
ProvideDocumentFormattingEditsSignature ,
21
- ProvideDocumentHighlightsSignature ,
22
19
ProvideDocumentLinksSignature ,
23
- ProvideDocumentSymbolsSignature ,
24
- ProvideHoverSignature ,
25
- ProvideReferencesSignature ,
26
- ProvideRenameEditsSignature ,
27
- ProvideSignatureHelpSignature ,
28
- ProvideWorkspaceSymbolsSignature ,
29
20
RevealOutputChannelOn
30
21
} from 'vscode-languageclient' ;
31
- import { ProvideImplementationSignature } from 'vscode-languageclient/lib/implementation' ;
32
- import { ProvideTypeDefinitionSignature } from 'vscode-languageclient/lib/typeDefinition' ;
33
22
import WebRequest = require( 'web-request' ) ;
34
23
import { GoDefinitionProvider } from './goDeclaration' ;
35
24
import { GoHoverProvider } from './goExtraInfo' ;
@@ -291,13 +280,11 @@ export function parseLanguageServerConfig(): LanguageServerConfig {
291
280
}
292
281
293
282
/**
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.
298
286
*/
299
287
export function getLanguageServerToolPath ( ) : string {
300
- // If language server is not enabled, return
301
288
const goConfig = getGoConfig ( ) ;
302
289
if ( ! goConfig [ 'useLanguageServer' ] ) {
303
290
return ;
@@ -311,39 +298,42 @@ export function getLanguageServerToolPath(): string {
311
298
return ;
312
299
}
313
300
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.
327
303
let languageServerOfChoice = 'gopls' ;
328
304
if ( goConfig [ 'alternateTools' ] ) {
329
305
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
+ }
332
318
languageServerOfChoice = getToolFromToolPath ( goplsAlternate ) ;
333
- } else if ( typeof golangserverAlternate === 'string' ) {
334
- languageServerOfChoice = getToolFromToolPath ( golangserverAlternate ) ;
335
319
}
336
320
}
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' ) {
339
329
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. `
341
331
) ;
342
332
return ;
343
333
}
334
+
344
335
// Otherwise, prompt the user to install the language server.
345
336
promptForMissingTool ( languageServerOfChoice ) ;
346
- vscode . window . showInformationMessage ( 'Reload VS Code window after installing the Go language server.' ) ;
347
337
}
348
338
349
339
function allFoldersHaveSameGopath ( ) : boolean {
0 commit comments