Skip to content

feat: add 'simplify variable initialization' code action#3197

Open
Metbcy wants to merge 1 commit intozigtools:masterfrom
Metbcy:feat/simplify-var-init
Open

feat: add 'simplify variable initialization' code action#3197
Metbcy wants to merge 1 commit intozigtools:masterfrom
Metbcy:feat/simplify-var-init

Conversation

@Metbcy
Copy link
Copy Markdown

@Metbcy Metbcy commented May 9, 2026

Adds a refactoring code action that simplifies variable declarations by hoisting type information into the type annotation:

// Before
const foo = @as(u32, 42);
const bar = Point{ .x = 1 };

// After
const foo: u32 = 42;
const bar: Point = .{ .x = 1 };

Handles both @as(T, value) builtin calls and typed struct initializers (T{ ... }). Skips declarations that already have explicit type annotations.

Includes tests for both patterns plus an empty struct init case.

Closes #2098

Add a refactoring code action that simplifies variable declarations
by hoisting type information into the type annotation:

  const foo = @as(u32, 42);    =>  const foo: u32 = 42;
  const bar = Point{ .x = 1 }; =>  const bar: Point = .{ .x = 1 };

Handles both @as(T, value) builtin calls and typed struct initializers
(T{ ... }). Skips declarations that already have explicit type annotations.

Closes zigtools#2098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add code action that simplifies variable initialization

1 participant