From b116fe9be0812ce3052d7c96359e87cfe7aca558 Mon Sep 17 00:00:00 2001 From: Isobel Redelmeier Date: Mon, 21 Nov 2022 16:40:32 -0500 Subject: [PATCH] Fix: Handle empty `checkOnSave/target` values This fixes a regression introduced by #13290, in which failing to set `checkOnSave/target` (or `checkOnSave/targets`) would lead to an invalid config. --- crates/rust-analyzer/src/config.rs | 20 ++++++++++++++------ docs/user/generated_config.adoc | 2 +- editors/code/package.json | 5 ++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 6b2f22faa7178..6c0d712a4f473 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -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 = "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. @@ -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 @@ -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" => set! { "anyOf": [ + { + "type": "null" + }, { "type": "string", }, diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 57f950034cbb7..db41c7bf109e2 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -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. diff --git a/editors/code/package.json b/editors/code/package.json index c4d4e428ea07d..a3385a3868b6d 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -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" },