Skip to content

Fix: Handle empty checkOnSave/target values #13661

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

Merged
merged 1 commit into from
Nov 24, 2022
Merged
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
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