Skip to content

feat(code-action): add "convert to inherit" code action for bindings#770

Merged
inclyc merged 2 commits into
mainfrom
feature/add-code-action-8
Jan 13, 2026
Merged

feat(code-action): add "convert to inherit" code action for bindings#770
inclyc merged 2 commits into
mainfrom
feature/add-code-action-8

Conversation

@takeokunn

@takeokunn takeokunn commented Jan 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a new code action that converts explicit bindings to inherit syntax.

Example transformations:

# Pattern 1: Simple variable assignment
# Before
{ foo = foo; bar = bar; }
# After
{ inherit foo; inherit bar; }

# Pattern 2: Select from source
# Before
{ x = lib.x; y = lib.y; }
# After
{ inherit (lib) x; inherit (lib) y; }

# Pattern 3: Nested source
# Before
{ x = lib.nested.x; }
# After
{ inherit (lib.nested) x; }

Features

  • Only offered when cursor is on a binding node
  • Supports simple { x = x; } pattern
  • Supports { a = source.a; } pattern with arbitrary source depth
  • Properly handles quoted attribute names (e.g., "foo-bar")
  • Works in recursive attribute sets (inherit takes from lexical scope)

Edge Cases (action NOT offered)

  • Multi-segment attribute paths: { foo.bar = baz; }
  • Name mismatch: { foo = bar; }
  • Selector mismatch: { foo = lib.bar; }
  • Select with default value: { foo = lib.foo or null; }
  • Dynamic/interpolated attribute names

Test Plan

  • Added 9 regression tests covering:
    • Basic { x = x; } conversion
    • { a = lib.a; } conversion with source
    • Nested source { x = lib.nested.x; }
    • Quoted attribute names
    • Recursive attribute sets
    • Name mismatch (negative)
    • Selector mismatch (negative)
    • Multi-segment path (negative)
    • Default value (negative)

Related

- IntroduceConvertToInherit suggest bindings
  like { x = x; } and { a = source.a; } to inherit syntax
- Only offer the action for single-segment, static attribute names
  where the value matches the attribute or is a selector ending with it
- Add tests for simple, nested, quoted, and rec attribute sets, as well
  as negative cases for mismatches, multi-segment paths, and selects
  with defaults
- Register the new code action in CodeAction.cpp and meson.build
@takeokunn takeokunn changed the title [wip] feat(code-action): add "convert to inherit" code action for bindings feat(code-action): add "convert to inherit" code action for bindings Jan 13, 2026
@takeokunn takeokunn marked this pull request as ready for review January 13, 2026 12:59
@takeokunn takeokunn requested a review from inclyc as a code owner January 13, 2026 12:59
@takeokunn takeokunn added enhancement New feature or request nixd:controller labels Jan 13, 2026
@inclyc inclyc merged commit bd7b414 into main Jan 13, 2026
19 checks passed
@inclyc inclyc deleted the feature/add-code-action-8 branch January 13, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request nixd:controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants