Skip to content

Commit

Permalink
Flatten cargoExtraArgs away from the runnable lsp extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jul 6, 2024
1 parent fcddcf2 commit f26cb92
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 26 deletions.
7 changes: 4 additions & 3 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ pub(crate) fn handle_runnables(
if all_targets {
cargo_args.push("--all-targets".to_owned());
}
cargo_args.extend(config.cargo_extra_args.iter().cloned());
res.push(lsp_ext::Runnable {
label: format!(
"cargo {cmd} -p {}{all_targets}",
Expand All @@ -887,7 +888,6 @@ pub(crate) fn handle_runnables(
cwd: cwd.into(),
override_cargo: config.override_cargo.clone(),
cargo_args,
cargo_extra_args: config.cargo_extra_args.clone(),
executable_args: Vec::new(),
environment: Default::default(),
}),
Expand All @@ -897,6 +897,8 @@ pub(crate) fn handle_runnables(
Some(TargetSpec::ProjectJson(_)) => {}
None => {
if !snap.config.linked_or_discovered_projects().is_empty() {
let mut cargo_args = vec!["check".to_owned(), "--workspace".to_owned()];
cargo_args.extend(config.cargo_extra_args.iter().cloned());
res.push(lsp_ext::Runnable {
label: "cargo check --workspace".to_owned(),
location: None,
Expand All @@ -905,8 +907,7 @@ pub(crate) fn handle_runnables(
workspace_root: None,
cwd: ".".into(),
override_cargo: config.override_cargo,
cargo_args: vec!["check".to_owned(), "--workspace".to_owned()],
cargo_extra_args: config.cargo_extra_args,
cargo_args,
executable_args: Vec::new(),
environment: Default::default(),
}),
Expand Down
2 changes: 0 additions & 2 deletions crates/rust-analyzer/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ pub struct CargoRunnableArgs {
pub workspace_root: Option<Utf8PathBuf>,
// command, --package and --lib stuff
pub cargo_args: Vec<String>,
// user-specified additional cargo args, like `--release`.
pub cargo_extra_args: Vec<String>,
// stuff after --
pub executable_args: Vec<String>,
}
Expand Down
2 changes: 0 additions & 2 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,6 @@ pub(crate) fn runnable(
override_cargo: config.override_cargo,
cargo_args,
cwd: cwd.into(),
cargo_extra_args: config.cargo_extra_args,
executable_args,
environment: Default::default(),
}),
Expand Down Expand Up @@ -1435,7 +1434,6 @@ pub(crate) fn runnable(
override_cargo: config.override_cargo,
cargo_args,
cwd: Utf8PathBuf::from("."),
cargo_extra_args: config.cargo_extra_args,
executable_args,
environment: Default::default(),
}),
Expand Down
4 changes: 3 additions & 1 deletion crates/rust-analyzer/src/target_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl CargoTargetSpec {
kind: &RunnableKind,
cfg: &Option<CfgExpr>,
) -> (Vec<String>, Vec<String>) {
let extra_test_binary_args = snap.config.runnables().extra_test_binary_args;
let config = snap.config.runnables();
let extra_test_binary_args = config.extra_test_binary_args;

let mut cargo_args = Vec::new();
let mut executable_args = Vec::new();
Expand Down Expand Up @@ -196,6 +197,7 @@ impl CargoTargetSpec {
}
}
}
cargo_args.extend(config.cargo_extra_args.iter().cloned());
(cargo_args, executable_args)
}

Expand Down
5 changes: 0 additions & 5 deletions docs/dev/lsp-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,6 @@ rust-analyzer supports two `kind`s of runnables, `"cargo"` and `"shell"`. The `a
* The cargo command to run.
*/
cargoArgs: string[];
/**
* Extra arguments to pass to cargo.
*/
// What is the point of this when cargoArgs exists?
cargoExtraArgs: string[];
/**
* Arguments to pass to the executable, these will be passed to the command after a `--` argument.
*/
Expand Down
15 changes: 6 additions & 9 deletions editors/code/src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,19 @@ export type CargoRunnableArgs = {
* The workspace root directory of the cargo project.
*/
workspaceRoot?: string;
/**
* The cargo command to run.
*/
cargoArgs: string[];
/**
* Extra arguments to pass to cargo.
*/
// What is the point of this when cargoArgs exists?
cargoExtraArgs: string[];
/**
* Arguments to pass to the executable, these will be passed to the command after a `--` argument.
*/
executableArgs: string[];
/**
* Arguments to pass to cargo.
*/
cargoArgs: string[];
/**
* Command to execute instead of `cargo`.
*/
// This is supplied by the user via config. We could pull this through the client config in the
// extension directly, but that would prevent us from honoring the rust-analyzer.toml for it.
overrideCargo?: string;
} & CommonRunnableArgs;

Expand Down
3 changes: 0 additions & 3 deletions editors/code/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ export async function createTaskFromRunnable(

export function createCargoArgs(runnableArgs: ra.CargoRunnableArgs): string[] {
const args = [...runnableArgs.cargoArgs]; // should be a copy!
if (runnableArgs.cargoExtraArgs) {
args.push(...runnableArgs.cargoExtraArgs); // Append user-specified cargo options.
}
if (runnableArgs.executableArgs.length > 0) {
args.push("--", ...runnableArgs.executableArgs);
}
Expand Down
1 change: 0 additions & 1 deletion editors/code/tests/unit/runnable_env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function makeRunnable(label: string): ra.Runnable {
cargoArgs: [],
cwd: ".",
executableArgs: [],
cargoExtraArgs: [],
environment: {},
},
};
Expand Down

0 comments on commit f26cb92

Please sign in to comment.