func main() {
foo = 1 // incorrectly initialized
bar := foo + 1 // no completion candidates item for `foo`
}
What did you see happen?
What did you expect to see?
offer completion for foo in second line bar := 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.
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