Skip to content

Commit a893f20

Browse files
authored
bug: Fix handling of CARGO_HOME (#30)
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
1 parent cbc18d1 commit a893f20

3 files changed

Lines changed: 10 additions & 22 deletions

File tree

README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,8 @@ also be set via lspconfig.
139139

140140
### Kate
141141

142-
Kate doesn't seem to include the typical cargo home (`<YOUR HOME DIRECTORY>/.cargo/bin`) directory
143-
on the `PATH` it passes to rust-analyzer, so you'll need to pass the cargo home path to
144-
`cargo-subspace` directly and provide an absolute path to the `cargo-subspace` binary itself.
145-
In the example below, `<CARGO HOME>` should be substituted for an absolute path to the directory
146-
in which your cargo binaries reside (usually, this is `<YOUR HOME DIRECTORY>/.cargo/bin`).
147-
148-
These settings should be specified in `Settings --> LSP Client --> User Server Settings`:
142+
These settings should be specified in `Settings --> LSP Client --> User Server Settings`. Note the
143+
`"useWorkspace": false` line; this is required!
149144

150145
```json
151146
{
@@ -154,19 +149,16 @@ These settings should be specified in `Settings --> LSP Client --> User Server S
154149
"useWorkspace": false,
155150
"initializationOptions": {
156151
"check": {
157-
"allFeatures": true,
158152
"overrideCommand": [
159-
"<CARGO HOME>/cargo-subspace",
160-
"--cargo-home=<CARGO HOME>",
153+
"cargo-subspace",
161154
"clippy",
162155
"$saved_file"
163156
]
164157
},
165158
"workspace": {
166159
"discoverConfig": {
167160
"command": [
168-
"<CARGO HOME>/cargo-subspace",
169-
"--cargo-home=<CARGO HOME>",
161+
"cargo-subspace",
170162
"discover",
171163
"{arg}"
172164
],
@@ -182,8 +174,6 @@ These settings should be specified in `Settings --> LSP Client --> User Server S
182174
}
183175
```
184176

185-
Note the `"useWorkspace": false` line; this is required!
186-
187177
## Troubleshooting/Debugging
188178

189179
If you run into trouble, please feel free to open an issue with the following:

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct CargoSubspace {
1414
#[arg(long, short)]
1515
pub verbose: bool,
1616

17-
/// The explicit path to the directory containing your cargo binaries. By default,
18-
/// `cargo-subspace` will use the binaries on your `PATH`.
17+
/// The explicit path to your cargo home. Typically, this is `$HOME/.cargo`. If this flag is not
18+
/// included, `cargo-subspace` will use the binaries on your `PATH`.
1919
#[arg(long, env = "CARGO_HOME")]
2020
pub cargo_home: Option<PathBuf>,
2121

src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ impl Context {
8181
}
8282

8383
fn toolchain_command(&self, command: &str) -> Command {
84-
let mut cmd = Command::new(command);
85-
8684
if let Some(cargo_home) = self.cargo_home.as_ref() {
87-
cmd.env("PATH", cargo_home);
85+
Command::new(cargo_home.join("bin").join(command))
86+
} else {
87+
Command::new(command)
8888
}
89-
90-
cmd
9189
}
9290
}
9391

@@ -189,7 +187,7 @@ fn discover(ctx: &Context, discover_args: DiscoverArgs, manifest_path: FilePath<
189187
cmd.manifest_path(manifest_path);
190188

191189
if let Some(cargo_home) = ctx.cargo_home.as_ref() {
192-
cmd.cargo_path(cargo_home.join("cargo"));
190+
cmd.cargo_path(cargo_home.join("bin/cargo"));
193191
}
194192

195193
if let Some(target_triple) = target_triple {

0 commit comments

Comments
 (0)