Open xzbdmw opened 1 month ago
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
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 :
similar to auto-import when resolving completion, so that we no longer have to write colons anymore 😄
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/internal/undeclaredname: CodeAction: Add missing colon when appropriate
gopls version
Build info
golang.org/x/tools/gopls (devel) golang.org/x/tools/gopls@(devel) github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y= golang.org/x/mod@v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/sync@v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/telemetry@v0.0.0-20240927184629-19675431963b h1:PfPrmVDHfPgLVpiYnf2R1uL8SCXBjkqT51+f/fQHR6Q= golang.org/x/text@v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/tools@v0.21.1-0.20240508182429-e35e4ccd0d2d => ../ golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I= honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= mvdan.cc/gofumpt@v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU= mvdan.cc/xurls/v2@v2.5.0 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