Skip to content

Commit f26cb92

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

File tree

8 files changed

+13
-26
lines changed

8 files changed

+13
-26
lines changed

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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,6 @@ pub struct CargoRunnableArgs {
468468
pub workspace_root: Option<Utf8PathBuf>,
469469
// command, --package and --lib stuff
470470
pub cargo_args: Vec<String>,
471-
// user-specified additional cargo args, like `--release`.
472-
pub cargo_extra_args: Vec<String>,
473471
// stuff after --
474472
pub executable_args: Vec<String>,
475473
}

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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

docs/dev/lsp-extensions.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/

editors/code/src/lsp_ext.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function makeRunnable(label: string): ra.Runnable {
1212
cargoArgs: [],
1313
cwd: ".",
1414
executableArgs: [],
15-
cargoExtraArgs: [],
1615
environment: {},
1716
},
1817
};

0 commit comments

Comments
 (0)