I use VSCode and Rust offline. and I finished to install rust-analyzer. But when I open a Rust project folder, VSCode show: rust-analyzer failed to load workspace:failed to read Cargo metadata from Cargo.toml file.
cargo metadata --all-targets work in the root of the workspace you opened in VSCode?
I get that error when there's a problem with my Cargo.toml. If you expand the box with the error, you'll see a detailed explanation. Here's an example:
rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /Users/alan/Documents/Pegasus/Cargo.toml, cargo 1.52.0 (69767412a 2021-04-21): Failed to run `cargo metadata --manifest-path /Users/alan/Documents/Pegasus/Cargo.toml` in `/Users/alan/Documents/Pegasus`: `cargo metadata` exited with an error: error: Package `pegasus v0.1.0 (/Users/alan/Documents/Pegasus)` does not have the feature `api-old`
My error is same as yours. How to resolve it.
cargo metadata --all-targets work for you?
I do it. but I work offline, it failed.@bjorn3
If you are offline, cargo won't be able to fetch the source for dependencies or even fetch the registry to get information about those dependencies. As such it is impossible for rust-analyzer to analyze dependencies. You could try vendoring the dependencies on a system connected to the internet using
cargo vendor and then copying it to the offline system.
cargo vendor will tell you how to point cargo to the vendored dependencies. You will need to do this on the offline system.
I succeded to use vendor to finished it.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.