The terminal process failed to launch: Path to shell executable "cargo" does not exist.
When clicking Run I get this in the terminal:
> Executing task: cargo run --package helloworld --bin helloworld <
The terminal process failed to launch: Path to shell executable "cargo" does not exist.
Terminal will be reused by tasks, press any key to close it.
rust-analyzer version: rust-analyzer version: 5fae65dd2 2022-03-07 stable
rustc version: rustc 1.61.0-nightly (458262b13 2022-03-09)
relevant settings:
"rust-analyzer.server.extraEnv": {
"CARGO": "/opt/rust/cargo/bin/cargo",
"RUSTC": "/opt/rust/cargo/bin/rustc",
},
Additional Information:
When I use:
"rust-analyzer.server.extraEnv": {
// "CARGO": "/opt/rust/cargo/bin/cargo",
"RUSTC": "/opt/rust/cargo/bin/rustc",
},
I get
rust-analyzer failed to load workspace: "cargo" "--version" failed: No such file or directory (os error 2)
and when I use:
"rust-analyzer.server.extraEnv": {
"CARGO": "/opt/rust/cargo/bin/cargo",
//"RUSTC": "/opt/rust/cargo/bin/rustc",
},
rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /mnt/helloworld/Cargo.toml. Is rust-src installed?: "rustc" "--print" "sysroot" failed: No such file or directory (os error 2)
I'm using Code-Server to install the .vsix directly using code-server --install-extension rust-analyzer-linux-x64.vsix. The behavior should be the same as a locally installed copy of VSCode since Code-Server uses a fork of it under the hood.
When I run directly from the terminal:
> cargo run
Compiling helloworld v0.1.0 (/mnt/helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 0.14s
Running `target/debug/helloworld`
Hello, world!
Installed components :
> rustup component list --installed
cargo-x86_64-unknown-linux-gnu
clippy-x86_64-unknown-linux-gnu
rust-analysis-x86_64-unknown-linux-gnu
rust-docs-x86_64-unknown-linux-gnu
rust-src
rust-std-x86_64-unknown-linux-gnu
rustc-x86_64-unknown-linux-gnu
rustfmt-x86_64-unknown-linux-gnu
I've also tried these settings with no change to behavior:
{
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.automationProfile.linux": {"path":"/bin/bash"},
}
/opt/rust/cargo/bin is not in your PATH when connecting via VS Code. I think there should be some ways to set environment variables for remote connections.
I guess the one setting I didn't mention is that I have is:
{"terminal.integrated.env.linux": {
"PATH": "/usr/lib/code-server/vendor/modules/code-oss-dev/bin:/opt/versions/node/v16.14.0/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
},
which puts it on the path and is why I can run cargo in the terminal.
So altogether for the relevant settings I have:
{
"terminal.integrated.env.linux": {
"PATH": "/usr/lib/code-server/vendor/modules/code-oss-dev/bin:/opt/versions/node/v16.14.0/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
},
"rust-analyzer.server.extraEnv": {
"CARGO": "/opt/rust/cargo/bin/cargo",
"RUSTC": "/opt/rust/cargo/bin/rustc",
},
}
That only applies to the integrated terminal, not to the code-server process. You might need to add it to ~/.bash_profile or something.
I added "rust-analyzer.runnableEnv": {"PATH": "/opt/rust/cargo/bin"} and it works now
now the settings.json looks like this:
{
"terminal.integrated.env.linux": {
"PATH": "/usr/lib/code-server/vendor/modules/code-oss-dev/bin:/opt/versions/node/v16.14.0/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
},
"rust-analyzer.server.extraEnv": {
"CARGO": "/opt/rust/cargo/bin/cargo",
"RUSTC": "/opt/rust/cargo/bin/rustc",
},
"rust-analyzer.runnableEnv": {"PATH": "/opt/rust/cargo/bin"}
}
for those who 1) use vscode remotely, 2) can run cargo in terminal, but vscode can't found cargo:
Final Solution
Kill the running vscode server, then reload the vscode.
Steps
- go to panel "Output" -> "Remote - SSH"
- get the server pid from output like this:
[12:36:33.333] [server] Found running server (pid=782060)
- kill the process by pid
- reload the vscode
for those who 1) use vscode remotely, 2) can run cargo in terminal, but vscode can't found cargo:
Final Solution
Kill the running vscode server, then reload the vscode.
Steps
- go to panel "Output" -> "Remote - SSH"
- get the server pid from output like this:
[12:36:33.333] [server] Found running server (pid=782060)
- kill the process by pid
- reload the vscode
Thank you, this realy help me.
{ "rust-analyzer.restartServerOnConfigChange": true, "rust-analyzer.runnables.extraEnv": {"PATH": "${env:HOME}/.cargo/bin:${env:PATH}"} }
reload
Work for me, thank you so much!!!
{ "rust-analyzer.restartServerOnConfigChange": true, "rust-analyzer.runnables.extraEnv": {"PATH": "${env:HOME}/.cargo/bin:${env:PATH}"} }
This is what worked for me! Thank you so much, I tried all the other solutions and they didn't fix it fully T-T