vscode-go
vscode-go copied to clipboard
"foo declared but not used" use gray color, not red
Is your feature request related to a problem? Please describe.
When I write code, then I often see red underlined variables of variables my code does not use yet.
But of course, this variable is not used, since I am writing line after line (I know 10x developers can write several lines at once, but I am just a 0.5x developer).
I like the fact that I see the unused variable highlighted, but I think the red color does not fit here.
Describe the solution you'd like
It would be more convenient and reduce cognitive load if "declared but not used" warning would be less highlighted.
Maybe use gray color?
Describe alternatives you've considered
There are many alternative to do less strong highlighting.
Additional context
I am new to go, and if there is something red, then I think there is something wrong with the code.
cc @findleyr
gopls is really fast at detecting errors and putting diagnostics. There may be some work to do to improve the user experience for diagnostics on code that is actively being edited.
gopls is great. While writing code you almost always have unused variables, since first write the line which creates the variable, and then in the next moment you will use the variable. Between both moments the variable is unused. That's obvious.
How long does it take on avarage for a developer to write the first line (create variable) until he/she uses the variable? May the nused var should be no error for the first N seconds?
+1, red color confuses with a real error
+1, red color confuses with a real error
Unused variables are real errors in Go though. From the spec (https://go.dev/ref/spec#Variable_declarations): "Implementation restriction: A compiler may make it illegal to declare a variable inside a function body if the variable is never used."
The Go compiler enforces this implementation restriction: https://go.dev/play/p/VCM7-h1LFoU
So I don't think we can reasonably change the color away from red. If we were to do so, then we would break the invariant that a program without red squiggles compiles.
+1, red color confuses with a real error
Unused variables are real errors in Go though. From the spec (https://go.dev/ref/spec#Variable_declarations): "Implementation restriction: A compiler may make it illegal to declare a variable inside a function body if the variable is never used."
The Go compiler enforces this implementation restriction: https://go.dev/play/p/VCM7-h1LFoU
So I don't think we can reasonably change the color away from red. If we were to do so, then we would break the invariant that a program without red squiggles compiles.
Hmmm what about two kinds of red? A normal red and a light red?
There is a mechanism to do this. go/types has a notion of a 'soft' error: https://pkg.go.dev/go/types#Error (which is approximately an error which is optional for the implementation). The errors we're talking about are soft, so we could use this.
But I don't think we have this level of control over the color in the LSP.
Change https://go.dev/cl/415499 mentions this issue: internal/lsp: add unnecessary tags for unused vars and imports
@suzmue is there anything which I can do to help? It would be great to see less red underlined code while typing Go code.
FWIW, the diagnostic tags added in https://go.dev/cl/415499 do work in neovim, and I've had the opposite reaction: I keep getting confused because my code doesn't compile even though there are no errors.
So now we're both bothered :)
FWIW, the diagnostic tags added in https://go.dev/cl/415499 do work in neovim, and I've had the opposite reaction: I keep getting confused because my code doesn't compile even though there are no errors.
So now we're both bothered :)
I can understand this. If there is no visual indicator, then it is confusing.
I think it would be great if unused variables get underlined in yellow color.
Is this possible (in vscode)?
I agree red error indication is appropriate but it would be nice if the editor could perhaps hold off flagging it until the user either saved, or moved the cursor out of the function being edited, or something like that.
New go learner here, I think a different color/shade would increase productivity since I don't know what the error is without hovering. And red line is jarring when I'm just typing out my code. I'm constantly in a state of why is my code erroring when this should be right.