-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: feature: offer quickfix for variable name that is incorrectly initialized #69980
Comments
The quickfix seems like a reasonable extension to gopls' existing https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/undeclaredname analyzer. |
How about auto adding missing |
In order to do the completion aspect of this, we'd probably need to extract undeclared names from type errors, and make them available to lexical completion. This is doable. This is really two separate issues. I'll file a separate issue for the completion issue. |
Filed #69993 for the completion request. As I said there, I think we're much more likely to add the quickfix, than we are to inject undeclared names into completion results. |
@findleyr I would like to take this up. However, having not contributed to the Go language before, I would require a bit of guidance on the objective. |
@shashank-priyadarshi One useful tip is using goland to debug, I remember there is a test file called fix_test.go, construct a similar test for missing function, and set breakpoints in undeclaredname.go. |
Change https://go.dev/cl/629895 mentions this issue: |
gopls version
Build info
golang.org/x/tools/gopls (devel)
golang.org/x/tools/gopls@(devel)
github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/[email protected] h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/[email protected] h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/[email protected] h1:PfPrmVDHfPgLVpiYnf2R1uL8SCXBjkqT51+f/fQHR6Q=
golang.org/x/[email protected] h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/[email protected] => ../
golang.org/x/[email protected] h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/[email protected] h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/[email protected] h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.23.2
go env
What did you do?
What did you see happen?
What did you expect to see?
offer completion for
foo
in second linebar := foo + 1
, offer a quickfix that add the missing:
in first line.Since an unused variable is always a error in go, the first line will have an error within expectation when writing from top to bottom, regardless this is a incorrectly initialized error rather than unused variable, which makes the lack of completion candidates surprising to me, further, the fix is annoy, because go-to-def does not work, I need to manually locate the first line where I miss a
:
.If this quickfix exists, one could stop writing
:
to initialize variables, which requires two keystroke :shift+;
, and let code action do the thing where it is later used. Even better, gopls can automatically add the missing:
when user confirm the completion item.Editor and settings
No response
Logs
No response
The text was updated successfully, but these errors were encountered: