rust-lang / rust-lang/rust-analyzer
Add infrastructure to narrow down diagnostic ranges
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
In https://github.com/rust-analyzer/rust-analyzer/pull/10499 and https://github.com/rust-analyzer/rust-analyzer/pull/10425 I've implemented some hacks to narrow down diagnostics range. "Remove this semicolon" diagnostics points to the whole expr_stmt, while we want to highlight only the ;. Similarly, for mismatch arg count we want to highlight only extra/missing args.
The impl there works for the common cases, but is wrong in general.
The overall problem is that diagnostic point to a syntax node in a potentially macro expanded file. We want to narrow this range down while still in the macro-expanded file, but then map it to the original file.
diagnostics_display_range doesn't support this API. We probably should remove diagnostics_display_range from Semancis entirely, and instead implement a helper for that in ide_diagnostics directly, such that it supports sub-node ranges.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the implementations in PRs #10499 and #10425, then trace diagnostics_display_range and Semancis into ide_diagnostics. Define how sub-node ranges are narrowed in macro-expanded files and mapped back to the original file; done means semicolon and argument-count diagnostics highlight only the relevant syntax while general cases remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100