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
Comments
no return values expected
any update here? as mentioned - I am willing to work on this myself and contribute it to Any help will be appreciated. |
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 You can run your own version of |
Hello @stamblerre Thank you for the detailed explanation. Michael's talk you refereed to and your talk from the same conference were very useful to me in getting some grasp on how Regarding this issue - I was wondering whether such analyzer does not already exist somewhere. The reason being that I already get an error message in my IDE, I just don't get 'quick fixes'. I found no such analyzer in the ~/go/src/github.com/golang
$ grep -ri 'no result values expected' .
....
./go/src/go/types/stmt.go: check.error(s.Results[0].Pos(), "no result values expected") this is the result of a So I was thinking that I can try to write a brand new analyzer from scratch and add it to the What's your take on that? Do you think it makes sense to write something brand new, when there already is something similar in the open, and do you think that adding such checker to |
Thanks for following up! The codebase that you were looking at here is the type-checker (https://golang.org/pkg/go/types/), which |
/cc @ridersofrohan |
Change https://golang.org/cl/222237 mentions this issue: |
Change https://golang.org/cl/222761 mentions this issue: |
Change https://golang.org/cl/223666 mentions this issue: |
Change https://golang.org/cl/225477 mentions this issue: |
This change adds support within gopls for analyzers that work with type errors to provide suggested fixes. Updates golang/go#34644 Change-Id: Ia8929173752fda6bd84a9edaabd310e758f25fe8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222761 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This change adds a quick fix for diagnostics that have an error message of the form "undeclared name: %s". It provides a quick fix to add a new variable with that name. Updates golang/go#34644 Change-Id: I6534ee79d1770d1a62bac169c3c7e52e2443f39e Reviewed-on: https://go-review.googlesource.com/c/tools/+/222237 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This change adds a quick fix for type errors of the type "no result values expected". It will replace the return statment with an empty return statement. Updates golang/go#34644 Change-Id: I3885748dfc69a2d19f8e7a2e81f36f6d0a20d25b Reviewed-on: https://go-review.googlesource.com/c/tools/+/223666 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This change adds a quick fix for type errors of the type "no new vars on left side of :=". It will replace the ":=" with an "=". Updates golang/go#34644 Change-Id: I91af8eb82956104229c3b4f3d0fce60fdfdbb5ea Reviewed-on: https://go-review.googlesource.com/c/tools/+/225477 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
We now have infrastructure for adding a type error analysis suggested fix, and we also have the |
What version of Go are you using (
go version
)?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
OutputWhat did you do?
no result values expected
(naturally)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 definitionWhat 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. Igrep
-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.
The text was updated successfully, but these errors were encountered: