Skip to content

fix(formatter): fix formatting order in codeActionsOnSave#201

Open
panudetjt wants to merge 1 commit into
oxc-project:mainfrom
panudetjt:fix/format-on-save-ordering
Open

fix(formatter): fix formatting order in codeActionsOnSave#201
panudetjt wants to merge 1 commit into
oxc-project:mainfrom
panudetjt:fix/format-on-save-ordering

Conversation

@panudetjt
Copy link
Copy Markdown

@panudetjt panudetjt commented Apr 6, 2026

Note

AI Assisted writing

Summary

  • Use onWillSaveTextDocument to apply formatting edits before code actions on save are collected, guaranteeing format→lint
    ordering when both source.format.oxc and source.fixAll.oxc are configured
  • Suppress the source.format.oxc code action when configured in codeActionsOnSave to prevent double-formatting (the code action's editor.action.formatDocument command would run after lint fixes, undoing them)

Problem

Previously, source.format.oxc was 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-case uppercasing hex literals).

Test plan

  • Verify source.format.oxc code action is suppressed when source.format.oxc is in codeActionsOnSave
  • Verify source.format.oxc code action is still returned for manual use when not in codeActionsOnSave
  • Manual: configure source.format.oxc and source.fixAll.oxc in codeActionsOnSave, save a file with both formatting and
    lint issues, verify format runs first

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.
@Sysix
Copy link
Copy Markdown
Member

Sysix commented Apr 20, 2026

Sorry for the long wait 🙇
I did not have time to check this PR, I am afraid of spamming the LSP server, need to check if creates some performance problems. 🙏

@panudetjt
Copy link
Copy Markdown
Author

I'm not sure either! 😂
This is my first contribution to a VS Code extension, so I would be very grateful if you could guide me through the process.
Thank you

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.

2 participants