Skip to content

Commit 3d7ee9b

Browse files
committed
Flatten cargoExtraArgs away from the runnable lsp extension
1 parent fcddcf2 commit 3d7ee9b

File tree

9 files changed

+19
-38
lines changed

9 files changed

+19
-38
lines changed

crates/rust-analyzer/src/handlers/request.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ pub(crate) fn handle_runnables(
874874
if all_targets {
875875
cargo_args.push("--all-targets".to_owned());
876876
}
877+
cargo_args.extend(config.cargo_extra_args.iter().cloned());
877878
res.push(lsp_ext::Runnable {
878879
label: format!(
879880
"cargo {cmd} -p {}{all_targets}",
@@ -887,7 +888,6 @@ pub(crate) fn handle_runnables(
887888
cwd: cwd.into(),
888889
override_cargo: config.override_cargo.clone(),
889890
cargo_args,
890-
cargo_extra_args: config.cargo_extra_args.clone(),
891891
executable_args: Vec::new(),
892892
environment: Default::default(),
893893
}),
@@ -897,6 +897,8 @@ pub(crate) fn handle_runnables(
897897
Some(TargetSpec::ProjectJson(_)) => {}
898898
None => {
899899
if !snap.config.linked_or_discovered_projects().is_empty() {
900+
let mut cargo_args = vec!["check".to_owned(), "--workspace".to_owned()];
901+
cargo_args.extend(config.cargo_extra_args.iter().cloned());
900902
res.push(lsp_ext::Runnable {
901903
label: "cargo check --workspace".to_owned(),
902904
location: None,
@@ -905,8 +907,7 @@ pub(crate) fn handle_runnables(
905907
workspace_root: None,
906908
cwd: ".".into(),
907909
override_cargo: config.override_cargo,
908-
cargo_args: vec!["check".to_owned(), "--workspace".to_owned()],
909-
cargo_extra_args: config.cargo_extra_args,
910+
cargo_args,
910911
executable_args: Vec::new(),
911912
environment: Default::default(),
912913
}),

crates/rust-analyzer/src/lsp/ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ pub enum RunnableKind {
460460
#[derive(Deserialize, Serialize, Debug)]
461461
#[serde(rename_all = "camelCase")]
462462
pub struct CargoRunnableArgs {
463+
#[serde(skip_serializing_if = "FxHashMap::is_empty")]
463464
pub environment: FxHashMap<String, String>,
464465
pub cwd: Utf8PathBuf,
465466
/// Command to be executed instead of cargo
@@ -468,15 +469,14 @@ pub struct CargoRunnableArgs {
468469
pub workspace_root: Option<Utf8PathBuf>,
469470
// command, --package and --lib stuff
470471
pub cargo_args: Vec<String>,
471-
// user-specified additional cargo args, like `--release`.
472-
pub cargo_extra_args: Vec<String>,
473472
// stuff after --
474473
pub executable_args: Vec<String>,
475474
}
476475

477476
#[derive(Deserialize, Serialize, Debug)]
478477
#[serde(rename_all = "camelCase")]
479478
pub struct ShellRunnableArgs {
479+
#[serde(skip_serializing_if = "FxHashMap::is_empty")]
480480
pub environment: FxHashMap<String, String>,
481481
pub cwd: Utf8PathBuf,
482482
pub program: String,

crates/rust-analyzer/src/lsp/to_proto.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,6 @@ pub(crate) fn runnable(
13911391
override_cargo: config.override_cargo,
13921392
cargo_args,
13931393
cwd: cwd.into(),
1394-
cargo_extra_args: config.cargo_extra_args,
13951394
executable_args,
13961395
environment: Default::default(),
13971396
}),
@@ -1435,7 +1434,6 @@ pub(crate) fn runnable(
14351434
override_cargo: config.override_cargo,
14361435
cargo_args,
14371436
cwd: Utf8PathBuf::from("."),
1438-
cargo_extra_args: config.cargo_extra_args,
14391437
executable_args,
14401438
environment: Default::default(),
14411439
}),

crates/rust-analyzer/src/target_spec.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ impl CargoTargetSpec {
110110
kind: &RunnableKind,
111111
cfg: &Option<CfgExpr>,
112112
) -> (Vec<String>, Vec<String>) {
113-
let extra_test_binary_args = snap.config.runnables().extra_test_binary_args;
113+
let config = snap.config.runnables();
114+
let extra_test_binary_args = config.extra_test_binary_args;
114115

115116
let mut cargo_args = Vec::new();
116117
let mut executable_args = Vec::new();
@@ -196,6 +197,7 @@ impl CargoTargetSpec {
196197
}
197198
}
198199
}
200+
cargo_args.extend(config.cargo_extra_args.iter().cloned());
199201
(cargo_args, executable_args)
200202
}
201203

crates/rust-analyzer/tests/slow-tests/main.rs

-7
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ fn main() {}
258258
"args": {
259259
"cargoArgs": ["test", "--package", "foo", "--test", "spam"],
260260
"executableArgs": ["test_eggs", "--exact", "--show-output"],
261-
"cargoExtraArgs": [],
262261
"overrideCargo": null,
263262
"cwd": server.path().join("foo"),
264263
"workspaceRoot": server.path().join("foo")
@@ -289,7 +288,6 @@ fn main() {}
289288
"--test",
290289
"spam"
291290
],
292-
"cargoExtraArgs": [],
293291
"executableArgs": [
294292
"",
295293
"--show-output"
@@ -325,7 +323,6 @@ fn main() {}
325323
"args": {
326324
"cargoArgs": ["check", "--package", "foo", "--all-targets"],
327325
"executableArgs": [],
328-
"cargoExtraArgs": [],
329326
"overrideCargo": null,
330327
"cwd": server.path().join("foo"),
331328
"workspaceRoot": server.path().join("foo")
@@ -337,7 +334,6 @@ fn main() {}
337334
"args": {
338335
"cargoArgs": ["test", "--package", "foo", "--all-targets"],
339336
"executableArgs": [],
340-
"cargoExtraArgs": [],
341337
"overrideCargo": null,
342338
"cwd": server.path().join("foo"),
343339
"workspaceRoot": server.path().join("foo")
@@ -426,7 +422,6 @@ mod tests {
426422
runnable,
427423
"--all-targets"
428424
],
429-
"cargoExtraArgs": [],
430425
"executableArgs": []
431426
},
432427
},
@@ -489,7 +484,6 @@ fn otherpkg() {}
489484
"mainpkg",
490485
"--all-targets"
491486
],
492-
"cargoExtraArgs": [],
493487
"executableArgs": []
494488
},
495489
},
@@ -515,7 +509,6 @@ fn otherpkg() {}
515509
"otherpkg",
516510
"--all-targets"
517511
],
518-
"cargoExtraArgs": [],
519512
"executableArgs": []
520513
},
521514
},

docs/dev/lsp-extensions.md

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!---
2-
lsp/ext.rs hash: 3605fab9e66e14a0
2+
lsp/ext.rs hash: a0867710490bf8da
33
44
If you need to change the above hash to make the test pass, please check if you
55
need to adjust this doc as well and ping this issue:
@@ -379,7 +379,7 @@ rust-analyzer supports two `kind`s of runnables, `"cargo"` and `"shell"`. The `a
379379
/**
380380
* Environment variables to set before running the command.
381381
*/
382-
environment: Record<string, string>;
382+
environment?: Record<string, string>;
383383
/**
384384
* The working directory to run the command in.
385385
*/
@@ -392,11 +392,6 @@ rust-analyzer supports two `kind`s of runnables, `"cargo"` and `"shell"`. The `a
392392
* The cargo command to run.
393393
*/
394394
cargoArgs: string[];
395-
/**
396-
* Extra arguments to pass to cargo.
397-
*/
398-
// What is the point of this when cargoArgs exists?
399-
cargoExtraArgs: string[];
400395
/**
401396
* Arguments to pass to the executable, these will be passed to the command after a `--` argument.
402397
*/
@@ -415,7 +410,7 @@ The args for `"shell"` look like this:
415410
/**
416411
* Environment variables to set before running the command.
417412
*/
418-
environment: Record<string, string>;
413+
environment?: Record<string, string>;
419414
/**
420415
* The working directory to run the command in.
421416
*/

editors/code/src/lsp_ext.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export type CommonRunnableArgs = {
239239
/**
240240
* Environment variables to set before running the command.
241241
*/
242-
environment: Record<string, string>;
242+
environment?: Record<string, string>;
243243
/**
244244
* The working directory to run the command in.
245245
*/
@@ -257,22 +257,19 @@ export type CargoRunnableArgs = {
257257
* The workspace root directory of the cargo project.
258258
*/
259259
workspaceRoot?: string;
260-
/**
261-
* The cargo command to run.
262-
*/
263-
cargoArgs: string[];
264-
/**
265-
* Extra arguments to pass to cargo.
266-
*/
267-
// What is the point of this when cargoArgs exists?
268-
cargoExtraArgs: string[];
269260
/**
270261
* Arguments to pass to the executable, these will be passed to the command after a `--` argument.
271262
*/
272263
executableArgs: string[];
264+
/**
265+
* Arguments to pass to cargo.
266+
*/
267+
cargoArgs: string[];
273268
/**
274269
* Command to execute instead of `cargo`.
275270
*/
271+
// This is supplied by the user via config. We could pull this through the client config in the
272+
// extension directly, but that would prevent us from honoring the rust-analyzer.toml for it.
276273
overrideCargo?: string;
277274
} & CommonRunnableArgs;
278275

editors/code/src/run.ts

-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ export async function createTaskFromRunnable(
165165

166166
export function createCargoArgs(runnableArgs: ra.CargoRunnableArgs): string[] {
167167
const args = [...runnableArgs.cargoArgs]; // should be a copy!
168-
if (runnableArgs.cargoExtraArgs) {
169-
args.push(...runnableArgs.cargoExtraArgs); // Append user-specified cargo options.
170-
}
171168
if (runnableArgs.executableArgs.length > 0) {
172169
args.push("--", ...runnableArgs.executableArgs);
173170
}

editors/code/tests/unit/runnable_env.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ function makeRunnable(label: string): ra.Runnable {
1212
cargoArgs: [],
1313
cwd: ".",
1414
executableArgs: [],
15-
cargoExtraArgs: [],
16-
environment: {},
1715
},
1816
};
1917
}

0 commit comments

Comments
 (0)