-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
feat: Code action for variable discards #1949
Conversation
For a code action to be part of "autofix" it should ideally be reversible but One possible approach to bring the "var -> const" code action back to being part of autofix is to see if Zig's AstGen step can be improved to report a "constant variable is mutated" error. If both of these errors can counter each other then we could consider bringing it back to autofix. I don't know whether the test {
const foo = 5;
foo = 5;
} |
Done👍
Gotcha, it definitely makes sense to have the "var -> const" direction as part of autofix. Do you think it still makes sense to have this |
The inverse direction cannot be correctly detected due to the existence of pointers. (This is also precisely why the I know the ZLS authors have the final say here, but I would strongly discourage accepting this PR. The |
RIght, I had the feeling that something didn't make this possible. This is why we need
This is the exact reason why Without reversibility this code action could only be a quickfix that need to be manually applied by the user. But as you have pointed out, the correct move is to change |
Thanks for the insight @mlugg! I really appreciate the in depth explanation, I was clearly missing a big part of the larger picture. Cheers |
I was interested in addressing ziglang/zig#20584 (comment), so I added a code action to discard variables using the
_ = &x;
"trick". Happy to close this PR if this isn't a desired feature; I really just wanted a reason to dig around the code action/ quick fix code a bit :)Quick demo: