Skip to content

fix(formatter): remove defaultFormatter dependency for codeActionsOnSave#236

Open
alphatr wants to merge 1 commit into
oxc-project:mainfrom
alphatr:fix/formatter-code-actions-on-save
Open

fix(formatter): remove defaultFormatter dependency for codeActionsOnSave#236
alphatr wants to merge 1 commit into
oxc-project:mainfrom
alphatr:fix/formatter-code-actions-on-save

Conversation

@alphatr

@alphatr alphatr commented Apr 30, 2026

Copy link
Copy Markdown

Summary

Previously, using oxfmt via editor.codeActionsOnSave required setting editor.defaultFormatter to "oxc.oxc-vscode", because the code action relied on VS Code's built-in editor.action.formatDocument command. This change removes that dependency.

What changed

  • Custom format command: Registered oxc.formatDocument that directly calls the LSP textDocument/formatting request via the language client, bypassing the need for editor.defaultFormatter
  • Removed defaultFormatter check: The code actions provider no longer checks whether editor.defaultFormatter is set to "oxc.oxc-vscode"
  • Updated README: Clarified that editor.defaultFormatter is now optional when using codeActionsOnSave, and is only recommended for manual formatting

Test plan

  • source.format.oxc in codeActionsOnSave works without setting editor.defaultFormatter
  • editor.formatOnSave with editor.defaultFormatter set to "oxc.oxc-vscode" still works
  • Manual formatting via Format Document command still works

@Sysix

Sysix commented May 3, 2026

Copy link
Copy Markdown
Member

I do not like adding a second command specific for oxfmt, when the editor does already have a command for formatting.
Do you have any use cases where the defaultFormatter-check needs to be removed?

@alphatr

alphatr commented May 20, 2026

Copy link
Copy Markdown
Author

The core issue is about supporting a gradual migration path to oxc without requiring per-project VS Code settings changes.

The ideal setup is to configure once at the global level:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "oxc.fmt.requireConfig": true,
  "editor.codeActionsOnSave": {
    "source.format.oxc": "always",
    "source.fixAll.oxc": "always"
  }
}

With oxc.fmt.requireConfig: true, oxfmt only activates in projects that have an oxfmt config file. Projects without it are silently skipped, and Prettier handles formatting as the fallback. As projects mature and adopt oxfmt, they simply add oxfmt.config.ts — no VS Code settings change needed, ever.

This makes migration a one-step operation driven entirely by the project's own config files, not by VS Code settings management. The per-folder editor.defaultFormatter approach requires two changes per project (add oxfmt.config.ts + update VS Code settings), and accumulates settings debt that needs cleanup as the fleet evolves.

This PR is one piece of that picture: source.format.oxc must directly invoke oxfmt regardless of editor.defaultFormatter, otherwise the entire pattern breaks. A natural follow-up would be making requireConfig for the formatter an official feature with documentation, establishing this as a recommended incremental adoption path.

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