-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
allow autofix to be configurable instead of just on/off #1641
Comments
i'd like to disable the |
I'd like to enable back var -> const |
code actions that are part of autofix should ideally be reversible if necessary. This means that we would need the zig compiler to produce a "constant variable is being mutated" error so that we can do "const -> var". If the use case is to update old code, recompiling ZLS with the following diff could be useful. diff --git a/src/features/code_actions.zig b/src/features/code_actions.zig
index 74723ec7..17c2440d 100644
--- a/src/features/code_actions.zig
+++ b/src/features/code_actions.zig
@@ -355,7 +355,7 @@ fn handleVariableNeverMutated(builder: *Builder, actions: *std.ArrayListUnmanage
try actions.append(builder.arena, .{
.title = "use 'const'",
- .kind = .quickfix,
+ .kind = .@"source.fixAll",
.isPreferred = true,
.edit = try builder.createWorkspaceEdit(&.{
builder.createTextEditLoc(var_keyword_loc, "const"), |
The use case is not for updating old code but just having the feature in general. if [[ ! -d "$1" ]]; then
printf 'error: no such directory: %s\n' "$1"
exit 1
fi
cd "$1"
has_wontfix=0
while {
IFS=$':' read -r file line col msg;
} do
if [[ "$msg" ]]; then
case "$msg" in
*"local variable is never mutated")
printf 'autofix: %s\n' "$file:$line:$col:$msg" 1>&2
sed -i "''${line}s/var/const/" "$file"
;;
*)
printf 'wontfix: %s\n' "$file:$line:$col:$msg" 1>&2
has_wontfix=1
;;
esac
fi
done < <(zig build 2>&1 | grep "error:")
exit $has_wontfix |
The autofix feature is now configured through in-editor configuration. This makes it possible to configure individual code actions kinds to be applied on save. Here is an example of how it could look like in VS Code: "editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.fixAll.varToConst": "explicit",
"source.fixAll.preferRLS": "explicit", // https://github.com/zigtools/zls/issues/2098
"source.organizeImports": "explicit",
} I currently do not have any plans to implement this for "var -> const" but #2098 will need it if it wants to become triggered on save. |
related to #1621 and #1623 i think it should be configurable which autofixes are applied rather than simply enabling and disabling the entire feature. i assume it was designed the way it is since there was only 1 autofix for a while but we're adding more now and likely will continue to in the future
The text was updated successfully, but these errors were encountered: