Skip to content

Commit c466460

Browse files
committed
Use package root as cargo check working directory
Cargo commands are affected by the `.cargo/config` files above their working directory. If cargo is invoked from above the directory holding `Cargo.toml`, it may not pick up important settings like registry replacements, causing it to behave differently or even fail. Most cargo invocations are currently setting their working directories to the directory containing `Cargo.toml`, but a couple of paths remain in which cargo is invoked from the default workspace root instead. This change fixes that, resolving some cargo check failures that I experienced in a multi-root workspace in which packages used different registries.
1 parent 312f1fe commit c466460

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

crates/flycheck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ impl FlycheckActor {
215215
} => {
216216
let mut cmd = Command::new(toolchain::cargo());
217217
cmd.arg(command);
218+
cmd.current_dir(&self.workspace_root);
218219
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
219220
.arg(self.workspace_root.join("Cargo.toml"));
220221

crates/project_model/src/build_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ impl WorkspaceBuildData {
143143
cmd.env("RA_RUSTC_WRAPPER", "1");
144144
}
145145

146+
cmd.current_dir(cargo_toml.parent().unwrap());
146147
cmd.args(&["check", "--quiet", "--workspace", "--message-format=json", "--manifest-path"])
147148
.arg(cargo_toml.as_ref());
148149

0 commit comments

Comments
 (0)