Skip to content
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

x/tools/cmd/gopls: Wiki configuration suggestion for LanguageClient save action does not apply imports #31532

Closed
jbizzle opened this issue Apr 18, 2019 · 4 comments
Labels
ExpertNeeded FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@jbizzle
Copy link

jbizzle commented Apr 18, 2019

Forking this issue out of discussion in #30843, since it seems unrelated and I don't want to derail the conversation there. See #30843 (comment) for the specifics, but the TL;DR is that gopls+LanguageClient+vim using the config suggested in the gopls wiki does not seem to produce the expected results when saving a file.

What version of Go are you using (go version)?

$ go version
go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?

unknown

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

Configured LanguageClient according to instructions in the gopls wiki

What did you expect to see?

Source file imports organized along with formatting applied.

What did you see instead?

Only formatting.

@gopherbot gopherbot added this to the Unreleased milestone Apr 18, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Apr 24, 2019
@stamblerre
Copy link
Contributor

Is there a way to run code actions on save in Vim? The way it works for VSCode is the source.organizeImports code action is run on save, and that runs goimports on the file. I am not familiar with the specifics of the configuration for Vim, so this question may be better directed at that repository.

@bcmills bcmills added ExpertNeeded NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 28, 2019
@myitcv
Copy link
Member

myitcv commented May 28, 2019

I would suggest this is a question for the LanguageClient plugin in the first instance.

Unless you have already asked the question there @jbizzle?

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 28, 2019
@jbizzle
Copy link
Author

jbizzle commented May 28, 2019

Thanks to everyone for your replies. Will try and aggregate response to all of them here:

@myitcv -- I hadn't filed an issue there yet, since I wasn't sure that the problem was there. But maybe now that is the consensus.

@stamblerre -- There may be, though it's not clear to me yet how to configure LanguageClient to do so. I logged IO to gopls and, following the sample configuration on the gopls wiki only, see that it is not enough to automatically get the code action commands on save:

==> 0_build/_tmp/language_client.log.in <==
Content-Length: 224

{"jsonrpc":"2.0","method":"textDocument/formatting","params":{"options":{"insertSpaces":false,"tabSize":4},"textDocument":{"uri":"file:///dir/test.go"}},"id":9}
==> 0_build/_tmp/language_client.log.out <==
Content-Length: 36

{"jsonrpc":"2.0","result":[],"id":9}

However, if I explicitly call the code action command from within vim using the language client Vim function (not documented well), it seems to get suggestions from gopls but does not actually add them to my buffer in the editor:

==> 0_build/_tmp/language_client.log.in <==
Content-Length: 283

{"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[]},"range":{"end":{"character":2,"line":2},"start":{"character":2,"line":2}},"textDocument":{"uri":"file:///dir/test.go"}},"id":10}
==> 0_build/_tmp/language_client.log.out <==
Content-Length: 402

{"jsonrpc":"2.0","result":[{"title":"Organize Imports","kind":"source.organizeImports","edit":{"changes":{"file:///dir/test.go":[{"range":{"start":{"line":2,"character":0},"end":{"line":2,"character":0}},"newText":"import \"log\"\n"},{"range":{"start":{"line":2,"character":0},"end":{"line":2,"character":0}},"newText":"\n"}]}}}],"id":10}

So I guess there are two problems:

  1. Language Client itself doesn't seem to document or even support how to properly invoke and use code actions from a language server. That is an issue for that project, and I can file it separately.

  2. The gopls wiki itself suggests a configuration for Language Client which appears to be incomplete or no longer adequate to accomplish what it says. If that's the case, then maybe better to just not show the configuration at all?

@stamblerre
Copy link
Contributor

The settings on the Wiki were mostly contributed by users, so I imagine that if someone added this setting, they were able to use it in conjunction with another plugin that does goimports or something like that. It would be ideal to have a more complete configuration listed, but as these are user-contributed configurations, I'd rather not hide them. If someone finds a good solution, I would encourage them to add it to the wiki.

It seems to me that this a feature request / issue for the LanguageClient plugin, so I will close this issue for now.

@golang golang locked and limited conversation to collaborators Jun 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ExpertNeeded FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants