rust-lang / rust-lang/rust-analyzer

Feature: smart order of cargo diagnostics

Open
#7,660 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics S-unactionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

It seems that currently diagnostics are sorted by file path. This order isn't very useful when one wants to refactor some low-level modules (and their API is changed), because higher-level modules get errors too, and these errors are unactionable (One can't fix high-level code because they haven't updated low-level code yet).

I'd propose the following algorithm to determine better readable diagnostic order:

  1. Build an oriented graph, where each vertex corresponds to a source file, and edge u -> v exists if the file u references file v (e.g. mentions an item defined in v).
  2. Find any topological sorting of this graph.
  3. When return diagnostics, sort them using source file's position in the sorting as a comparison key.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing where rust-analyzer currently orders diagnostics by source-file path. Study how file-reference relationships could provide the directed graph, then determine how to handle cycles and disconnected files. Done means diagnostics are returned in a useful topological order so lower-level errors precede dependent higher-level errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.