Reputation: 61
I know that there are a lot of similar questions regarding rust-analyzer and I've checked them out but couldn't find the solution to my problem so I decided to ask a question myself. I've decided to start learning Rust and I'm having issues with rust-analyzer. Here is my workspace structure:
I created a project using cargo and hoped that rust-analyzer will automatically register it but for some reason it fails. I get this error message
> rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml, cargo 1.61.0 (a028ae4 2022-04-29): Failed to run `"/home/remax/.cargo/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: could not execute process `rustc -vV` (never executed)
Caused by:
No such file or directory (os error 2)
I honestly have no idea what to do. My cargo version is 1.61.0
UPDATE: issue persists even with only rust project in workspace
Upvotes: 4
Views: 15826
Reputation: 41
In case you are using zed IDE, it can be solve by edit the Cargo.toml by deleting [package] and [dependencies] and just leaving the [workspace], for example:
[workspace] members = ["api", "domain", "infrastructure", "application", "shared"]
Upvotes: 0
Reputation: 1208
You might have missed the rustup step. It is stated in the rust-analyzer extension that you need to install rustup first.
Upvotes: 1
Reputation: 529
I often encounter this issue. For me this fixed it
Find settings.json
as given in this answer:
In my case the settings file has the following lines:
"rust-analyzer.cargo.autoreload": false,
"rust-analyzer.cargo.features": [
]
Delete these lines and restart rust-analyer in vscode using cmd+shift+P
and rust-analyzer: Restart Server
Upvotes: 0
Reputation: 16685
The issue happens because all the workspace directories, when vscode detects those, are stored within the <project root>/.vscode/settings.json
file, like this:
{
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
]
}
When you move your sub-crates around manually, vscode can't detect this, and change this array of Cargo.toml
s, too. So you should open this file and manually correct the entries there so that only the existing workspaces (entries of Cargo.toml
paths) are listed in the array.
Upvotes: 5
Reputation: 1
in Rust you don't have to create the Cargo.toml file manually for a new project. delete your current workspace then, make a new dir eg, mkdir "home/spitfire/Documents/rust" cd into rust make a new project file in the root dir in this case is rust
like this "cargo new learning"
you will get an output like this Created binary (application) learning
package
check the learning folder it will contain Cargo.toml go back to rust by doing .. reload vscode and enjoy rust
Upvotes: 0
Reputation: 1
Upgrade your rust-analyzer extension to the pre-release(v0.4.1525) one. This fixed the issue on my Macbook Pro m1.
Upvotes: 0
Reputation: 61
I solved the issue by deleting the .vscode folder. Reinstalling rustup didn't help.
The issue started appearing when I created a lib and then deleted it.
Upvotes: 4
Reputation: 1
rustup must be installed in the same system as Vscode. If you are using WLS Subsystem (like me), try installing rustup on Windows with the rustup-init.exe.
Run/Debug won't work (probably - I don't know why, but there's always cargo run
) but you'll still get all the other features.
Upvotes: 0