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/gopls: support quick fixes for type errors #34644

Open
asankov opened this issue Oct 1, 2019 · 2 comments

Comments

@asankov
Copy link

commented Oct 1, 2019

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

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

MacOS Mojave 10.14.5

go env Output
$ go env
GOOS="darwin"
GOARCH="amd64"

What did you do?

  1. I am using VSCode for Go development
  2. open/create a golang file
  3. write a function without specifying a return type
  4. return inside the function
  5. VS Code shows error - no result values expected (naturally)

Screen Shot 2019-10-01 at 15 15 47

Screen Shot 2019-10-01 at 15 15 40

What did you expect to see?

I would expect to see option like Specify return value, which when clicked would append the return value to method definition

What did you see instead?

No quick fixes available

I tried to troubleshoot the issue myself. From the MS LSP specification I found out that these actions are controlled by the textDocument/codeAction request. I grep-ed that in the /go/tools code and got to the (h serverHandler) Deliver method. The handler of this request calls (s *Server) CodeAction, which in terms calles the private (s *Server) codeAction. This method is quite long and I could not continue investigation further.

I am willing to help with the design/implentation of this, if you think it makes sense to have something like this build into the tools. Also, I would be thankful if you point me to some guidelines for building/running the language server locally, so I can debug a sample request and see what is happening where.

@gopherbot gopherbot added this to the Unreleased milestone Oct 1, 2019
@stamblerre stamblerre changed the title x/tools/gopls: No quick fixes for `no return values expected` x/tools/gopls: support quick fixes for compile errors Oct 2, 2019
@stamblerre stamblerre changed the title x/tools/gopls: support quick fixes for compile errors x/tools/gopls: support quick fixes for type errors Oct 2, 2019
@golang golang deleted a comment from gopherbot Oct 2, 2019
@asankov

This comment has been minimized.

Copy link
Author

commented Oct 7, 2019

any update here?

as mentioned - I am willing to work on this myself and contribute it to gopls.

Any help will be appreciated.

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Oct 7, 2019

Hi @asankov - thank you for filing this detailed issue report! You are correct in saying that these types of quick fixes are provided as code actions.

To add such a fix, we would first need to write an analysis with a suggested fix. You may find this talk given by @matloob helpful when getting started with go/analysis. Once the analysis is written, it can be added to gopls quite simply - just by adding it to this list.

You can run your own version of gopls simply by cding into golang.org/x/tools/gopls and running go install on your machine. To avoid clobbering your stable version of gopls, you can rename the development binary. You can also have per-workspace configurations for VSCode which differentiate which version of gopls to use based on the workspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.