Unnamed repository; edit this file 'description' to name the repository.
Set `CARGO_TARGET_DIR` when using Flycheck custom command
Victor Song 2023-10-09
parent ef0b3bb · commit 3682c37
-rw-r--r--crates/flycheck/src/lib.rs6
-rw-r--r--crates/rust-analyzer/src/config.rs4
2 files changed, 9 insertions, 1 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index 0749d91eb3..f0d2f79f63 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -58,6 +58,7 @@ pub enum FlycheckConfig {
extra_env: FxHashMap<String, String>,
invocation_strategy: InvocationStrategy,
invocation_location: InvocationLocation,
+ target_dir: Option<PathBuf>,
},
}
@@ -354,10 +355,15 @@ impl FlycheckActor {
extra_env,
invocation_strategy,
invocation_location,
+ target_dir,
} => {
let mut cmd = Command::new(command);
cmd.envs(extra_env);
+ if let Some(target_dir) = target_dir {
+ cmd.env("CARGO_TARGET_DIR", target_dir);
+ }
+
match invocation_location {
InvocationLocation::Workspace => {
match invocation_strategy {
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 39a98bcd29..23cf71cff4 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -1289,6 +1289,7 @@ impl Config {
}
pub fn flycheck(&self) -> FlycheckConfig {
+ let target_dir = self.target_dir_from_config();
match &self.data.check_overrideCommand {
Some(args) if !args.is_empty() => {
let mut args = args.clone();
@@ -1309,6 +1310,7 @@ impl Config {
}
InvocationLocation::Workspace => flycheck::InvocationLocation::Workspace,
},
+ target_dir,
}
}
Some(_) | None => FlycheckConfig::CargoCommand {
@@ -1343,7 +1345,7 @@ impl Config {
extra_args: self.check_extra_args(),
extra_env: self.check_extra_env(),
ansi_color_output: self.color_diagnostic_output(),
- target_dir: self.target_dir_from_config(),
+ target_dir,
},
}
}