Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14328 - lnicola:build-scripts-extra-args, r=Veykril
fix: Pass flycheck extra args when running build scripts
Closes #14315
Not sure if we want to do it like this or to add an extra config key, though.
| -rw-r--r-- | crates/project-model/src/build_scripts.rs | 1 | ||||
| -rw-r--r-- | crates/project-model/src/cargo_workspace.rs | 2 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/config.rs | 15 | ||||
| -rw-r--r-- | docs/user/generated_config.adoc | 5 | ||||
| -rw-r--r-- | editors/code/package.json | 8 |
5 files changed, 30 insertions, 1 deletions
diff --git a/crates/project-model/src/build_scripts.rs b/crates/project-model/src/build_scripts.rs index 38c1b37f0e..6df1273edd 100644 --- a/crates/project-model/src/build_scripts.rs +++ b/crates/project-model/src/build_scripts.rs @@ -67,6 +67,7 @@ impl WorkspaceBuildScripts { let mut cmd = Command::new(toolchain::cargo()); cmd.args(["check", "--quiet", "--workspace", "--message-format=json"]); + cmd.args(&config.extra_args); // --all-targets includes tests, benches and examples in addition to the // default lib and bins. This is an independent concept from the --target diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index fdc7859eb9..732adc50b5 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -105,6 +105,8 @@ pub struct CargoConfig { pub wrap_rustc_in_build_scripts: bool, /// The command to run instead of `cargo check` for building build scripts. pub run_build_script_command: Option<Vec<String>>, + /// Extra args to pass to the cargo command. + pub extra_args: Vec<String>, /// Extra env vars to set when invoking the cargo command pub extra_env: FxHashMap<String, String>, pub invocation_strategy: InvocationStrategy, diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 0d75607f35..75233dbb2a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -101,6 +101,8 @@ config_data! { /// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to /// avoid checking unnecessary things. cargo_buildScripts_useRustcWrapper: bool = "true", + /// Extra arguments that are passed to every cargo invocation. + cargo_extraArgs: Vec<String> = "[]", /// Extra environment variables that will be set when running cargo, rustc /// or other commands within the workspace. Useful for setting RUSTFLAGS. cargo_extraEnv: FxHashMap<String, String> = "{}", @@ -1055,10 +1057,20 @@ impl Config { } } + pub fn extra_args(&self) -> &Vec<String> { + &self.data.cargo_extraArgs + } + pub fn extra_env(&self) -> &FxHashMap<String, String> { &self.data.cargo_extraEnv } + pub fn check_extra_args(&self) -> Vec<String> { + let mut extra_args = self.extra_args().clone(); + extra_args.extend_from_slice(&self.data.check_extraArgs); + extra_args + } + pub fn check_extra_env(&self) -> FxHashMap<String, String> { let mut extra_env = self.data.cargo_extraEnv.clone(); extra_env.extend(self.data.check_extraEnv.clone()); @@ -1157,6 +1169,7 @@ impl Config { InvocationLocation::Workspace => project_model::InvocationLocation::Workspace, }, run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(), + extra_args: self.data.cargo_extraArgs.clone(), extra_env: self.data.cargo_extraEnv.clone(), } } @@ -1227,7 +1240,7 @@ impl Config { CargoFeaturesDef::All => vec![], CargoFeaturesDef::Selected(it) => it, }, - extra_args: self.data.check_extraArgs.clone(), + extra_args: self.check_extra_args(), extra_env: self.check_extra_env(), ansi_color_output: self.color_diagnostic_output(), }, diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 1bc498c42c..6937a7ed9a 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -71,6 +71,11 @@ cargo check --quiet --workspace --message-format=json --all-targets Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to avoid checking unnecessary things. -- +[[rust-analyzer.cargo.extraArgs]]rust-analyzer.cargo.extraArgs (default: `[]`):: ++ +-- +Extra arguments that are passed to every cargo invocation. +-- [[rust-analyzer.cargo.extraEnv]]rust-analyzer.cargo.extraEnv (default: `{}`):: + -- diff --git a/editors/code/package.json b/editors/code/package.json index 90f7b9074c..a3b1a3107d 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -511,6 +511,14 @@ "default": true, "type": "boolean" }, + "rust-analyzer.cargo.extraArgs": { + "markdownDescription": "Extra arguments that are passed to every cargo invocation.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, "rust-analyzer.cargo.extraEnv": { "markdownDescription": "Extra environment variables that will be set when running cargo, rustc\nor other commands within the workspace. Useful for setting RUSTFLAGS.", "default": {}, |