zls
zls copied to clipboard
add code action that simplifies variable initialization
Before:
const foo = @as(T, something);
const bar = T{};
After:
const foo: T = something;
const bar: T = .{};
This feature has been suggested by @mlugg a while ago but I never found the time to implement it.
Thanks to https://github.com/zigtools/zls/pull/2063 it becomes trivial to optionally enable certain code actions to be run on save.
Related https://github.com/ziglang/zig/issues/5038
Hm. This would be nice to have. If you haven't taken a look by next weekend, I can take a stab at it.
@mlugg Since you know so much about RLS, could you tell me whether the following conversion is also valid?
const foo = T{}; // Before
const foo: T = .{}; // After
Yep, T{ ...} is identical to @as(T, .{ ... }), so that's a valid conversion.