Skip to content

feat: Add "Fix all: X" code action for codefixes appearing multiple times in a file - #11468

Open
timotheeguerin with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-codefixes-suggest-fix-all
Open

feat: Add "Fix all: X" code action for codefixes appearing multiple times in a file#11468
timotheeguerin with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-codefixes-suggest-fix-all

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

The TypeSpec language server only offered per-instance quick fixes. ESLint-style "Fix all X problems" was missing, so users had to manually apply the same fix repeatedly for e.g. multiple unused using statements.

Changes

serverlib.ts

  • currentDiagnosticIndex now stores { diagnostic, fileUri } instead of just Diagnostic, enabling file-scoped lookup without resolving AST nodes
  • getCodeActions: after building individual fixes, counts how many times each codefix ID appears across all diagnostics in the same file; adds a "Fix all: <label>" action (kind QuickFix) when count > 1, carrying { fixAllInFile: { fixId, fileUri } } in data
  • resolveCodeAction: handles fixAllInFile data by collecting and merging edits from every matching codefix in the target file into one workspace edit

Example

Given two unused using statements, the lightbulb menu now shows:

Remove unused code          ← fixes current diagnostic only
Fix all: Remove unused code ← removes all unused usings in the file

test/server/code-actions.test.ts — new tests covering:

  • "Fix all" action appears when ≥2 instances of the same codefix exist in the file
  • "Fix all" action is absent when only one instance exists
  • Resolved "Fix all" action produces edits covering all instances

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

…s in a file

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jul 30, 2026
Copilot AI changed the title [WIP] Implement codefixes to suggest a fix all for a given file feat: Add "Fix all: X" code action for codefixes appearing multiple times in a file Jul 30, 2026
Copilot AI requested a review from timotheeguerin July 30, 2026 01:47
@timotheeguerin
timotheeguerin marked this pull request as ready for review July 30, 2026 11:10
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11468

commit: 445e442

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

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codefixes should suggest a fix all for a given file

2 participants