Hi, I have a question as a fellow LanguageServer implementer, how does rust-analyzer fetch and manage dependencies?
rustup I would assume
I would have to pay closer attention next time it updates though
From what I recall it uses
cargo metadata, this crate is the relevant part for that I believe https://github.com/rust-analyzer/rust-analyzer/tree/master/crates/project_model/src
hmmm, thanks for the link, although I'm unable to see where in the code it fetches dependencies. Does rust-analyzer avoid a race condition between when it is fetching dependencies and if the user is fetching dependencies?
which dependencies are you interested in?
Do you mean the actual download of dependencies / the index? That is handled by Cargo, which has a file lock on the corresponding directories, which should avoid any races.
Ah, I see. Cargo handling the race condition makes sense. (I'm not interested in any particular dependency, I'm interested in how dependencies are fetched in general)
It does also use
rustup to install the
Hi @Jason Axelson !
I believe the best approach here is to let the build system do the heavy lifting. ie, the server asks where the deps are, and the build system provides the server with paths (maybe fetching some from the internet).
One problem here is that the user and the server might invoke the build system concurrently. Solution to that is just to make sure that the build system is concurrency-safe. I submitted some bugs and fixed for Cargo for this, back when I worked on IntelliJ.
Thanks for the info @matklad, solving it in the build system makes a lot of sense.