refactor(lsp): tools can report diagnostics for other uris too#16783
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the LSP tool diagnostic API to allow tools to report diagnostics for multiple URIs, not just the file being analyzed. This enables cross-file analysis features like import cycle detection where a tool analyzing one file may need to report issues in related files.
Key changes:
- Introduces
DiagnosticResulttype alias asVec<(Uri, Vec<Diagnostic>)>to return diagnostics for multiple URIs - Updates all diagnostic trait methods to return
DiagnosticResultinstead ofOption<Vec<Diagnostic>> - Adds
collect_diagnostics_withaggregation helper inWorkspaceWorkerto merge diagnostics from multiple tools - Updates backend to use
publish_all_diagnosticshelper for publishing multi-URI diagnostic results
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_language_server/src/tool.rs | Defines new DiagnosticResult type and updates trait method signatures to return multi-URI diagnostics |
| crates/oxc_language_server/src/worker.rs | Adds collect_diagnostics_with aggregator and refactors diagnostic methods to handle multi-URI results |
| crates/oxc_language_server/src/tests.rs | Updates fake tool implementation to return diagnostics using new tuple structure |
| crates/oxc_language_server/src/linter/tester.rs | Adds snapshot helpers for multi-URI diagnostic results |
| crates/oxc_language_server/src/linter/server_linter.rs | Implements new trait interface by wrapping single-file diagnostics in Vec with URI |
| crates/oxc_language_server/src/backend.rs | Updates diagnostic publishing to use publish_all_diagnostics helper for multi-URI results |
| crates/oxc_language_server/src/linter/snapshots/*.snap | Updates snapshot test outputs to include "File URI" prefix for each file's diagnostics |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3c1dfc8 to
ff29f34
Compare
There was a problem hiding this comment.
The new multi-URI diagnostic plumbing is solid, but a few behavioral edges need tightening: aggregation order is nondeterministic due to HashMap iteration, snapshot URI scrubbing can now panic!() for non-file:///non-repo URIs, and the tester output conflates “ignored” with “no diagnostics.” Additionally, the backend appears to have dropped LSP diagnostic version publication for did_open/did_change, which can cause stale diagnostics if publish_all_diagnostics doesn’t preserve versions.
Additional notes (1)
- Compatibility |
crates/oxc_language_server/src/backend.rs:510-510
Indid_open/did_change, the old flow published diagnostics with a version (Some(params.text_document.version)), but the new flow callspublish_all_diagnostics(diagnostics)without passing the version.
If publish_all_diagnostics doesn’t incorporate the document version, clients may receive diagnostics that apply to a different buffer version (especially with on-type linting), which can lead to stale/incorrect squiggles.
This is a behavior change; it should be intentional and verified.
Summary of changes
Summary of changes
Multi-URI diagnostics support
- Introduced
DiagnosticResult = Vec<(Uri, Vec<Diagnostic>)>incrates/oxc_language_server/src/tool.rs. - Updated
Tool::{run_diagnostic, run_diagnostic_on_save, run_diagnostic_on_change}to returnDiagnosticResult(defaulting to an empty vector) instead ofOption<Vec<Diagnostic>>.
Worker aggregation changes
- Refactored
WorkspaceWorkerto aggregate diagnostics across tools and URIs viacollect_diagnostics_with, merging results into a per-Uricollection (HashMap<Uri, Vec<Diagnostic>>). - Updated all worker diagnostic entry points (
run_diagnostic*) to return multi-URI results.
Backend publishing flow
- Updated backend call sites (
did_open,did_change,did_save, and initial workspace scan) to consume multi-URI results and publish viapublish_all_diagnostics.
Linter and tests/snapshots
- Updated
ServerLinterto wrap single-file lint results intovec![(uri.clone(), diagnostics)]. - Updated snapshot formatting to include
Linted file:and per-entryFile URI:headers; added URI “scrubbing” helper for deterministic snapshots. - Updated fake tool and worker tests to assert against the new
(Uri, Vec<Diagnostic>)structure.
ff29f34 to
8d04ae2
Compare
Merge activity
|
> This PR refactors the LSP tool diagnostic API to allow tools to report diagnostics for multiple URIs, not just the file being analyzed. This enables cross-file analysis features like ts config deprecation detection.
8d04ae2 to
a3b9eff
Compare

Uh oh!
There was an error while loading. Please reload this page.