Fix source.fixAll.prettier respecting editor.defaultFormatter (#3908)#3937
Merged
Fix source.fixAll.prettier respecting editor.defaultFormatter (#3908)#3937
Conversation
The code action provider now checks the user's editor settings before
providing code actions. This prevents Prettier from running via
source.fixAll when the user has explicitly chosen a different formatter
(e.g., ESLint with Prettier plugin).
The code action will now only run when:
1. source.fixAll.prettier is explicitly set to "always" or "explicit"
2. editor.defaultFormatter is not set to another extension
This fix also properly handles language-specific settings (e.g.,
[javascript]: { "editor.defaultFormatter": "..." }).
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes an issue where the source.fixAll.prettier code action was running even when users had explicitly chosen a different default formatter (like ESLint with Prettier plugin), causing double-formatting. The fix adds logic to respect the editor.defaultFormatter setting while still allowing users to explicitly enable the Prettier code action if desired.
Changes:
- Added
shouldProvideCodeActions()method to check if Prettier should provide code actions based on settings - Added comprehensive tests for the new behavior with two test scenarios
- Updated documentation to explain the new behavior
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/PrettierCodeActionProvider.ts | Added shouldProvideCodeActions() method that respects editor.defaultFormatter setting while allowing explicit source.fixAll.prettier override |
| src/test/suite/codeAction.test.ts | Added two new tests verifying code actions respect defaultFormatter and explicit settings |
| test-fixtures/workspace/test.js | Added test file for scenario where defaultFormatter is set to another extension |
| test-fixtures/workspace-explicit-prettier/test.js | Added test file for scenario with explicit source.fixAll.prettier setting |
| test-fixtures/workspace-explicit-prettier/.vscode/settings.json | Configuration for test with different defaultFormatter but explicit Prettier code action |
| test-fixtures/test.code-workspace | Added workspace-explicit-prettier folder to workspace configuration |
| README.md | Added note explaining that code action respects defaultFormatter setting |
| CHANGELOG.md | Documented the fix in unreleased section |
The tests were timing out on CI (Linux) because they need time for formatter registration when switching to a new workspace folder. - Added 1 second delay after showing document to wait for formatter registration - Increased test timeout to 10 seconds for workspace folder tests Co-Authored-By: Claude Opus 4.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
source.fixAll.prettiercode action running even wheneditor.defaultFormatterwas set to a different extensionsource.fixAll.prettieris explicitly enabled[javascript]: { "editor.defaultFormatter": "..." })Fixes #3908
Changes
src/PrettierCodeActionProvider.ts: AddedshouldProvideCodeActions()method that checks:source.fixAll.prettieris explicitly set to "always" or "explicit" → always provide actionseditor.defaultFormatteris set to another extension → don't provide actionssrc/test/suite/codeAction.test.ts: Added two new tests:defaultFormatteris set to another extensionsource.fixAll.prettieris explicitly enabled (even with different default formatter)Test fixtures: Added workspace configurations to test the scenarios
Documentation: Updated CHANGELOG.md and README.md to document the new behavior
Test plan
editor.defaultFormatteris not Prettiersource.fixAll.prettieris explicitly enabled🤖 Generated with Claude Code