Skip to content

feat(code-action): add quickfix to remove redundant parentheses#788

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

feat(code-action): add quickfix to remove redundant parentheses#788
takeokunn wants to merge 1 commit into
mainfrom
feature/add-code-action-17

Conversation

@takeokunn

Copy link
Copy Markdown
Collaborator

Summary

Add code action to remove redundant parentheses from Nix expressions.

Example Transformation:

Before After
(1) 1
((1)) (1) then 1 (two separate actions)
(x) x
({ }) { }

Changes

File Description
nixd/lib/Controller/CodeAction.cpp Set isPreferred: true for redundant paren quickfix

Behavior

Action offered when:

  • Cursor is on a parenthesized expression wrapping a "simple" form
  • Simple forms: variable, integer, float, string, path, search path, paren, attribute set, list

Action NOT offered when:

  • Inner expression requires parentheses for disambiguation (binary ops, if-then-else, lambda, let, with, etc.)

Handles removal:

  • Removes both ( and ) with two TextEdit::mkRemoval edits
  • Works with single-line and multiline expressions

Test Plan

  • All 4 redundant-paren tests pass
  • Build succeeds
  • Tests cover:
    • basic.md: Remove parens around integer literal (1)
    • nested.md: Double-nested ((1)) produces two quickfix actions
    • multiline.md: Multiline paren removal across lines
    • needed-paren.md: Negative - (1 + 2) does NOT offer action

Related

- Mark redundant parentheses diagnostics as preferred quickfix
- Add tests for basic, multiline, and nested redundant paren cases
- Ensure no action is offered when parentheses are required
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.

1 participant