I installed the Rust Analyser, but it can't see cargo and rustc:
[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to load workspace: Failed to load the project at
Failed to query rust toolchain version at
&& "cargo" "--version" failed: No such file or directory (os error 2)
But I copy and paste the same command from the VS Code terminal into bash and it works flawlessly with the same directory.
How do I fix this please? I'm on Ubuntu, with rustc and cargo installed, VS Code and Rust-Analyser installed. I can't see any settings related to my path.
Same here. No problems with VS Code and Rust so far on Windows. Need to try it on a WSL2 Debian instance soon. I just want to check out alternatives, but I don't plan to replace VS Code which runs well for my needs in any language so far.
This just says install the analyzer and rust, which I've done, and Rust works. The article is mostly a list of analyzer features - it doesn't explain how to configure it at all.
I beg your pardon, then. Sorry, I guess I missed what you exactly need to configure. For me it works if I have a toml file and create the project with cargo new. If I use an empty folder and just place a .rs file into it, it doesn't work. I guess this is what you want to fix. Hope some more experienced community members can help you out.
I install rust with rustup
I install vscode
I open vscode and install rust analyzer
I create a new rust project with cargo new
I open vscode and use "open folder" to point it at the new project
I create a new vscode workspace for the project
The most likely explanation here is that the environment is different between terminal and GUI. E.g, cargo is in PATH when run from the terminal, but not when run through VS Code launched as GUI.
To test this hypothesis, try launching code itself from the terminal. If the works, it’d say it’s 0.9 that the underlying issue is different PATH between terminal and GUI.
The underlying reason for this mess is that by default on Linux there’s no reliable way to set PATH both for graphical and console environments.
@matklad, Thanks, I can start VSCode from the terminal fine: flatpak run com.visualstudio.code
I tried running a JS file from VSCode and it couldn't find Node, but once I made a launch.json and set "runtimeExecutable": "/home/me/.nvm/versions/node/v18.18.0/bin/node" it ran fine.
Is there a similar configuration file for Rust please?
If you use flatpak you need to tell flatpak to override the PATH env var to include the absolute path to the .cargo/bin directory in your home dir. I don't know how to do that using the flatpak cli, but with Flatseal it should be pretty easy.