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 4 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 4 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
npm i https://pkg.pr.new/@typespec/playground@11468

commit: 7911f32

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin

Copy link
Copy Markdown
Member

@copilot I don't see the fix all in the playground

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I don't see the fix all in the playground

The playground uses its own Monaco code action provider (in packages/playground/src/services.ts) that doesn't go through the LSP server — so the "Fix all" logic I added to serverlib.ts wasn't visible there. Fixed in commit feat: add Fix all code action to playground code action provider: the playground's provider now does the same two-pass approach — grouping all fix IDs across the whole file first, then adding a Fix all: <label> action for any fix that appears more than once.

@timotheeguerin

Copy link
Copy Markdown
Member

@copilot build fails now

vite v8.1.4 building client environment for production...
src/services.ts:400:42 - error TS18048: 'compiler' is possibly 'undefined'.

400         edits: Awaited<ReturnType<typeof compiler.resolveCodeFix>>,
                                             ~~~~~~~~


why are we adding all those computer types here they should be exported

…osure

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot build fails now

vite v8.1.4 building client environment for production...

...

Fixed in the latest commit. The helper codeFixEditsToMonacoEdits is now a module-level function (so there's no captured compiler variable in its type), and it takes CodeFixEdit[] — using the CodeFix and CodeFixEdit types imported directly from @typespec/compiler instead of the inline Awaited<ReturnType<typeof compiler.resolveCodeFix>> expression.

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 ui:playground

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