Skip to content

Commit 0ce842d

Browse files
committed
Extend cargo_unsetTest to support "all" like cargo_features
1 parent 187bd7d commit 0ce842d

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 34 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",
@@ -919,7 +921,10 @@ impl Config {
919921
target: self.data.cargo_target.clone(),
920922
no_sysroot: self.data.cargo_noSysroot,
921923
rustc_source,
922-
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
924+
unset_test_crates: match &self.data.cargo_unsetTest {
925+
CargoUnsetTest::All => UnsetTestCrates::All,
926+
CargoUnsetTest::Listed(crates) => UnsetTestCrates::Only(crates.clone()),
927+
},
923928
wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper,
924929
run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(),
925930
}
@@ -1411,6 +1416,14 @@ enum CargoFeatures {
14111416
Listed(Vec<String>),
14121417
}
14131418

1419+
#[derive(Deserialize, Debug, Clone)]
1420+
#[serde(untagged)]
1421+
enum CargoUnsetTest {
1422+
#[serde(deserialize_with = "de_unit_v::all")]
1423+
All,
1424+
Listed(Vec<String>),
1425+
}
1426+
14141427
#[derive(Deserialize, Debug, Clone)]
14151428
#[serde(untagged)]
14161429
enum LifetimeElisionDef {
@@ -1756,6 +1769,23 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
17561769
{ "type": "null" }
17571770
],
17581771
},
1772+
"CargoUnsetTest" => set! {
1773+
"anyOf": [
1774+
{
1775+
"type": "string",
1776+
"enum": [
1777+
"all"
1778+
],
1779+
"enumDescriptions": [
1780+
"All crates are analyzed without `--cfg=test`",
1781+
]
1782+
},
1783+
{
1784+
"type": "array",
1785+
"items": { "type": "string" }
1786+
}
1787+
],
1788+
},
17591789
"CallableCompletionDef" => set! {
17601790
"type": "string",
17611791
"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: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,27 @@
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",
468-
"items": {
469-
"type": "string"
470-
}
467+
"anyOf": [
468+
{
469+
"type": "string",
470+
"enum": [
471+
"all"
472+
],
473+
"enumDescriptions": [
474+
"All crates are analyzed without `--cfg=test`"
475+
]
476+
},
477+
{
478+
"type": "array",
479+
"items": {
480+
"type": "string"
481+
}
482+
}
483+
]
471484
},
472485
"rust-analyzer.checkOnSave.allTargets": {
473486
"markdownDescription": "Check all targets and tests (`--all-targets`).",

0 commit comments

Comments
 (0)