Skip to content

feat(code-action): add quickfix to remove extra rec keyword#785

Closed
takeokunn wants to merge 1 commit into
mainfrom
feature/add-code-action-14
Closed

feat(code-action): add quickfix to remove extra rec keyword#785
takeokunn wants to merge 1 commit into
mainfrom
feature/add-code-action-14

Conversation

@takeokunn

Copy link
Copy Markdown
Collaborator

Summary

Add a code action that removes unnecessary rec keywords from attribute sets, marked as a preferred quickfix.

Example Transformation:

Before After
rec { x = 1; } { x = 1; }

Changes

File Description
nixd/lib/Controller/CodeAction.cpp Mark DK_ExtraRecursive as isPreferred

Behavior

Action offered when:

  • Cursor is on a rec keyword where no binding references another binding in the same attrset

Action NOT offered when:

  • Bindings reference each other (e.g., rec { x = 1; y = x; })

Test Plan

  • All 3 extra-rec tests pass
  • Build with sanitizers succeeds
  • Tests cover:
    • basic.md: Single-line rec { x = 1; } removal
    • multiline.md: Multiline attrset with independent bindings
    • needed-rec.md: Negative test — action not offered when rec is needed

Related

- Recognize DK_ExtraRecursive diagnostics as preferred quickfixes
- Add tests for removing extra rec in basic, empty, and multiline attrsets
- Ensure no code action is offered when rec is required for references
bool IsPreferred = false;
switch (D.kind()) {
case nixf::Diagnostic::DK_UnusedDefLet:
case nixf::Diagnostic::DK_ExtraRecursive:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also #786, #787, #788 PRs, they all just add isPreferred = true for some diagnostic ID, why those code actions from diagnostic fix() cannot be preferred by default?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also these PRs are conflict to #778?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, You're right — these PRs all add the same pattern and they conflict with #778.

#778 introduces Fix::prefer() so each fix declares itself as preferred at creation time, which removes this switch statement.

I'll close #785#788, get #778 merged first, then open a single follow-up PR that adds .prefer() to the remaining diagnostic fixes (extra-rec, extra-with, empty-inherit, redundant-paren) together with their tests.

@takeokunn takeokunn closed this Feb 15, 2026
@takeokunn takeokunn deleted the feature/add-code-action-14 branch February 15, 2026 05:39
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