Skip to content

Conversation

@ethowitz
Copy link
Owner

@ethowitz ethowitz commented Oct 26, 2025

Previously, we were reporting the workspace Cargo.toml as the buildfile
for a discover invocation. This led to incorrect behavior where RA
would "unindex" any crates that were included in the first discover
invocation but not in subsequent invocations (reporting the buildfile as
the workspace Cargo.toml implies that we are telling RA about all of the
crates in the workspace, but we are actually only telling it about a
subset). Consider the following dependency graph:

A: C
B: C
C:

If we're invoked with a file from crate A, we would tell RA about
crates A and C with the workspace manifest as the buildfile. If we
are subsequently invoked with a file from crate B, we'd still report
the buildfile as the workspace manifest, but now we'd only tell RA about
crates B and C. This causes RA to "unindex" A, since we're telling
RA that the workspace doesn't include it.

This commit rectifies the issue by reporting the current crate's
Cargo.toml as the buildfile in the discover output. However, this
changes the semantics of how and when check is invoked. In the above
example, we'd now report two separate "projects" after being invoked
with files from crates A and B. Because A and B do not depend on
each other, RA will invoke check separately for each of them. This is
rather annoying if they share many dependencies (e.g. if C has a giant
dependency tree), since those check invocations will be duplicating a
lot of work.

This behavior can be adjusted by setting RA's check.invocationStrategy
setting to "once", which tells it just to invoke check for the current
project instead of all the projects we've told it about. This commit
also updates the README to reflect this change.

Fixes #34

Previously, we were reporting the workspace Cargo.toml as the buildfile
for a `discover` invocation. This led to incorrect behavior where RA
would "unindex" any crates that were included in the first `discover`
invocation but not in subsequent invocations (reporting the buildfile as
the workspace Cargo.toml implies that we are telling RA about all of the
crates in the workspace, but we are actually only telling it about a
subset). Consider the following dependency graph:

```
A: C
B: C
C:
```

If we're invoked with a file from crate `A`, we would tell RA about
crates `A` and `C` with the workspace manifest as the buildfile. If we
are subsequently invoked with a file from crate `B`, we'd still report
the buildfile as the workspace manifest, but now we'd only tell RA about
crates `B` and `C`. This causes RA to "unindex" `A`, since we're telling
RA that the workspace doesn't include it.

This commit rectifies the issue by reporting the current crate's
Cargo.toml as the buildfile in the `discover` output. However, this
changes the semantics of how and when `check` is invoked. In the above
example, we'd now report two separate "projects" after being invoked
with files from crates `A` and `B`. Because `A` and `B` do not depend on
each other, RA will invoke `check` separately for each of them. This is
rather annoying if they share many dependencies (e.g. if `C` has a giant
dependency tree), since those `check` invocations will be duplicating a
lot of work.

This behavior can be adjusted by setting RA's `check.invocationStrategy`
setting to `"once"`, which tells it just to invoke check for the current
project instead of all the projects we've told it about. This commit
also updates the README to reflect this change.

Fixes #34
@ethowitz ethowitz force-pushed the report-crate-manifest-as-buildfile branch from 8af68ec to 8a57a66 Compare October 26, 2025 16:41
@ethowitz ethowitz merged commit 99b69ec into main Oct 26, 2025
7 checks passed
@ethowitz ethowitz deleted the report-crate-manifest-as-buildfile branch October 26, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sometimes, switching to another crate seemingly causes rust analyzer to "unindex" the original crate

2 participants