In #20327 we started truncating custom check commands so they render
nicely in the IDE. This was then accidentally undone in
9c18569d0c87d7f643db50b4806b59642762f1c3, and ended up making the
command summary longer (it included full paths).
We ended up with a `Display` implementation and a `display_command`
function that both tried to solve the same problem. I've merged and
simplified the logic and added tests.
Example
---
```rust
fn foo(cond: bool) {
if cond.$0
}
```
**Before this PR**
```text
...
sn deref *expr
sn ref &expr
...
```
**After this PR**
```text
...
sn deref *expr
sn not !expr
sn ref &expr
...
```
The usage of normal `display()` caused it to emit `{unknown}` which then failed to parse in `make::ty()`.
Really we should not use stringly-typed things here, but that's a change for another day.
PR #18043 changed flycheck to be scoped to the relevant package. This
broke projects using check commands that invoke rustc directly,
because diagnostic JSON from rustc doesn't contain the package ID.
This was visible in the rust-analyzer logs when RA_LOG is set to
`rust_analyzer::flycheck=trace`.
Before:
2026-02-02T07:03:48.020184937-08:00 TRACE diagnostic received flycheck_id=0 mismatched types package_id=None scope=Workspace
...
2026-02-02T07:03:55.082046488-08:00 TRACE clearing diagnostics flycheck_id=0 scope=Workspace
After:
2026-02-02T07:14:32.760707785-08:00 TRACE diagnostic received flycheck_id=0 mismatched types package_id=None scope=Package { package: BuildInfo { label: "fbcode//rust_devx/rust-guess-deps:rust-guess-deps" }, workspace_deps: Some({}) }
...
2026-02-02T07:14:48.355981415-08:00 TRACE clearing diagnostics flycheck_id=0 scope=Package { package: BuildInfo { label: "fbcode//rust_devx/rust-guess-deps:rust-guess-deps" }, workspace_deps: Some({}) }
Previously r-a assumed that a diagnostic without a package ID applied
to the whole workspace. We would insert the diagnostic at the
workspace level, but then only clear diagnostics for the package.
As a result, red squiggles would get 'stuck'. Users who had fixed
compilation issues would still see the old red squiggles until they
introduced a new compilation error.
Instead, always apply diagnostics to the current package if flycheck
is scoped to a package and the diagnostic doesn't specify a
package. This makes CargoCheckEvent(None) and CargoCheckEvent(Some(_))
more consistent, as they now both match on scope.
CargoCheckMessage and CargoCheckParser were misleading, because they
could apply to any tool that emits diagnostics. For example, it may be
rustc directly rather than via cargo.
Clarify this in the names. This is most noticeable when working on
custom check commands in rust-project.json.