fix(formatter): fix formatting order in codeActionsOnSave#201
Open
panudetjt wants to merge 1 commit into
Open
Conversation
Ensure formatting is applied via onWillSaveTextDocument before code actions are collected when source.format.oxc is configured in editor.codeActionsOnSave. This guarantees format-before-lint order and prevents the formatter from undoing lint fixes. Suppress the source.format.oxc code action when it's already handled by onWillSaveTextDocument to avoid duplicate formatting.
Member
|
Sorry for the long wait 🙇 |
Author
|
I'm not sure either! 😂 |
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.
Note
AI Assisted writing
Summary
onWillSaveTextDocumentto apply formatting edits before code actions on save are collected, guaranteeing format→lintordering when both
source.format.oxcandsource.fixAll.oxcare configuredsource.format.oxccode action when configured incodeActionsOnSaveto prevent double-formatting (the code action'seditor.action.formatDocumentcommand would run after lint fixes, undoing them)Problem
Previously,
source.format.oxcwas implemented as a code action with a command. VS Code collects all code actions before applying any of them, so lint fix edits were computed on the original (unformatted) document. When the format command ran after lint fixes, it could undo lint edits that also changed formatting (e.g.unicorn/number-literal-caseuppercasing hex literals).Test plan
source.format.oxccode action is suppressed whensource.format.oxcis incodeActionsOnSavesource.format.oxccode action is still returned for manual use when not incodeActionsOnSavesource.format.oxcandsource.fixAll.oxcincodeActionsOnSave, save a file with both formatting andlint issues, verify format runs first