Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix source.fixAll.prettier respecting editor.defaultFormatter (#3908)#3937

Merged
ntotten merged 2 commits intomainfrom
fix/respect-default-formatter-in-code-actions
Jan 21, 2026
Merged

Fix source.fixAll.prettier respecting editor.defaultFormatter (#3908)#3937
ntotten merged 2 commits intomainfrom
fix/respect-default-formatter-in-code-actions

Conversation

@ntotten
Copy link
Member

@ntotten ntotten commented Jan 21, 2026

Summary

  • Fixed source.fixAll.prettier code action running even when editor.defaultFormatter was set to a different extension
  • The code action now respects the user's formatter choice and only runs when Prettier is the default formatter or when source.fixAll.prettier is explicitly enabled
  • Properly handles language-specific settings (e.g., [javascript]: { "editor.defaultFormatter": "..." })

Fixes #3908

Changes

  • src/PrettierCodeActionProvider.ts: Added shouldProvideCodeActions() method that checks:

    1. If source.fixAll.prettier is explicitly set to "always" or "explicit" → always provide actions
    2. If editor.defaultFormatter is set to another extension → don't provide actions
    3. Otherwise → provide actions (backward compatible default)
  • src/test/suite/codeAction.test.ts: Added two new tests:

    • Verifies code actions are NOT provided when defaultFormatter is set to another extension
    • Verifies code actions ARE provided when source.fixAll.prettier is 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

  • All 70 existing tests pass
  • New test verifies code action is NOT provided when editor.defaultFormatter is not Prettier
  • New test verifies code action IS provided when source.fixAll.prettier is explicitly enabled
  • Lint and Prettier checks pass

🤖 Generated with Claude Code

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]>
Copilot AI review requested due to automatic review settings January 21, 2026 18:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@ntotten ntotten merged commit e9207c4 into main Jan 21, 2026
13 checks passed
@ntotten ntotten deleted the fix/respect-default-formatter-in-code-actions branch January 21, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No longer respects editor.defaultFormatter and editor.formatOnSave

2 participants