Description
openedon Aug 15, 2022
In the workspace with several projects, when a new project is added (e.g. by cargo new example
and adding example
in members list in Cargo.toml
), rust-analyzer doesn't work at all in the new project until rust-analyzer is restarted.
To reproduce it is important to edit Cargo.toml
with some external editor (in my actual case Cargo.toml
is updated by another program automatically, and rust-analyzer doesn't notice it). In case you manually save Cargo.toml
again in VSCode, it will trigger DidSaveTextDocument
, which in the end does a full workspace reload and fixes the problem. But if the DidSaveTextDocument
event does not happen, a new project is not analyzed by rust-analyzer.
I did some git bisect and figured out that it stopped working a week ago after this pull request #12947 by @Veykril was merged.
As I understand previously it worked like this. After creating a new project (say example
), adding it to the Cargo.toml
, and opening example/src/main.rs
in VSCode, GlobalState::process_changes
is called with this file, which added something to self.fetch_workspaces_queue
, and in the end, triggered workspace reload.
But in the newest version of rust-analyzer, there is an additional check that the source root of the modified file is not a library. It sounds like a reasonable check (and I'd expect rust-analyzer to think about example
project as not library). As I understand the problem is when new roots are calculated, source_root_config
doesn't know yet about new files, and classify them into last special file_set
(which is considered as a library).
Funny enough unknown files are not always mapped into that last special file_set. For example, if project example
is already present, and you add a new project, which starts from the same name (e.g. example2
), FileSetConfig
maps files from the new project to the old one (until it will know example2
is actually a separate thing). This probably should be also fixed.
To end this long (sorry for that) text, I don't really know what should be the correct fix for this issue (e.g. I don't really understand why rust-analyzer doesn't just watch for updates of Cargo.toml
), but hope at least my findings will help somebody to fix it :)
rust-analyzer version: both current master (3903243), and current stable version (2022-08-15) doesn't work. 97038e5 worked fine.
rustc version: rustc 1.65.0-nightly (29e4a9ee0 2022-08-10)
I use Ubuntu if it matters.