-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set cargo path #16204
Comments
In this setup, how do you invoke cargo on the CLI? You are not typing the entire |
Pixi allows you to run arbitrary commands within the new env:
|
Ah, interesting! Yeah, currently rust-analyzer assumes that it can invoke So, the best fix here would probably be just: The current work-around would be to launch VS Code from Alternatively, perhaps there could be a VS Code extension for |
Yes, being able to set something like
It would work but it's not ideal.
|
@matklad would that require a lot of work to implement your proposal? I am still learning rust, but would be happy to give it a shot if it's a low-hanging fruit. It's also a general solution that would benefit beyond |
For what it's worth, I hacked up something similar for the |
Facing the same problem. Is there any progress? |
I belive you can now use config like the fololwing "rust-analyzer.server.extraEnv": {
"CARGO": "/your/project/.pixi/env/cargo"
} (I havin't actually tried this, so it might need adjustmeents, but something like that should work) |
Your configuration won't work directly, but setting "extraEnv" is indeed a feasible idea. The underlying logic of switching environments in pixi is to set a series of specific environment variables and run some specific "activation" scripts if necessary. Detailed information can be found at: https://pixi.sh/latest/features/environment/#activation Therefore, I can run "pixi shell-hook" to check the environment variables needed for activation and then manually add them to "rust-analyzer.cargo.extraEnv". In fact, the result I get from executing "pixi shell-hook" is: # pixi shell-hook
export PATH="/Users/nova/rust-learn/my_rust_project/.pixi/envs/default/bin:/Users/nova/.nvm/versions/node/v21.6.2/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/nova/.cargo/bin:/Users/nova/.rye/shims:/Users/nova/.nvm/versions/node/v21.6.2/bin:/opt/homebrew/bin:/opt/homebrew/sbin"
export CONDA_PREFIX="/Users/nova/rust-learn/my_rust_project/.pixi/envs/default"
export PIXI_PROMPT="(my_rust_project) "
export PIXI_PROJECT_VERSION="0.1.0"
export PIXI_PROJECT_NAME="my_rust_project"
export PIXI_EXE="/opt/homebrew/bin/pixi"
export PIXI_ENVIRONMENT_PLATFORMS="osx-arm64"
export PIXI_PROJECT_ROOT="/Users/nova/rust-learn/my_rust_project"
export PIXI_PROJECT_MANIFEST="/Users/nova/rust-learn/my_rust_project/pixi.toml"
export PIXI_IN_SHELL="1"
export PIXI_ENVIRONMENT_NAME="default"
export CONDA_DEFAULT_ENV="my_rust_project" Among these, the truly important part is Therefore, I can set "rust-analyzer.cargo.extraEnv" at the "workspace level": {
"rust-analyzer.server.extraEnv": {
"PATH": "/Users/nova/rust-learn/my_rust_project/.pixi/envs/default/bin:$PATH"
}
} After setting this, restart the rust-analyzer plugin or reload VSCode, and you will find that the rust-analyzer plugin can check the syntax of .rs files. However, this is still not a perfect solution. For example, clicking the * Executing task: cargo run --package my_rust_project --bin my_rust_project
* The terminal process failed to launch: Path to shell executable "cargo" does not exist. Moreover, this method of manually setting the PATH is not only cumbersome (you have to set it manually for each new workspace, because pixi creates separate environment folders for each new project. ) but also inconvenient for switching between multiple Rust environments(nightly beta etc.). A better solution is still needed! |
Any fix? |
@b0c1 reopen vscode process, maybe can fix. |
Did you solve the |
Would it be possible to add a configuration to be able to set the path to
cargo
?Related to #3154
Setting
PATH
would not work for my use case. I am using pixi to set up and install the dev environment. This tool installs cargo and all the deps inside{{ workspace_folder }}/.pixi/env
.The text was updated successfully, but these errors were encountered: