-
Notifications
You must be signed in to change notification settings - Fork 645
When using go-languageserver, also use code completion feature #1607
Conversation
Instead of using go-code, use go-languageserver for providing code completion results when enabled. Solves #1593
I wonder if there is some way for the extension to know if the installed version of |
In case executing the binary with an unknown flag does not yield the -gocodecompletion flag in the help output, we assume the version installed is out of date and prompt for updating
src/goInstallTools.ts
Outdated
} | ||
return langServerAvailable; | ||
|
||
// we execute the languageserver using -help so that it will fail and |
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.
This is pretty terrible, but it's the best I could come up with in case we want to make sure an up-to-date version of the language server is installed.
Alternatively we could call go-langserver -version, but I don't really know what do to with the output as it would currently just print sth like v2-dev: https://github.com/sourcegraph/go-langserver/blob/dd4c619b53ae9d18c94e372d23d8710e59f0766b/main.go#L41
This doesn't seem to work at all, I can see |
Ignore my previous comment, this is related to nsf/gocode#510, I opened a ticket sourcegraph/go-langserver#268. I can confirm this works perfectly with go 1.10. @ramya-rao-a ping |
works like a charm for me |
@ramya-rao-a Any input on this one? |
@m90 Do you know the reason why completions are not supported by default by the language server? If this indeed is the case, then I'd prefer for users to opt-in to use the completions from the language server instead of us providing as a default. cc @keegancsmith and @slimsag for input on why completions are not supported by default by the language server. |
src/goInstallTools.ts
Outdated
vscode.window.showInformationMessage('Reload VS Code window after updating the Go language server'); | ||
} | ||
|
||
return langserverSupportsCompletion; |
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.
Here, checkLanguageServer
will return false
for users with older version of the language server stopping them from using the language server altogether.
Instead, create a new function getLanguageServerFlags
that returns all supported flags. Then in goMain
, you can use the result to pass the appropriate flags. This will help in the future when we have other flags.
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.
Instead, create a new function getLanguageServerFlags that returns all supported flags.
Just to double check: for getLanguageServerFlags
you envision sth that reads the output from calling the naked command just above? Or do we already do sth similar elsewhere?
src/goMain.ts
Outdated
@@ -96,7 +96,7 @@ export function activate(ctx: vscode.ExtensionContext): void { | |||
'go-langserver', | |||
{ | |||
command: getBinPath('go-langserver'), | |||
args: ['-mode=stdio', ...langServerFlags], | |||
args: ['-mode=stdio', '-gocodecompletion', ...langServerFlags], |
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.
Pass the func-snippet-enabled
flag as per the setting go.useCodeSnippetsOnFunctionSuggest
src/goMain.ts
Outdated
@@ -110,6 +110,7 @@ export function activate(ctx: vscode.ExtensionContext): void { | |||
|
|||
ctx.subscriptions.push(c.start()); |
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.
Since its possible for users to run the older versions of the language server where completions are not supported, add the below to register the completion provider from the extension
c.onReady().then(() => {
if (c.initializeResult && c.initializeResult.capabilities && !c.initializeResult.capabilities.completionProvider) {
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(), '.', '\"'));
}
});
@ramya-rao-a That's a good question and a valid concern. I do have no idea why completion is behind a flag though. All I know is that when running locally it feels faster and more lightweight, but then again that's very likely to be very subjective. Maybe the lovely Sourcegraph people know why it is the way it is? |
@ramya-rao-a I think this should reflect the requested changes now, feel free to check and let me know if you feel it'd be nicer to put this behind a preference. |
src/goMain.ts
Outdated
]; | ||
|
||
let applicableFlags = configuredLangServerFlags.filter(f => { | ||
return supportedLangServerFlags.some(supported => f.startsWith(supported)); |
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.
why startsWith
and not ===
?
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.
Because for example the supported flags will contain -func-snippet-enabled
but we also pass a value like -func-snippet-enabled=false
.
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.
Ah! Makes sense
I've logged a proposal for the language server to use the Let's wait on what our friends at sourcegraph have to say there before moving forward here |
@m90 Can you update this PR as per the below points?
|
@ramya-rao-a Sure thing. When are you planning to do the next release of the extension? I'm a little swamped right now, so it might take until the weekend or so. |
@m90 In that case, no worries. I can make the changes in your branch and create a vsix file. You can then install that vsix and help with testing? |
I can test if you like. I’m on that branch anyway |
@ramya-rao-a Sounds good, thanks. Let me know when I can give things a test drive. |
@ramya-rao-a So I have been able to unswamp myself and would be happy to still do the requested updates in the coming days. Does that sound like a plan to you or have you already started updating things? |
@m90 I havent started :) so go ahead make the updates |
@ramya-rao-a I pushed the requested changes. Tbh I am not entirely sure how the entire graceful fallback mechanism works now when someone has an older version of |
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.
Main comment in the PR is that we can revert the changes made to support the flag and assume that the user has the latest version of the language server if they have enabled the auto-complete feature.
Other than that, just small changes needed. Thats all.
Thanks for all your work on this!
src/goInstallTools.ts
Outdated
export function checkLanguageServer(): boolean { | ||
// If langserver needs to be used, and is installed, this will return the list of supported flags | ||
// Returns null in all other cases | ||
export function checkLanguageServer(): string[] { |
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.
To keep things simple, lets go with the assumption that the auto-completion feature from language server is available only if the user has the latest language server i.e if the user's version of the language server respects the initalizationOptions
sent.
Towards that end, we can revert the changes made to checkLanguageServer
here
src/goMain.ts
Outdated
@@ -109,7 +117,7 @@ export function activate(ctx: vscode.ExtensionContext): void { | |||
revealOutputChannelOn: RevealOutputChannelOn.Never, | |||
middleware: { | |||
provideDocumentFormattingEdits: (document: vscode.TextDocument, options: FormattingOptions, token: vscode.CancellationToken, next: ProvideDocumentFormattingEditsSignature) => { | |||
if (languageServerExperimentalFeatures['format'] === true) { | |||
if (languageServerExperimentalFeatures['format']) { |
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.
I specifically check for true
here as user can provide anything in the settings and that value will make it through.
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.
I wasn't allowed to use a non-boolean value when testing, which is why thought this was possible, but maybe that's only a warning? Undid this in any case.
src/goMain.ts
Outdated
@@ -118,6 +126,12 @@ export function activate(ctx: vscode.ExtensionContext): void { | |||
} | |||
); | |||
|
|||
c.onReady().then(() => { |
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.
There is already a c.onReady()
below, can you combine this with that?
src/goMain.ts
Outdated
@@ -118,6 +126,12 @@ export function activate(ctx: vscode.ExtensionContext): void { | |||
} | |||
); | |||
|
|||
c.onReady().then(() => { | |||
if (c.initializeResult && c.initializeResult.capabilities && !c.initializeResult.capabilities.completionProvider) { | |||
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(), '.', '\"')); |
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.
We would get inside this if
block when the user had enabled the languageServerExperimentalFeatures['autoComplete']
setting, but the language server is old as well. In this case, we should notify the user that their version of the language server is old and does not support the auto-complete
feature.
Same for the format feature.
src/goMain.ts
Outdated
const capabilities = c.initializeResult && c.initializeResult.capabilities; | ||
if (capabilities && !capabilities.completionProvider) { | ||
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(), '.', '\"')); | ||
vscode.window.showInformationMessage('Your installed version of `go-langserver` is out of date and does not support code completion. Falling back to default behavior.'); |
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.
@ramya-rao-a Is this an ok phrasing or would you also prompt the user to upgrade? It might also make sense to show a single generic message in case any fallback condition inside this function body was triggered.
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.
@m90 I'll look into the update option later. I've pushed a commit to use generic message
src/goMain.ts
Outdated
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(), '.', '\"')); | ||
vscode.window.showInformationMessage('Your installed version of `go-langserver` is out of date and does not support code completion. Falling back to default behavior.'); | ||
} | ||
|
||
if (!languageServerExperimentalFeatures['format'] || |
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.
Should this check for !== true
then, too?
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.
Good point, I've pushed a commit to fix it
… message about outdated langserver version
Instead of using go-code, use go-languageserver for providing
code completion results when enabled. Solves #1593