-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Feature request: Option to use rust-analyzer
-specific target directory (relative to target directory)
#6007
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
Comments
Could probably be fixed by #6099 by setting CARGO_TARGET_DIR. I also wouldn't be opposed to having a dedicated option for this. |
@matklad out of curiosity, is there any reason that the vscode extension doesn't just default to using a directory that wouldn't conflict with command-line cargo use? |
Using a different destination means that you'll get two different build directories if you also build from a terminal. In normal usage, cargo check is fast enough, so it's only an issue on the first load. I prefer using the same directory to avoid building the project twice. Maybe this could be solved in cargo: release and dev builds could presumably work simultaneously. |
Another possible idea: Maybe rust-analyzer could support specifying a path to an additional |
@lnicola think there would be pleanty of users that would sacrifice diskspace of two target dirs to stop having contention all the time between RA and command line. Being able to just check a checkbox [ ] to say please use an alternative dir would be super nice. |
Can you set |
Difficulty presenting a consistent environment to rustc is causing RA to clobber my compile cache constantly (see #4616 (comment)). An inconsequential increase in disk use would be much, much better than having to spend ten minutes rebuilding the world every time I look at vscode funny. |
Setting rust-analyser.server.extraEnv isn't as user friendly as a checkbox. You need to know that a json 'object' is a map and to use { and not [ brackets. Will trial it. The other option btw is that at the bottom of vscode is a status bar where you can see what rust analyzer is doing - if we could click cancel on that so that it dropped the lock for now and tried again later that would allow the two to co-exist better. |
It also doesn't actually seem to work reliably; maybe I'm doing something wrong, but separating target dirs would be foolproof. |
As someone working on an extremely large project, where some changes (especially to Cargo.toml) can take minutes for rust-analyzer to get through (during which cargo is blocked on the command line) I'd definitely love to see direct support for this. |
This would be really helpful. On some projects I set specific I solved this for now with |
Given the amount of 👍 here, and the relative simplicity of the issue, it's a bit surprising that this isn't fixed yet. It's not utterly trivial (nothing touching the interface visible to the user ever is), but should be relatively simple. Tagging as good first issue. Some relevant pointers:
Implementation-wise, I think I'd prefer setting Also, in config we should support both |
My solution for this problem is wrapping the
#!/bin/sh
CARGO_PATH=/usr/bin/cargo
if test ! -z ${RUST_ANALYZER}; then
CARGO_TOML_PATH=$(${CARGO_PATH} locate-project --workspace --message-format=plain 2> /dev/null)
if test ! -z ${CARGO_TOML_PATH}; then
CARGO_TOML_DIR=$(dirname ${CARGO_TOML_PATH})
CARGO_TARGET_DIR=${CARGO_TOML_DIR}/target/analyzer ${CARGO_PATH} $@
exit
fi
fi
${CARGO_PATH} $@ And then set "rust-analyzer.server.extraEnv": {
"RUST_ANALYZER": "1",
} Setting
|
@matklad I would like to take this as my first issue if it's still necessary/relevant. To confirm, per your earlier comment, would this involve adding an extra option to the configuration to set a target directory relative to the project target directory? |
Edit: I solved my problem with the vs-code setting I'm not sure I totally understand, but I think I'm having the same issue. My project structure looks something like this
Am I right in thinking that I would have to open the |
@MrEmanuel: No, this isn't related to what is discussed here. You can turn |
Can’t wait for the day when rust analyzer doesn’t need to shell out to
cargo check.
…On Sat, 29 Oct 2022 at 12:01, d4h0 ***@***.***> wrote:
@MrEmanuel <https://github.com/MrEmanuel>: No, this isn't related to what
is discussed here. You can turn /my-project into a Cargo Workspace
<https://doc.rust-lang.org/cargo/reference/workspaces.html>, and add
rust-app as a crate.
—
Reply to this email directly, view it on GitHub
<#6007 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGEJCHHNWHD2KGRLN5R7QDWFT7ZRANCNFSM4RNDL4BA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I think I found good workaround that wasn't mentioned above. Step 1: Create a global Cargo profile in Cargo's config file. (Note: Not in the project On Linux, edit [profile.rust-analyzer]
inherits = "dev" This creates a new Cargo profile that has the same values as the default Step 2: Tell Rust-Analyzer to use this new How to do that depends on your editor. For Helix you do it simply by adding the following code to your [[language]]
name = "rust"
config = {checkOnSave = {extraArgs = ["--profile", "rust-analyzer"]}} Now Rust-Analyzer will always execute |
@d4h0 's solution worked for me in VSCode with a minor tweak. Instead of setting the profile on the In my "rust-analyzer.cargo.extraArgs": [
"--profile",
"rust-analyzer"
], |
@liamaharon That doesn't seem to work for me (using the Helix editor). The |
Using NeoVim, adding it to both causes an error for me, saying that the arg can't be repeated. It shouldn't depend on the editor, so not sure what's up. |
Just fyi I use this code in VS Code: {
"rust-analyzer.cargo.extraEnv": {
"CARGO_PROFILE_RUST_ANALYZER_INHERITS": "dev"
},
"rust-analyzer.cargo.extraArgs": [
"--profile",
"rust-analyzer"
]
} No need to create a global cargo config. |
I've been using this quite successfully too: {
"rust-analyzer.server.extraEnv": {
"CARGO_TARGET_DIR": "target/analyzer"
},
"rust-analyzer.check.extraArgs": [
"--target-dir=target/analyzer"
]
} |
Updating from 2023-04-24 to 2023-05-01 broke proc macros for me as the |
References: rust-lang/rust-analyzer#6007 (comment) Signed-off-by: Fletcher Nichol <[email protected]>
Can someone please tell us which one works? |
Adds a Rust Analyzer configuration option to set a custom target directory for builds. This is a workaround for Rust Analyzer blocking debug builds while running `cargo check`. This change should close rust-lang#6007
Adds a Rust Analyzer configuration option to set a custom target directory for builds. This is a workaround for Rust Analyzer blocking debug builds while running `cargo check`. This change should close rust-lang#6007
Adds a Rust Analyzer configuration option to set a custom target directory for builds. This is a workaround for Rust Analyzer blocking debug builds while running `cargo check`. This change should close rust-lang#6007
Adds a Rust Analyzer configuration option to set a custom target directory for builds. This is a workaround for Rust Analyzer blocking debug builds while running `cargo check`. This change should close rust-lang#6007
Add config option to use `rust-analyzer` specific target dir Adds a Rust Analyzer configuration option to set a custom target directory for builds. This is a workaround for Rust Analyzer blocking debug builds while running `cargo check`. This change should close #6007. This is my first time contributing to this project, so any feedback regarding best practices that I'm not aware of are greatly appreciated! Thanks to all the maintainers for their hard work on this project and reviewing contributions.
* add symlink * ignore artifacts * settings.json works way better rust-lang/rust-analyzer#6007 (comment) * fix EOF (hopefully) * fix another EOF * mention some recommended extensions
see this rust-analyzer configuration: rust-lang/rust-analyzer#6007 (comment)
this simple option works in helix: [language-server.rust-analyzer.config.cargo]
targetDir = true you can also set it to a relative path (the default with |
For vscode put the following in {
"rust-analyzer.cargo.targetDir": true,
} |
@raldone01 thank you! |
This would be useful to implement one of the workarounds for Rust analyzer "cargo check" blocks debug builds #4616 for people who use workspaces.
Normally, my current working directory is a specific crate, but I could also be in the workspace directory.
Because of that, if I add
["--target-dir", "/path/to/proect/target/check"]
to "rust-analyzer.checkOnSave.extraArgs" I can't use a relative path (the path would be "target/check" if I'm in the workspace, or "../target/check" if I'm in a crate directory).Workarounds would be to use an absolute path (then I have to set this config option for every project) or to create a symbolic link in every crate to the target directory of the workspace.
A better solution, IMO, would be if there was an option for Rust-Analyzer to use a specific directory relative to the target directory.
Edit: This comment contains a good workaround to switch Rust-Analyzer to a different Cargo profile, globally.
The text was updated successfully, but these errors were encountered: