-
Notifications
You must be signed in to change notification settings - Fork 798
Refactor handling for go-langserver installation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c86f6a
refactor handling for go-langserver installation
stamblerre acd5d2b
mention reload in the error message
stamblerre 76207ea
update comment
stamblerre f0ad023
remove support for go-langserver
stamblerre 873d6c5
remove support for installing go-langserver
stamblerre 137073b
remove more go-langserver checks
stamblerre 9aa7363
Merge branch 'master' of https://github.com/stamblerre/vscode-go into…
stamblerre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about updating this to add |
||
); | ||
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 { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user had
gopls
installed in this case, then shouldn't we gracefully switch to that?And also perhaps add a button to update the settings to remove
go-langserver
from the alternate tools setting?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if the user didn't had
gopls
installed, have a button to installgopls
?