Rust newbie here, so pardon the possibly simplistic question...
I've setup Rust using rtx (GitHub - jdxcode/rtx: Runtime Executor (asdf rust clone)) and now I'm trying to get rust-analyzer to work in VSCode. However I'm stumbling over how to get it to realize that rustup, cargo, et. al. are installed via rtx, so it fails on startup with this error:
[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to load workspace: cd "/Users/me/dev/playground/opencv-rust" && "cargo" "--version" failed: No such file or directory (os error 2)
I believe it is unable to find the cargo command, which makes sense since it's not on the default path, being managed via rtx. rtx typically installs hooks in the shell - in my case by running eval "$(/opt/homebrew/bin/rtx activate zsh)" in my ~/.zshrc.
Running cargo --version in Code's Terminal works fine - since it runs my .zshrc first, rtx is loaded and all is well. Of course the plugin does not do that, so it fails when it tries to load.
I've tried to fix this by adding configs to override the default commands, prefixing them with rtx exec rust --, however that hasn't solved the issue. Here are the configs I added:
Is there some way I can make this setup work, or do I have to rely on rustup for version management and abandon the rtx approach? If possible I'd like to keep rtx since I manage all of my programming language environments with it and that consistency helps my poor brain not get overloaded when trying to figure out how to switch versions for a given programming language. I have very limited brain capacity and I play with lots of different languages... ;]
I think rust-analyzer makes a pretty deep assumption that cargo is a binary (rather than a binary with argumens). You should be able to override the cargo it uses with:
But it seems that the core problem here is that the environment in the terminal, and in the GUI apps is different. So the best way to fix that would be to arrange for rtx to also set up env for all graphical programs. Don't know how to do that though.
[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to load workspace: cd "/Users/me/dev/playground/opencv-rust" && "rtx exec rust -- cargo" "--version" failed: No such file or directory (os error 2)
Probably because it's looking for cargo to be a plain binary, as you correctly assumed (trying to run the executable as "rtx exec rust -- cargo", which of course doesn't exist).