> ## Pull request overview
> This PR updates oxfmt’s LSP in-memory formatting to handle URIs that don’t have an authority component (i.e., non-`file://` URIs like `vscode-userdata:/...`) by deriving a “fake” file path from the URI’s authority *or* path, and updates the LSP formatting tests/snapshots accordingly.
Fixes#20416 for Oxfmt
- Gate `vite.config.ts` recognition behind `VP_VERSION` env var
- With it, only vite.config.ts is recognized
- Without it, excluded from config candidates (.oxfmtrc.json, oxfmt.config.ts are used)
- Refactor JS config loader into `loadJsConfig` / `loadVitePlusConfig` with shared `importJsConfig` helper
- `loadVitePlusConfig` should be updated to use `resolveConfig` from `vite-plus` soon
- Split tests into `vite_config` (non VP mode) and `vite_plus` (VP mode)
closes https://github.com/oxc-project/oxc-vscode/issues/140
Preferring the languageID over the real file extension creates inconsistency between the editor and the CLI.
Reverting the changes from #19977 back to align back with CLI.
This only effects `file://` scheme, where we can expect a real file on a disk. Other schemes are still preferring the languageID, because we do not to what exactly they are relating to.
NOTE: I'll do a self-review and add the test tomorrow.
<details>
<summary>Prompt</summary>
```
# Support `vite.config.*` as a Configuration File
## Target Files
- `vite.config.ts`
- `vite.config.mts`
- `vite.config.cts`
- `vite.config.js`
- `vite.config.mjs`
- `vite.config.cjs`
## Auto-Discovery Priority
When searching for a config file from `cwd` upwards, the following priority applies within the same directory:
1. Tool-specific JSON/JSONC config files (e.g. `.oxfmtrc.json`, `.oxlintrc.json`)
2. Tool-specific JS/TS config files (e.g. `oxfmt.config.ts`, `oxlint.config.ts`)
3. `vite.config.*`
## Extracting Configuration
The default export of `vite.config.*` is expected to contain tool-specific configuration under a dedicated field:
- oxfmt: `.fmt`
- oxlint: `.lint`
If the field does not exist, an error is returned (e.g. `Expected a 'fmt' field in the default export.`).
## Explicit `--config` Flag
When `--config vite.config.ts` is explicitly specified, the same behavior applies. The file name is used to determine whether to extract a nested field.
## LSP
`vite.config.*` files are added to the file watch patterns so that configuration changes trigger a reload.
```
</details>
- [x] Explore the codebase (apps/oxfmt/src/lsp/, test/lsp/format/)
- [x] Make `get_file_extension_from_language_id` accessible (pub(super)) in `mod.rs`
- [x] Modify `format_file` in `server_formatter.rs` to prefer `language_id` over file extension
- [x] Update `run_format` to pass `language_id` to `format_file`
- [x] Create test fixture `apps/oxfmt/test/lsp/format/fixtures/format/test.ts.txt`
- [x] Add test case in `format.test.ts` for `.txt` file with TypeScript `language_id`
- [x] Update snapshot
- [x] Refactor: extract `apply_language_id_extension` helper shared by both `create_fake_file_path_from_language_id` and `format_file`
<!-- START COPILOT CODING AGENT TIPS -->
---
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security)
> This PR expands `oxfmt`’s LSP formatting support to treat additional non-`file://` document URIs as “in-memory” documents (instead of only handling `file://` and `untitled://`), and extends the test suite/snapshots to cover new schemes.
closes https://github.com/oxc-project/oxc-vscode/issues/8
related https://github.com/oxc-project/oxc-vscode/issues/25
> This PR adds support for formatting unsaved documents using the untitled:// URI scheme in the oxfmt LSP server. This enables VS Code and other LSP clients to format in-memory documents that haven't been saved to disk yet.
Angular is not supported for the moment, could not find a VS Code extension which defines a language ID for it :/
Fixes#19082
The CLI can format paths specified directly, even if they are `.gitignore`d.
LSP should also be able to format files if they are open in the editor.