Skip to content

feat(code-action): add quickfix to remove unused let bindings#779

Merged
takeokunn merged 1 commit into
mainfrom
feature/add-code-action-13
Feb 7, 2026
Merged

feat(code-action): add quickfix to remove unused let bindings#779
takeokunn merged 1 commit into
mainfrom
feature/add-code-action-13

Conversation

@takeokunn

@takeokunn takeokunn commented Jan 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add code action to remove unused bindings from let expressions.

Example Transformation:

Before After
let x = 1; in 2 let in 2
let x = 1; y = 2; in y let y = 2; in y
let x = 1; y = 2; in 3 let y = 2; in 3 (each gets separate action)

Changes

File Description
libnixf/src/Sema/VariableLookup.cpp Generate fix for DK_UnusedDefLet diagnostics
nixd/lib/Controller/CodeAction.cpp Set isPreferred: true for unused binding quickfix

Behavior

Action offered when:

  • Cursor is on an unused let binding
  • Diagnostic DK_UnusedDefLet exists

Action NOT offered when:

  • Binding is used in the let body
  • Binding is an inherit statement (intentionally excluded)

Handles removal:

  • Removes full binding range including = value;
  • Works with single-line and multiline let expressions

Test Plan

  • All 4 unused-def tests pass
  • Build succeeds with -Dwerror=true
  • Tests cover:
    • basic.md: Remove single unused binding
    • multiple-bindings.md: Remove one of multiple bindings
    • all-unused.md: All bindings unused (each gets separate action)
    • multiline.md: Multiline let expression formatting
    • unquote-let-invalid.md: Interaction with unquote action (updated)
    • unquote-let-keyword.md: Interaction with unquote action (updated)

Related

@takeokunn takeokunn changed the title [wip] feat(code-action): add quickfix to remove unused let bindings feat(code-action): add quickfix to remove unused let bindings Jan 29, 2026
- Detect unused let bindings in VariableLookup and provide a fix
- Mark "remove unused binding" as preferred quickfix in CodeAction
- Update tests to check for unused binding quickfix in various scenarios
- Add new tests for all-unused, basic, multiline, and multiple-bindings cases
@takeokunn takeokunn force-pushed the feature/add-code-action-13 branch from 8062023 to 00958de Compare January 29, 2026 19:36
@takeokunn takeokunn marked this pull request as ready for review January 29, 2026 19:36
@takeokunn takeokunn requested a review from inclyc as a code owner January 29, 2026 19:36
@takeokunn takeokunn merged commit 1b55380 into main Feb 7, 2026
19 checks passed
@takeokunn takeokunn deleted the feature/add-code-action-13 branch February 7, 2026 06:35
@inclyc inclyc added enhancement New feature or request nixd:controller labels Feb 7, 2026
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