Skip to content

Extend cargo_unsetTest to support "all" like cargo_features #11962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = "null",
/// Unsets `#[cfg(test)]` for the specified crates.
cargo_unsetTest: Vec<String> = "[\"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",
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -1411,6 +1416,14 @@ enum CargoFeatures {
Listed(Vec<String>),
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
enum CargoUnsetTest {
#[serde(deserialize_with = "de_unit_v::all")]
All,
Listed(Vec<String>),
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
enum LifetimeElisionDef {
Expand Down Expand Up @@ -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": [
Expand Down
4 changes: 3 additions & 1 deletion docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`)::
+
Expand Down
23 changes: 18 additions & 5 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`).",
Expand Down