Skip to content

Comments

feat(oxfmt/lsp): Use SourceFormatter to support non-JS files and napi features#17655

Merged
graphite-app[bot] merged 1 commit intomainfrom
01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files
Jan 7, 2026
Merged

feat(oxfmt/lsp): Use SourceFormatter to support non-JS files and napi features#17655
graphite-app[bot] merged 1 commit intomainfrom
01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented Jan 5, 2026

Part of #16729, LSP part.

@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request labels Jan 5, 2026
Copy link
Member Author

leaysgur commented Jan 5, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@leaysgur leaysgur changed the title feat(oxfmt/lsp): Use SourceFormatter for non-JS files feat(oxfmt/lsp): Use SourceFormatter for non-JS files Jan 5, 2026
@leaysgur leaysgur requested a review from Sysix January 5, 2026 09:39
@leaysgur
Copy link
Member Author

leaysgur commented Jan 5, 2026

@Sysix Self-review is still ongoing (will fix up tomorrow), but since I don't anticipate making major changes, I'd like to request a review for this stacked PRs first to ensure there are no critical concerns.

Please take a look when you have time. 🙏🏻

Copy link
Member

@Sysix Sysix left a comment

Choose a reason for hiding this comment

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

I am not sure if ExternalFormatter is capable of formatting different files with different formatting options.
ServerFormatterBuilder will create for each workspace a ServerFormatter. Each workspace will target a different config_path, files under this workspace should only be formatted with the respected resolved config.

I had the idea of createWorkspace(root_uri): NAPICallbacks and deleteWorkspace(root_uri): void.
The rust equal should be ServerFormatterBuilder.build_boxed and ServerFormatterBuilder.shutdown.

@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_configresolver branch from 73c796c to 96f0548 Compare January 6, 2026 04:44
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from 645bedf to 2f98bdf Compare January 6, 2026 04:44
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_configresolver branch from 96f0548 to ebe1901 Compare January 6, 2026 04:50
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from 2f98bdf to c0342cb Compare January 6, 2026 04:50
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_configresolver branch from ebe1901 to 6c2343e Compare January 6, 2026 05:14
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from c0342cb to 296ced7 Compare January 6, 2026 05:14
@leaysgur leaysgur changed the base branch from 01-05-feat_oxfmt_lsp_use_configresolver to graphite-base/17655 January 6, 2026 05:16
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from 296ced7 to 4dc45cf Compare January 6, 2026 05:16
@leaysgur leaysgur changed the base branch from graphite-base/17655 to 01-06-feat_oxfmt_lsp_add_.editorconfig_to_get_watcher_patterns January 6, 2026 05:16
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from 4dc45cf to 5dac97d Compare January 6, 2026 05:34
@leaysgur
Copy link
Member Author

leaysgur commented Jan 6, 2026

ExternalFormatter is stateless, it just passes the received options through to Prettier on each call.
And options are generated per-call from each workspace's ConfigResolver.

So..., there's no cross-workspace interference?

@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch 2 times, most recently from 6b1f5bc to ee53bec Compare January 6, 2026 05:55
@leaysgur leaysgur marked this pull request as ready for review January 6, 2026 06:21
@leaysgur leaysgur assigned Sysix and unassigned leaysgur Jan 6, 2026
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch 2 times, most recently from fff5b4b to fe4966c Compare January 6, 2026 07:22
Copy link
Member

@Sysix Sysix left a comment

Choose a reason for hiding this comment

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

Great work 👍
Have successfully tested it with workspace folders and the VSCode changes from #17615

Copilot AI review requested due to automatic review settings January 7, 2026 02:02
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from 948f56a to 6301da5 Compare January 7, 2026 02:02
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 PR refactors the LSP (Language Server Protocol) implementation to use SourceFormatter for formatting non-JavaScript files, unifying the formatting approach across different file types. The changes introduce external formatter support in the LSP server, allowing it to handle a broader range of file formats including JSON, YAML, and CSS.

Key Changes

  • Refactored LSP server formatter to use SourceFormatter instead of directly using oxc_formatter and Parser
  • Added ExternalFormatter integration to the LSP server with lazy initialization support
  • Restructured main_napi.rs to centralize external formatter creation and pass it to LSP mode

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
apps/oxfmt/src/main_napi.rs Restructures code flow to create external formatter once and pass to different modes; contains unresolved merge conflict
apps/oxfmt/src/lsp/server_formatter.rs Major refactoring to use SourceFormatter and integrate ExternalFormatter with lazy initialization
apps/oxfmt/src/lsp/tester.rs Updates test helper to use new ServerFormatterBuilder::dummy() method
apps/oxfmt/src/lsp/mod.rs Updates run_lsp signature to accept ExternalFormatter parameter
apps/oxfmt/src/core/external_formatter.rs Adds dummy() constructor for testing purposes
apps/oxfmt/src/core/config.rs Adds Debug derive to ResolvedOptions enum for better debugging support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch 6 times, most recently from 4012aff to d99b629 Compare January 7, 2026 04:02
@leaysgur leaysgur requested a review from Sysix January 7, 2026 04:04
@leaysgur
Copy link
Member Author

leaysgur commented Jan 7, 2026

@Sysix I've addressed the review comments, also completed the self-review. 🫡

@leaysgur leaysgur changed the title feat(oxfmt/lsp): Use SourceFormatter for non-JS files feat(oxfmt/lsp): Use SourceFormatter to support non-JS files and napi features Jan 7, 2026
@leaysgur leaysgur force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from d99b629 to d9a91b9 Compare January 7, 2026 08:45
@Sysix
Copy link
Member

Sysix commented Jan 7, 2026

Great work! Works great from the LSP side, VS Code somehow has a strange bug on my machine => Will be solved in the other PR :)

@Sysix Sysix added the 0-merge Merge with Graphite Merge Queue label Jan 7, 2026
Copy link
Member

Sysix commented Jan 7, 2026

Merge activity

@graphite-app graphite-app bot force-pushed the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch from d9a91b9 to 2e03ebf Compare January 7, 2026 19:00
@graphite-app graphite-app bot merged commit 2e03ebf into main Jan 7, 2026
19 checks passed
@graphite-app graphite-app bot deleted the 01-05-feat_oxfmt_lsp_use_sourceformatter_for_non-js_files branch January 7, 2026 19:06
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 7, 2026
Sysix added a commit that referenced this pull request Jan 8, 2026
Syncs extensions and filenames with
#16524. LSP support for it in
#17655.

Resolves #16729

---------

Signed-off-by: Alexander S. <sysix@sysix-coding.de>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Alexander S. <sysix@sysix-coding.de>
Dunqing pushed a commit that referenced this pull request Jan 12, 2026
# Oxlint
### 🚀 Features

- 9699a1b linter/prefer-global-this: Add suggestion (#17873) (Mikhail
Baev)
- 51c2815 linter/no-invalid-regexp: Add labels and help text to flag
diagnostics (#17865) (camchenry)
- 344d77d linter/no-ex-assign: Improve diagnostic with more detail
(#17864) (camchenry)
- 7d280e0 linter: Add fixer for
`unicorn/no-useless-error-capture-stack-trace` rule (#17839) (Mikhail
Baev)
- af1d0e3 linter/prefer-optional-chain: Add rule (#17831) (camc314)
- e3c4108 vscode: Add more supported languages to extension (#17812)
(Alexander Lichter)
- 4a46678 vscode: Activate extension on more languages (#17717) (Sysix)
- b1298fc vscode: Sync formatter with supported files (#17615)
(Alexander Lichter)
- c7f0848 linte/rno-required-prop-with-default: Implement suggestion
(#17747) (Minsu Lee)
- 0e8127e linter/vue: Implement no-lifecycle-after-await (#17701)
(yefan)
- 3567304 linter/vitest: Implement `consistent-each-for` (#17601) (Said
Atrahouch)
- 883e156 linter: Add fixer for `unicorn/no-useless-collection-argument`
rule (#17594) (Mikhail Baev)
- 4eb335c linter/vitest: Implemented prefer-called-once (#17674) (Said
Atrahouch)
- 2bd2d5a linter/vitest: Implement hoisted-apis-on-top (#17658) (Said
Atrahouch)
- cfb2bcc linter/vue: Implement no-arrow-functions-in-watch (#17672)
(yefan)
- a68208a linter/eslint-plugin-vitest: Implements
`prefer-describe-function-title` (#17677) (Said Atrahouch)
- efa029f linter/vitest: Implement no-unneeded-async-expect-function
(#17494) (Minsu Lee)

### 🐛 Bug Fixes

- 49cf66e lsp: Fix workspace worker selection for nested and
similar-named workspaces (#17853) (Copilot)
- 84f4f3c linter: Add doc url for tsgolint diagnostics (#17879) (Sysix)
- 76c903f linter/consistent-indexed-object-style: Skip fixing default
exported interface (#17874) (Copilot)
- 7e87d16 linter/tabindex-no-positive: Improve diagnostic phrasing
(#17849) (connorshea)
- 28f9fba vscode: Fix nested search for binaries (#17832) (Sysix)
- 8ca2cd2 linter: Move jsx-a11y/no-static-element-interactions rule to
nursery. (#17818) (connorshea)
- dc9fdd6 linter/consistent-indexed-object-style: Re-port test cases and
fix some bugs (#17802) (camc314)
- 7bbd880 linter: Update prefer-destructuring rule metadata (#17642)
(Hamir Mahal)
- 3c45185 linter/consistent-indexed-object-style: False positive with
circular reference (#17789) (heygsc)
- bd186b4 vscode: Search for `oxlint` and `oxfmt` in every workspace
directory (#17760) (Sysix)
- 3e0dff7 linter/no-hooks: Add punctuation to diagnostic message
(#17751) (camc314)
- 6ae21f9 linter/prefer-called-once: Avoid panic on trailing comma
(#17735) (Said Atrahouch)
- 32c3901 oxlint: Do not panic on invalid `no-unused-vars` configuration
(#17719) (Sysix)
- 59a6228 parser: Detect TS1363 error for type-only imports with mixed
default and named/namespace bindings (#17712) (Copilot)

### ⚡ Performance

- f87a1e2 linter: Check for giving reserved plugin name before calling
`load_plugin` on napi side (#17841) (Sysix)

### 📚 Documentation

- a2b3a24 linter/no-caller: Improve docs and diagnostic for rule.
(#17890) (connorshea)
- aa48247 linter/no-unsafe-finally: Improve rule docs. (#17891)
(connorshea)
- 1b0bdee linter: Tweak docs for no-useless-constructor and
hoisted-apis-on-top (#17888) (connorshea)
- 8f24fa9 vscode: Remove mention of a built-in server (#17836) (Sysix)
- e81a306 linter: Update the tsconfig flag mention for the import
plugin. (#17778) (connorshea)
# Oxfmt
### 🚀 Features

- 539b350 formatter/sort_imports: Update `NODE_BUILTINS` modules
(#17771) (nilptr)
- 2e03ebf oxfmt/lsp: Use `SourceFormatter` to support non-JS files and
napi features (#17655) (leaysgur)
- 623f7eb oxfmt/sort_package_json: Use `options.sort_scripts` (#17740)
(leaysgur)
- 86c0168 oxfmt/sort_package_json: Handle `oxfmtrc.sort_scripts` option
(#17738) (leaysgur)
- 256636a oxfmt/lsp: Add `.editorconfig` to `get_watcher_patterns`
(#17694) (leaysgur)
- 3f3db39 oxfmt/lsp: Use `ConfigResolver` to align with CLI (#17654)
(leaysgur)

### 🐛 Bug Fixes

- fdd1e1e formatter: Don't wrap parenthesis for type assertion when it's
an declaration of export default (#17878) (Dunqing)
- f0813ad formatter: Incorrect type annotation check for short argument
(#17877) (Dunqing)
- 9e89389 formatter/tailwindcss: Nested class string doesn't respect
`singleQuote: true` (#17838) (Dunqing)
- e2f534c formatter/sort_imports: Handle alignable comment with JsLabels
(#17791) (leaysgur)
- f0cedd4 formatter/tailwindcss: Class name is broken after sorting when
its contains single quotes with `singleQuote: true` (#17790) (Dunqing)
- 1864142 oxfmt/tailwindcss: Bundle `prettier/plugins/*` (#17782)
(leaysgur)
- 3a9d43b oxfmt: Ignore explicit positional path which is ignored by
directory (#17732) (leaysgur)
- 0563217 formatter: Classes will be stripped out when both
`experimentalTailwindcss` and `experimentalSortImports` are enabled
(#17726) (Dunqing)

### ⚡ Performance

- d1bc514 formatter: Optimize RegExpLiteral formatting to avoid heap
allocations (#17797) (Dunqing)

### 📚 Documentation

- 62b7a01 formatter: Clarify `experimentalTailwindcss` configuration
comments (#17898) (Dunqing)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants