From 90466e4c71951abe17759126ccc59db69698056c Mon Sep 17 00:00:00 2001 From: Ethan Donowitz Date: Tue, 14 Oct 2025 09:09:12 -0400 Subject: [PATCH 1/2] bug: Fix handling of CARGO_HOME We were incorrectly expecting the given CARGO_HOME to point to `$CARGO_HOME/bin`, but the `bin` dir is actually a subdirectory of the cargo home. This commit fixes it. Fixes #29 --- README.md | 18 ++++-------------- src/main.rs | 4 ++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 080d9a4..9f0dbb4 100644 --- a/README.md +++ b/README.md @@ -139,13 +139,8 @@ also be set via lspconfig. ### Kate -Kate doesn't seem to include the typical cargo home (`/.cargo/bin`) directory -on the `PATH` it passes to rust-analyzer, so you'll need to pass the cargo home path to -`cargo-subspace` directly and provide an absolute path to the `cargo-subspace` binary itself. -In the example below, `` should be substituted for an absolute path to the directory -in which your cargo binaries reside (usually, this is `/.cargo/bin`). - -These settings should be specified in `Settings --> LSP Client --> User Server Settings`: +These settings should be specified in `Settings --> LSP Client --> User Server Settings`. Note the +`"useWorkspace": false` line; this is required! ```json { @@ -154,10 +149,8 @@ These settings should be specified in `Settings --> LSP Client --> User Server S "useWorkspace": false, "initializationOptions": { "check": { - "allFeatures": true, "overrideCommand": [ - "/cargo-subspace", - "--cargo-home=", + "cargo-subspace", "clippy", "$saved_file" ] @@ -165,8 +158,7 @@ These settings should be specified in `Settings --> LSP Client --> User Server S "workspace": { "discoverConfig": { "command": [ - "/cargo-subspace", - "--cargo-home=", + "cargo-subspace", "discover", "{arg}" ], @@ -182,8 +174,6 @@ These settings should be specified in `Settings --> LSP Client --> User Server S } ``` -Note the `"useWorkspace": false` line; this is required! - ## Troubleshooting/Debugging If you run into trouble, please feel free to open an issue with the following: diff --git a/src/main.rs b/src/main.rs index 9ea3b2c..6ad79a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,7 +84,7 @@ impl Context { let mut cmd = Command::new(command); if let Some(cargo_home) = self.cargo_home.as_ref() { - cmd.env("PATH", cargo_home); + cmd.env("PATH", cargo_home.join("bin")); } cmd @@ -189,7 +189,7 @@ fn discover(ctx: &Context, discover_args: DiscoverArgs, manifest_path: FilePath< cmd.manifest_path(manifest_path); if let Some(cargo_home) = ctx.cargo_home.as_ref() { - cmd.cargo_path(cargo_home.join("cargo")); + cmd.cargo_path(cargo_home.join("bin/cargo")); } if let Some(target_triple) = target_triple { From eb436a2e2ff43bc2c6492f44b51c68ede3e4413f Mon Sep 17 00:00:00 2001 From: Ethan Donowitz Date: Tue, 14 Oct 2025 09:20:23 -0400 Subject: [PATCH 2/2] fix --- src/cli.rs | 4 ++-- src/main.rs | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 1c2bbc3..1d0eac6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,8 +14,8 @@ pub struct CargoSubspace { #[arg(long, short)] pub verbose: bool, - /// The explicit path to the directory containing your cargo binaries. By default, - /// `cargo-subspace` will use the binaries on your `PATH`. + /// The explicit path to your cargo home. Typically, this is `$HOME/.cargo`. If this flag is not + /// included, `cargo-subspace` will use the binaries on your `PATH`. #[arg(long, env = "CARGO_HOME")] pub cargo_home: Option, diff --git a/src/main.rs b/src/main.rs index 6ad79a7..4adb0b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,13 +81,11 @@ impl Context { } fn toolchain_command(&self, command: &str) -> Command { - let mut cmd = Command::new(command); - if let Some(cargo_home) = self.cargo_home.as_ref() { - cmd.env("PATH", cargo_home.join("bin")); + Command::new(cargo_home.join("bin").join(command)) + } else { + Command::new(command) } - - cmd } }