Skip to content
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

add code action that simplifies variable initialization #2098

Open
Techatrix opened this issue Nov 30, 2024 · 3 comments
Open

add code action that simplifies variable initialization #2098

Techatrix opened this issue Nov 30, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Techatrix
Copy link
Member

Techatrix commented Nov 30, 2024

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 #2063 it becomes trivial to optionally enable certain code actions to be run on save.

Related ziglang/zig#5038

@Techatrix Techatrix added the enhancement New feature or request label Nov 30, 2024
@srijan-paul
Copy link
Contributor

Hm. This would be nice to have.
If you haven't taken a look by next weekend, I can take a stab at it.

@Techatrix
Copy link
Member Author

@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

@mlugg
Copy link
Contributor

mlugg commented Nov 30, 2024

Yep, T{ ...} is identical to @as(T, .{ ... }), so that's a valid conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants