Flatten cargoExtraArgs away from the runnable lsp extension

This commit is contained in:
Lukas Wirth 2024-07-06 16:28:45 +02:00
parent fcddcf2ee5
commit 3d7ee9b4ea
9 changed files with 19 additions and 38 deletions

View file

@ -874,6 +874,7 @@ pub(crate) fn handle_runnables(
if all_targets { if all_targets {
cargo_args.push("--all-targets".to_owned()); cargo_args.push("--all-targets".to_owned());
} }
cargo_args.extend(config.cargo_extra_args.iter().cloned());
res.push(lsp_ext::Runnable { res.push(lsp_ext::Runnable {
label: format!( label: format!(
"cargo {cmd} -p {}{all_targets}", "cargo {cmd} -p {}{all_targets}",
@ -887,7 +888,6 @@ pub(crate) fn handle_runnables(
cwd: cwd.into(), cwd: cwd.into(),
override_cargo: config.override_cargo.clone(), override_cargo: config.override_cargo.clone(),
cargo_args, cargo_args,
cargo_extra_args: config.cargo_extra_args.clone(),
executable_args: Vec::new(), executable_args: Vec::new(),
environment: Default::default(), environment: Default::default(),
}), }),
@ -897,6 +897,8 @@ pub(crate) fn handle_runnables(
Some(TargetSpec::ProjectJson(_)) => {} Some(TargetSpec::ProjectJson(_)) => {}
None => { None => {
if !snap.config.linked_or_discovered_projects().is_empty() { 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 { res.push(lsp_ext::Runnable {
label: "cargo check --workspace".to_owned(), label: "cargo check --workspace".to_owned(),
location: None, location: None,
@ -905,8 +907,7 @@ pub(crate) fn handle_runnables(
workspace_root: None, workspace_root: None,
cwd: ".".into(), cwd: ".".into(),
override_cargo: config.override_cargo, override_cargo: config.override_cargo,
cargo_args: vec!["check".to_owned(), "--workspace".to_owned()], cargo_args,
cargo_extra_args: config.cargo_extra_args,
executable_args: Vec::new(), executable_args: Vec::new(),
environment: Default::default(), environment: Default::default(),
}), }),

View file

@ -460,6 +460,7 @@ pub enum RunnableKind {
#[derive(Deserialize, Serialize, Debug)] #[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct CargoRunnableArgs { pub struct CargoRunnableArgs {
#[serde(skip_serializing_if = "FxHashMap::is_empty")]
pub environment: FxHashMap<String, String>, pub environment: FxHashMap<String, String>,
pub cwd: Utf8PathBuf, pub cwd: Utf8PathBuf,
/// Command to be executed instead of cargo /// Command to be executed instead of cargo
@ -468,8 +469,6 @@ pub struct CargoRunnableArgs {
pub workspace_root: Option<Utf8PathBuf>, pub workspace_root: Option<Utf8PathBuf>,
// command, --package and --lib stuff // command, --package and --lib stuff
pub cargo_args: Vec<String>, pub cargo_args: Vec<String>,
// user-specified additional cargo args, like `--release`.
pub cargo_extra_args: Vec<String>,
// stuff after -- // stuff after --
pub executable_args: Vec<String>, pub executable_args: Vec<String>,
} }
@ -477,6 +476,7 @@ pub struct CargoRunnableArgs {
#[derive(Deserialize, Serialize, Debug)] #[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ShellRunnableArgs { pub struct ShellRunnableArgs {
#[serde(skip_serializing_if = "FxHashMap::is_empty")]
pub environment: FxHashMap<String, String>, pub environment: FxHashMap<String, String>,
pub cwd: Utf8PathBuf, pub cwd: Utf8PathBuf,
pub program: String, pub program: String,

View file

@ -1391,7 +1391,6 @@ pub(crate) fn runnable(
override_cargo: config.override_cargo, override_cargo: config.override_cargo,
cargo_args, cargo_args,
cwd: cwd.into(), cwd: cwd.into(),
cargo_extra_args: config.cargo_extra_args,
executable_args, executable_args,
environment: Default::default(), environment: Default::default(),
}), }),
@ -1435,7 +1434,6 @@ pub(crate) fn runnable(
override_cargo: config.override_cargo, override_cargo: config.override_cargo,
cargo_args, cargo_args,
cwd: Utf8PathBuf::from("."), cwd: Utf8PathBuf::from("."),
cargo_extra_args: config.cargo_extra_args,
executable_args, executable_args,
environment: Default::default(), environment: Default::default(),
}), }),

View file

@ -110,7 +110,8 @@ impl CargoTargetSpec {
kind: &RunnableKind, kind: &RunnableKind,
cfg: &Option<CfgExpr>, cfg: &Option<CfgExpr>,
) -> (Vec<String>, Vec<String>) { ) -> (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 cargo_args = Vec::new();
let mut executable_args = Vec::new(); let mut executable_args = Vec::new();
@ -196,6 +197,7 @@ impl CargoTargetSpec {
} }
} }
} }
cargo_args.extend(config.cargo_extra_args.iter().cloned());
(cargo_args, executable_args) (cargo_args, executable_args)
} }

View file

@ -258,7 +258,6 @@ fn main() {}
"args": { "args": {
"cargoArgs": ["test", "--package", "foo", "--test", "spam"], "cargoArgs": ["test", "--package", "foo", "--test", "spam"],
"executableArgs": ["test_eggs", "--exact", "--show-output"], "executableArgs": ["test_eggs", "--exact", "--show-output"],
"cargoExtraArgs": [],
"overrideCargo": null, "overrideCargo": null,
"cwd": server.path().join("foo"), "cwd": server.path().join("foo"),
"workspaceRoot": server.path().join("foo") "workspaceRoot": server.path().join("foo")
@ -289,7 +288,6 @@ fn main() {}
"--test", "--test",
"spam" "spam"
], ],
"cargoExtraArgs": [],
"executableArgs": [ "executableArgs": [
"", "",
"--show-output" "--show-output"
@ -325,7 +323,6 @@ fn main() {}
"args": { "args": {
"cargoArgs": ["check", "--package", "foo", "--all-targets"], "cargoArgs": ["check", "--package", "foo", "--all-targets"],
"executableArgs": [], "executableArgs": [],
"cargoExtraArgs": [],
"overrideCargo": null, "overrideCargo": null,
"cwd": server.path().join("foo"), "cwd": server.path().join("foo"),
"workspaceRoot": server.path().join("foo") "workspaceRoot": server.path().join("foo")
@ -337,7 +334,6 @@ fn main() {}
"args": { "args": {
"cargoArgs": ["test", "--package", "foo", "--all-targets"], "cargoArgs": ["test", "--package", "foo", "--all-targets"],
"executableArgs": [], "executableArgs": [],
"cargoExtraArgs": [],
"overrideCargo": null, "overrideCargo": null,
"cwd": server.path().join("foo"), "cwd": server.path().join("foo"),
"workspaceRoot": server.path().join("foo") "workspaceRoot": server.path().join("foo")
@ -426,7 +422,6 @@ mod tests {
runnable, runnable,
"--all-targets" "--all-targets"
], ],
"cargoExtraArgs": [],
"executableArgs": [] "executableArgs": []
}, },
}, },
@ -489,7 +484,6 @@ fn otherpkg() {}
"mainpkg", "mainpkg",
"--all-targets" "--all-targets"
], ],
"cargoExtraArgs": [],
"executableArgs": [] "executableArgs": []
}, },
}, },
@ -515,7 +509,6 @@ fn otherpkg() {}
"otherpkg", "otherpkg",
"--all-targets" "--all-targets"
], ],
"cargoExtraArgs": [],
"executableArgs": [] "executableArgs": []
}, },
}, },

View file

@ -1,5 +1,5 @@
<!--- <!---
lsp/ext.rs hash: 3605fab9e66e14a0 lsp/ext.rs hash: a0867710490bf8da
If you need to change the above hash to make the test pass, please check if you If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue: 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
/** /**
* Environment variables to set before running the command. * Environment variables to set before running the command.
*/ */
environment: Record<string, string>; environment?: Record<string, string>;
/** /**
* The working directory to run the command in. * The working directory to run the command in.
*/ */
@ -392,11 +392,6 @@ rust-analyzer supports two `kind`s of runnables, `"cargo"` and `"shell"`. The `a
* The cargo command to run. * The cargo command to run.
*/ */
cargoArgs: string[]; 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. * Arguments to pass to the executable, these will be passed to the command after a `--` argument.
*/ */
@ -415,7 +410,7 @@ The args for `"shell"` look like this:
/** /**
* Environment variables to set before running the command. * Environment variables to set before running the command.
*/ */
environment: Record<string, string>; environment?: Record<string, string>;
/** /**
* The working directory to run the command in. * The working directory to run the command in.
*/ */

View file

@ -239,7 +239,7 @@ export type CommonRunnableArgs = {
/** /**
* Environment variables to set before running the command. * Environment variables to set before running the command.
*/ */
environment: Record<string, string>; environment?: Record<string, string>;
/** /**
* The working directory to run the command in. * The working directory to run the command in.
*/ */
@ -257,22 +257,19 @@ export type CargoRunnableArgs = {
* The workspace root directory of the cargo project. * The workspace root directory of the cargo project.
*/ */
workspaceRoot?: string; 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. * Arguments to pass to the executable, these will be passed to the command after a `--` argument.
*/ */
executableArgs: string[]; executableArgs: string[];
/**
* Arguments to pass to cargo.
*/
cargoArgs: string[];
/** /**
* Command to execute instead of `cargo`. * 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; overrideCargo?: string;
} & CommonRunnableArgs; } & CommonRunnableArgs;

View file

@ -165,9 +165,6 @@ export async function createTaskFromRunnable(
export function createCargoArgs(runnableArgs: ra.CargoRunnableArgs): string[] { export function createCargoArgs(runnableArgs: ra.CargoRunnableArgs): string[] {
const args = [...runnableArgs.cargoArgs]; // should be a copy! 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) { if (runnableArgs.executableArgs.length > 0) {
args.push("--", ...runnableArgs.executableArgs); args.push("--", ...runnableArgs.executableArgs);
} }

View file

@ -12,8 +12,6 @@ function makeRunnable(label: string): ra.Runnable {
cargoArgs: [], cargoArgs: [],
cwd: ".", cwd: ".",
executableArgs: [], executableArgs: [],
cargoExtraArgs: [],
environment: {},
}, },
}; };
} }