Skip to content

Commit 122446e

Browse files
committed
Extend cargo_unsetTest to support "all" like cargo_features
1 parent 50ed1a5 commit 122446e

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,17 @@ config_data! {
8686
/// List of features to activate.
8787
///
8888
/// Set this to `"all"` to pass `--all-features` to cargo.
89-
cargo_features: CargoFeatures = "[]",
89+
cargo_features: CargoFeatures = "[]",
9090
/// Whether to pass `--no-default-features` to cargo.
9191
cargo_noDefaultFeatures: bool = "false",
9292
/// Internal config for debugging, disables loading of sysroot crates.
9393
cargo_noSysroot: bool = "false",
9494
/// Compilation target override (target triple).
9595
cargo_target: Option<String> = "null",
96-
/// Unsets `#[cfg(test)]` for the specified crates.
97-
cargo_unsetTest: Vec<String> = "[\"core\"]",
96+
/// List of crates for which `--cfg=test` should not be used.
97+
///
98+
/// Set this to `"all"` to never use `--cfg=test`. By default, `--cfg=test` is always used.
99+
cargo_unsetTest: CargoUnsetTest = "[\"core\"]",
98100

99101
/// Check all targets and tests (`--all-targets`).
100102
checkOnSave_allTargets: bool = "true",
@@ -912,7 +914,10 @@ impl Config {
912914
target: self.data.cargo_target.clone(),
913915
no_sysroot: self.data.cargo_noSysroot,
914916
rustc_source,
915-
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
917+
unset_test_crates: match &self.data.cargo_unsetTest {
918+
CargoUnsetTest::All => UnsetTestCrates::All,
919+
CargoUnsetTest::Listed(crates) => UnsetTestCrates::Only(crates.clone()),
920+
},
916921
wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper,
917922
run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(),
918923
}
@@ -1398,6 +1403,14 @@ enum CargoFeatures {
13981403
Listed(Vec<String>),
13991404
}
14001405

1406+
#[derive(Deserialize, Debug, Clone)]
1407+
#[serde(untagged)]
1408+
enum CargoUnsetTest {
1409+
#[serde(deserialize_with = "de_unit_v::all")]
1410+
All,
1411+
Listed(Vec<String>),
1412+
}
1413+
14011414
#[derive(Deserialize, Debug, Clone)]
14021415
#[serde(untagged)]
14031416
enum LifetimeElisionDef {
@@ -1743,6 +1756,22 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
17431756
{ "type": "null" }
17441757
],
17451758
},
1759+
"CargoUnsetTest" => set! {
1760+
"type": ["string", "array"],
1761+
"items": { "type": "string" },
1762+
"enum": ["all"],
1763+
"enumDescriptions": [
1764+
"All crates are analyzed without `--cfg=test`",
1765+
],
1766+
},
1767+
"Option<CargoUnsetTest>" => set! {
1768+
"type": ["string", "array", "null"],
1769+
"items": { "type": "string" },
1770+
"enum": ["all"],
1771+
"enumDescriptions": [
1772+
"All crates are analyzed without `--cfg=test`",
1773+
],
1774+
},
17461775
"CallableCompletionDef" => set! {
17471776
"type": "string",
17481777
"enum": [

docs/user/generated_config.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ Compilation target override (target triple).
7171
[[rust-analyzer.cargo.unsetTest]]rust-analyzer.cargo.unsetTest (default: `["core"]`)::
7272
+
7373
--
74-
Unsets `#[cfg(test)]` for the specified crates.
74+
List of crates for which `--cfg=test` should not be used.
75+
76+
Set this to `"all"` to never use `--cfg=test`. By default, `--cfg=test` is always used.
7577
--
7678
[[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`)::
7779
+

editors/code/package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,23 @@
460460
]
461461
},
462462
"rust-analyzer.cargo.unsetTest": {
463-
"markdownDescription": "Unsets `#[cfg(test)]` for the specified crates.",
463+
"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.",
464464
"default": [
465465
"core"
466466
],
467-
"type": "array",
467+
"type": [
468+
"string",
469+
"array"
470+
],
468471
"items": {
469472
"type": "string"
470-
}
473+
},
474+
"enum": [
475+
"all"
476+
],
477+
"enumDescriptions": [
478+
"All crates are analyzed without `--cfg=test`"
479+
]
471480
},
472481
"rust-analyzer.checkOnSave.allTargets": {
473482
"markdownDescription": "Check all targets and tests (`--all-targets`).",

0 commit comments

Comments
 (0)