I don't think we should have a feature that unexpectedly deletes user's code. If go/ast is too unhelpful, perhaps we could change the title of the suggested fix to "Rearrange fields (may delete comments)" or some such?
Yes, as per CL 278872 this is indeed how it works (also see #20744). I agree that it isn't optimal.
Given the niched nature of this analyser (and the fact that it is opt-in), how about adding a note to the documentation? That would be the entry-point for users.
Updating the title to "Rearrange fields (removes comments)" could add confusion, especially to those who wouldn't notice since they don't have comments. In that case, I'd rather see that we only update the title if there are any comments.
The long term goal is to keep the comments, but as I see it (with very limited experience of AST) it isn't trivial. If there are ideas on how to achieve that please let me know.
FWIW, I think having the suffix appear only when there are comments that will be destroyed is a good idea and should be completely possible.
My understanding matches yours: there is a long-standing feature request in goimports that is blocked by poor comment support in the AST. So I think noting the problem in the title is actually the best path forward to get this on by default :-/
What version of Go, VS Code & VS Code Go extension are you using?
go versionto get version of Go
gopls -v versionto get version of Gopls if you are using the language server.
code-insiders -vto get version of VS Code or VS Code Insiders
Check your installed extensions to get the version of the VS Code Go extension
go envto get the go development environment details
Share the Go related settings you have added/edited
Preferences: Open Settings (JSON)command to open your settings.json file.
Share all the settings with the
Describe the bug
One of the recommended refactoring actions is to rearrange the struct fields to better align and save memory. When this action is carried out, the comments written for the fields get deleted.
Steps to reproduce the behavior:
If you rearrange the struct fields using the suggested action, the comments are deleted (check the attached recording).
Screenshots or recordings
The text was updated successfully, but these errors were encountered: