From 0ce842d05cd25cf1bcbac8b578f30ec1f67e0737 Mon Sep 17 00:00:00 2001 From: ia0 Date: Tue, 10 May 2022 21:59:11 +0200 Subject: [PATCH] Extend cargo_unsetTest to support "all" like cargo_features --- crates/rust-analyzer/src/config.rs | 38 ++++++++++++++++++++++++++---- docs/user/generated_config.adoc | 4 +++- editors/code/package.json | 23 ++++++++++++++---- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 304254c3e26e..d27a1a058e65 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -86,15 +86,17 @@ config_data! { /// List of features to activate. /// /// Set this to `"all"` to pass `--all-features` to cargo. - cargo_features: CargoFeatures = "[]", + cargo_features: CargoFeatures = "[]", /// Whether to pass `--no-default-features` to cargo. cargo_noDefaultFeatures: bool = "false", /// Internal config for debugging, disables loading of sysroot crates. cargo_noSysroot: bool = "false", /// Compilation target override (target triple). cargo_target: Option = "null", - /// Unsets `#[cfg(test)]` for the specified crates. - cargo_unsetTest: Vec = "[\"core\"]", + /// List of crates for which `--cfg=test` should not be used. + /// + /// Set this to `"all"` to never use `--cfg=test`. By default, `--cfg=test` is always used. + cargo_unsetTest: CargoUnsetTest = "[\"core\"]", /// Check all targets and tests (`--all-targets`). checkOnSave_allTargets: bool = "true", @@ -919,7 +921,10 @@ impl Config { target: self.data.cargo_target.clone(), no_sysroot: self.data.cargo_noSysroot, rustc_source, - unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()), + unset_test_crates: match &self.data.cargo_unsetTest { + CargoUnsetTest::All => UnsetTestCrates::All, + CargoUnsetTest::Listed(crates) => UnsetTestCrates::Only(crates.clone()), + }, wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper, run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(), } @@ -1411,6 +1416,14 @@ enum CargoFeatures { Listed(Vec), } +#[derive(Deserialize, Debug, Clone)] +#[serde(untagged)] +enum CargoUnsetTest { + #[serde(deserialize_with = "de_unit_v::all")] + All, + Listed(Vec), +} + #[derive(Deserialize, Debug, Clone)] #[serde(untagged)] enum LifetimeElisionDef { @@ -1756,6 +1769,23 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json { "type": "null" } ], }, + "CargoUnsetTest" => set! { + "anyOf": [ + { + "type": "string", + "enum": [ + "all" + ], + "enumDescriptions": [ + "All crates are analyzed without `--cfg=test`", + ] + }, + { + "type": "array", + "items": { "type": "string" } + } + ], + }, "CallableCompletionDef" => set! { "type": "string", "enum": [ diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index d8585ffb1deb..1b9a5147f25e 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -71,7 +71,9 @@ Compilation target override (target triple). [[rust-analyzer.cargo.unsetTest]]rust-analyzer.cargo.unsetTest (default: `["core"]`):: + -- -Unsets `#[cfg(test)]` for the specified crates. +List of crates for which `--cfg=test` should not be used. + +Set this to `"all"` to never use `--cfg=test`. By default, `--cfg=test` is always used. -- [[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`):: + diff --git a/editors/code/package.json b/editors/code/package.json index 02899b6d17ba..fd157434dbf6 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -460,14 +460,27 @@ ] }, "rust-analyzer.cargo.unsetTest": { - "markdownDescription": "Unsets `#[cfg(test)]` for the specified crates.", + "markdownDescription": "List of crates for which `--cfg=test` should not be used.\n\nSet this to `\"all\"` to never use `--cfg=test`. By default, `--cfg=test` is always used.", "default": [ "core" ], - "type": "array", - "items": { - "type": "string" - } + "anyOf": [ + { + "type": "string", + "enum": [ + "all" + ], + "enumDescriptions": [ + "All crates are analyzed without `--cfg=test`" + ] + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] }, "rust-analyzer.checkOnSave.allTargets": { "markdownDescription": "Check all targets and tests (`--all-targets`).",