Skip to content

Commit

Permalink
Auto merge of rust-lang#13661 - iredelmeier:fix-null-checkonsave-targ…
Browse files Browse the repository at this point in the history
…et, r=jonas-schievink

Fix: Handle empty `checkOnSave/target` values

This fixes a regression introduced by rust-lang#13290, in which failing to set `checkOnSave/target` (or `checkOnSave/targets`) would lead to an invalid config.

[Fixes rust-lang#13660]
  • Loading branch information
bors committed Nov 24, 2022
2 parents 63a676e + b116fe9 commit e9f6087
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
20 changes: 14 additions & 6 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ config_data! {
/// `["aarch64-apple-darwin", "x86_64-apple-darwin"]`.
///
/// Aliased as `"checkOnSave.targets"`.
checkOnSave_target | checkOnSave_targets: CheckOnSaveTargets = "[]",
checkOnSave_target | checkOnSave_targets: Option<CheckOnSaveTargets> = "null",

/// Toggles the additional completions that automatically add imports when completed.
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
Expand Down Expand Up @@ -1153,10 +1153,15 @@ impl Config {
}
Some(_) | None => FlycheckConfig::CargoCommand {
command: self.data.checkOnSave_command.clone(),
target_triples: match &self.data.checkOnSave_target.0[..] {
[] => self.data.cargo_target.clone().into_iter().collect(),
targets => targets.into(),
},
target_triples: self
.data
.checkOnSave_target
.clone()
.and_then(|targets| match &targets.0[..] {
[] => None,
targets => Some(targets.into()),
})
.unwrap_or_else(|| self.data.cargo_target.clone().into_iter().collect()),
all_targets: self.data.checkOnSave_allTargets,
no_default_features: self
.data
Expand Down Expand Up @@ -2126,8 +2131,11 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
"The command will be executed in the project root."
],
},
"CheckOnSaveTargets" => set! {
"Option<CheckOnSaveTargets>" => set! {
"anyOf": [
{
"type": "null"
},
{
"type": "string",
},
Expand Down
2 changes: 1 addition & 1 deletion docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ cargo check --workspace --message-format=json --all-targets
```
.
--
[[rust-analyzer.checkOnSave.target]]rust-analyzer.checkOnSave.target (default: `[]`)::
[[rust-analyzer.checkOnSave.target]]rust-analyzer.checkOnSave.target (default: `null`)::
+
--
Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.
Expand Down
5 changes: 4 additions & 1 deletion editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,11 @@
},
"rust-analyzer.checkOnSave.target": {
"markdownDescription": "Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.\n\nCan be a single target, e.g. `\"x86_64-unknown-linux-gnu\"` or a list of targets, e.g.\n`[\"aarch64-apple-darwin\", \"x86_64-apple-darwin\"]`.\n\nAliased as `\"checkOnSave.targets\"`.",
"default": [],
"default": null,
"anyOf": [
{
"type": "null"
},
{
"type": "string"
},
Expand Down

0 comments on commit e9f6087

Please sign in to comment.