Skip to content

Commit fd300ee

Browse files
committed
Auto merge of #13799 - Veykril:flycheck, r=Veykril
Rename `checkOnSave` settings to `check` Now that flychecks can be triggered without saving the setting name doesn't make that much sense anymore. This PR renames it to just `check`, but keeps `checkOnSave` as the enabling setting.
2 parents f920b03 + d2bb62b commit fd300ee

File tree

4 files changed

+84
-84
lines changed

4 files changed

+84
-84
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -124,39 +124,40 @@ config_data! {
124124
/// Unsets `#[cfg(test)]` for the specified crates.
125125
cargo_unsetTest: Vec<String> = "[\"core\"]",
126126

127+
/// Run the check command for diagnostics on save.
128+
checkOnSave | checkOnSave_enable: bool = "true",
129+
127130
/// Check all targets and tests (`--all-targets`).
128-
checkOnSave_allTargets: bool = "true",
131+
check_allTargets | checkOnSave_allTargets: bool = "true",
129132
/// Cargo command to use for `cargo check`.
130-
checkOnSave_command: String = "\"check\"",
131-
/// Run specified `cargo check` command for diagnostics on save.
132-
checkOnSave_enable: bool = "true",
133+
check_command | checkOnSave_command: String = "\"check\"",
133134
/// Extra arguments for `cargo check`.
134-
checkOnSave_extraArgs: Vec<String> = "[]",
135+
check_extraArgs | checkOnSave_extraArgs: Vec<String> = "[]",
135136
/// Extra environment variables that will be set when running `cargo check`.
136137
/// Extends `#rust-analyzer.cargo.extraEnv#`.
137-
checkOnSave_extraEnv: FxHashMap<String, String> = "{}",
138+
check_extraEnv | checkOnSave_extraEnv: FxHashMap<String, String> = "{}",
138139
/// List of features to activate. Defaults to
139140
/// `#rust-analyzer.cargo.features#`.
140141
///
141142
/// Set to `"all"` to pass `--all-features` to Cargo.
142-
checkOnSave_features: Option<CargoFeaturesDef> = "null",
143+
check_features | checkOnSave_features: Option<CargoFeaturesDef> = "null",
143144
/// Specifies the working directory for running checks.
144145
/// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
145146
// FIXME: Ideally we would support this in some way
146147
/// This falls back to "root" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.
147148
/// - "root": run checks in the project's root directory.
148149
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
149150
/// is set.
150-
checkOnSave_invocationLocation: InvocationLocation = "\"workspace\"",
151+
check_invocationLocation | checkOnSave_invocationLocation: InvocationLocation = "\"workspace\"",
151152
/// Specifies the invocation strategy to use when running the checkOnSave command.
152153
/// If `per_workspace` is set, the command will be executed for each workspace.
153154
/// If `once` is set, the command will be executed once.
154155
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
155156
/// is set.
156-
checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
157+
check_invocationStrategy | checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
157158
/// Whether to pass `--no-default-features` to Cargo. Defaults to
158159
/// `#rust-analyzer.cargo.noDefaultFeatures#`.
159-
checkOnSave_noDefaultFeatures: Option<bool> = "null",
160+
check_noDefaultFeatures | checkOnSave_noDefaultFeatures: Option<bool> = "null",
160161
/// Override the command rust-analyzer uses instead of `cargo check` for
161162
/// diagnostics on save. The command is required to output json and
162163
/// should therefore include `--message-format=json` or a similar option.
@@ -175,14 +176,14 @@ config_data! {
175176
/// cargo check --workspace --message-format=json --all-targets
176177
/// ```
177178
/// .
178-
checkOnSave_overrideCommand: Option<Vec<String>> = "null",
179+
check_overrideCommand | checkOnSave_overrideCommand: Option<Vec<String>> = "null",
179180
/// Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.
180181
///
181182
/// Can be a single target, e.g. `"x86_64-unknown-linux-gnu"` or a list of targets, e.g.
182183
/// `["aarch64-apple-darwin", "x86_64-apple-darwin"]`.
183184
///
184185
/// Aliased as `"checkOnSave.targets"`.
185-
checkOnSave_target | checkOnSave_targets: Option<CheckOnSaveTargets> = "null",
186+
check_targets | checkOnSave_targets | checkOnSave_target: Option<CheckOnSaveTargets> = "null",
186187

187188
/// Toggles the additional completions that automatically add imports when completed.
188189
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -791,9 +792,9 @@ impl Config {
791792

792793
fn validate(&self, error_sink: &mut Vec<(String, serde_json::Error)>) {
793794
use serde::de::Error;
794-
if self.data.checkOnSave_command.is_empty() {
795+
if self.data.check_command.is_empty() {
795796
error_sink.push((
796-
"/checkOnSave/command".to_string(),
797+
"/check/command".to_string(),
797798
serde_json::Error::custom("expected a non-empty string"),
798799
));
799800
}
@@ -1038,7 +1039,7 @@ impl Config {
10381039

10391040
pub fn check_on_save_extra_env(&self) -> FxHashMap<String, String> {
10401041
let mut extra_env = self.data.cargo_extraEnv.clone();
1041-
extra_env.extend(self.data.checkOnSave_extraEnv.clone());
1042+
extra_env.extend(self.data.check_extraEnv.clone());
10421043
extra_env
10431044
}
10441045

@@ -1150,21 +1151,21 @@ impl Config {
11501151
}
11511152

11521153
pub fn flycheck(&self) -> FlycheckConfig {
1153-
match &self.data.checkOnSave_overrideCommand {
1154+
match &self.data.check_overrideCommand {
11541155
Some(args) if !args.is_empty() => {
11551156
let mut args = args.clone();
11561157
let command = args.remove(0);
11571158
FlycheckConfig::CustomCommand {
11581159
command,
11591160
args,
11601161
extra_env: self.check_on_save_extra_env(),
1161-
invocation_strategy: match self.data.checkOnSave_invocationStrategy {
1162+
invocation_strategy: match self.data.check_invocationStrategy {
11621163
InvocationStrategy::Once => flycheck::InvocationStrategy::Once,
11631164
InvocationStrategy::PerWorkspace => {
11641165
flycheck::InvocationStrategy::PerWorkspace
11651166
}
11661167
},
1167-
invocation_location: match self.data.checkOnSave_invocationLocation {
1168+
invocation_location: match self.data.check_invocationLocation {
11681169
InvocationLocation::Root => {
11691170
flycheck::InvocationLocation::Root(self.root_path.clone())
11701171
}
@@ -1173,42 +1174,42 @@ impl Config {
11731174
}
11741175
}
11751176
Some(_) | None => FlycheckConfig::CargoCommand {
1176-
command: self.data.checkOnSave_command.clone(),
1177+
command: self.data.check_command.clone(),
11771178
target_triples: self
11781179
.data
1179-
.checkOnSave_target
1180+
.check_targets
11801181
.clone()
11811182
.and_then(|targets| match &targets.0[..] {
11821183
[] => None,
11831184
targets => Some(targets.into()),
11841185
})
11851186
.unwrap_or_else(|| self.data.cargo_target.clone().into_iter().collect()),
1186-
all_targets: self.data.checkOnSave_allTargets,
1187+
all_targets: self.data.check_allTargets,
11871188
no_default_features: self
11881189
.data
1189-
.checkOnSave_noDefaultFeatures
1190+
.check_noDefaultFeatures
11901191
.unwrap_or(self.data.cargo_noDefaultFeatures),
11911192
all_features: matches!(
1192-
self.data.checkOnSave_features.as_ref().unwrap_or(&self.data.cargo_features),
1193+
self.data.check_features.as_ref().unwrap_or(&self.data.cargo_features),
11931194
CargoFeaturesDef::All
11941195
),
11951196
features: match self
11961197
.data
1197-
.checkOnSave_features
1198+
.check_features
11981199
.clone()
11991200
.unwrap_or_else(|| self.data.cargo_features.clone())
12001201
{
12011202
CargoFeaturesDef::All => vec![],
12021203
CargoFeaturesDef::Selected(it) => it,
12031204
},
1204-
extra_args: self.data.checkOnSave_extraArgs.clone(),
1205+
extra_args: self.data.check_extraArgs.clone(),
12051206
extra_env: self.check_on_save_extra_env(),
12061207
},
12071208
}
12081209
}
12091210

12101211
pub fn check_on_save(&self) -> bool {
1211-
self.data.checkOnSave_enable
1212+
self.data.checkOnSave
12121213
}
12131214

12141215
pub fn runnables(&self) -> RunnablesConfig {
@@ -1886,35 +1887,30 @@ fn get_field<T: DeserializeOwned>(
18861887
alias: Option<&'static str>,
18871888
default: &str,
18881889
) -> T {
1889-
let default = serde_json::from_str(default).unwrap();
18901890
// XXX: check alias first, to work-around the VS Code where it pre-fills the
18911891
// defaults instead of sending an empty object.
18921892
alias
18931893
.into_iter()
18941894
.chain(iter::once(field))
1895-
.find_map(move |field| {
1895+
.filter_map(move |field| {
18961896
let mut pointer = field.replace('_', "/");
18971897
pointer.insert(0, '/');
1898-
json.pointer_mut(&pointer).and_then(|it| match serde_json::from_value(it.take()) {
1899-
Ok(it) => Some(it),
1900-
Err(e) => {
1901-
tracing::warn!("Failed to deserialize config field at {}: {:?}", pointer, e);
1902-
error_sink.push((pointer, e));
1903-
None
1904-
}
1905-
})
1898+
json.pointer_mut(&pointer)
1899+
.map(|it| serde_json::from_value(it.take()).map_err(|e| (e, pointer)))
1900+
})
1901+
.find(Result::is_ok)
1902+
.and_then(|res| match res {
1903+
Ok(it) => Some(it),
1904+
Err((e, pointer)) => {
1905+
tracing::warn!("Failed to deserialize config field at {}: {:?}", pointer, e);
1906+
error_sink.push((pointer, e));
1907+
None
1908+
}
19061909
})
1907-
.unwrap_or(default)
1910+
.unwrap_or_else(|| serde_json::from_str(default).unwrap())
19081911
}
19091912

19101913
fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value {
1911-
for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
1912-
fn key(f: &str) -> &str {
1913-
f.splitn(2, '_').next().unwrap()
1914-
}
1915-
assert!(key(f1) <= key(f2), "wrong field order: {f1:?} {f2:?}");
1916-
}
1917-
19181914
let map = fields
19191915
.iter()
19201916
.map(|(field, ty, doc, default)| {
@@ -1988,15 +1984,6 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
19881984
"type": ["null", "array"],
19891985
"items": { "type": "string" },
19901986
},
1991-
"MergeBehaviorDef" => set! {
1992-
"type": "string",
1993-
"enum": ["none", "crate", "module"],
1994-
"enumDescriptions": [
1995-
"Do not merge imports at all.",
1996-
"Merge imports from the same crate into a single `use` statement.",
1997-
"Merge imports from the same module into a single `use` statement."
1998-
],
1999-
},
20001987
"ExprFillDefaultDef" => set! {
20011988
"type": "string",
20021989
"enum": ["todo", "default"],

crates/rust-analyzer/src/config/patch_old_style.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use serde_json::{json, Value};
44
/// This function patches the json config to the new expected keys.
55
/// That is we try to load old known config keys here and convert them to the new ones.
66
/// See https://github.com/rust-lang/rust-analyzer/pull/12010
7+
///
8+
/// We already have an alias system for simple cases, but if we make structural changes
9+
/// the alias infra fails down.
710
pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
811
let copy = json.clone();
912

@@ -105,9 +108,9 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
105108
merge(json, json!({ "cargo": { "features": "all" } }));
106109
}
107110

108-
// checkOnSave_allFeatures, checkOnSave_features -> checkOnSave_features
111+
// checkOnSave_allFeatures, checkOnSave_features -> check_features
109112
if let Some(Value::Bool(true)) = copy.pointer("/checkOnSave/allFeatures") {
110-
merge(json, json!({ "checkOnSave": { "features": "all" } }));
113+
merge(json, json!({ "check": { "features": "all" } }));
111114
}
112115

113116
// completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets
@@ -121,6 +124,16 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
121124
(_, _) => return,
122125
};
123126
merge(json, json!({ "completion": { "callable": {"snippets": res }} }));
127+
128+
// We need to do this due to the checkOnSave_enable -> checkOnSave change, as that key now can either be an object or a bool
129+
// checkOnSave_* -> check_*
130+
if let Some(Value::Object(obj)) = copy.pointer("/checkOnSave") {
131+
// checkOnSave_enable -> checkOnSave
132+
if let Some(b @ Value::Bool(_)) = obj.get("enable") {
133+
merge(json, json!({ "checkOnSave": b }));
134+
}
135+
merge(json, json!({ "check": obj }));
136+
}
124137
}
125138

126139
fn merge(dst: &mut Value, src: Value) {

docs/user/generated_config.adoc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,41 +109,41 @@ Compilation target override (target triple).
109109
--
110110
Unsets `#[cfg(test)]` for the specified crates.
111111
--
112-
[[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`)::
112+
[[rust-analyzer.checkOnSave]]rust-analyzer.checkOnSave (default: `true`)::
113113
+
114114
--
115-
Check all targets and tests (`--all-targets`).
115+
Run the check command for diagnostics on save.
116116
--
117-
[[rust-analyzer.checkOnSave.command]]rust-analyzer.checkOnSave.command (default: `"check"`)::
117+
[[rust-analyzer.check.allTargets]]rust-analyzer.check.allTargets (default: `true`)::
118118
+
119119
--
120-
Cargo command to use for `cargo check`.
120+
Check all targets and tests (`--all-targets`).
121121
--
122-
[[rust-analyzer.checkOnSave.enable]]rust-analyzer.checkOnSave.enable (default: `true`)::
122+
[[rust-analyzer.check.command]]rust-analyzer.check.command (default: `"check"`)::
123123
+
124124
--
125-
Run specified `cargo check` command for diagnostics on save.
125+
Cargo command to use for `cargo check`.
126126
--
127-
[[rust-analyzer.checkOnSave.extraArgs]]rust-analyzer.checkOnSave.extraArgs (default: `[]`)::
127+
[[rust-analyzer.check.extraArgs]]rust-analyzer.check.extraArgs (default: `[]`)::
128128
+
129129
--
130130
Extra arguments for `cargo check`.
131131
--
132-
[[rust-analyzer.checkOnSave.extraEnv]]rust-analyzer.checkOnSave.extraEnv (default: `{}`)::
132+
[[rust-analyzer.check.extraEnv]]rust-analyzer.check.extraEnv (default: `{}`)::
133133
+
134134
--
135135
Extra environment variables that will be set when running `cargo check`.
136136
Extends `#rust-analyzer.cargo.extraEnv#`.
137137
--
138-
[[rust-analyzer.checkOnSave.features]]rust-analyzer.checkOnSave.features (default: `null`)::
138+
[[rust-analyzer.check.features]]rust-analyzer.check.features (default: `null`)::
139139
+
140140
--
141141
List of features to activate. Defaults to
142142
`#rust-analyzer.cargo.features#`.
143143

144144
Set to `"all"` to pass `--all-features` to Cargo.
145145
--
146-
[[rust-analyzer.checkOnSave.invocationLocation]]rust-analyzer.checkOnSave.invocationLocation (default: `"workspace"`)::
146+
[[rust-analyzer.check.invocationLocation]]rust-analyzer.check.invocationLocation (default: `"workspace"`)::
147147
+
148148
--
149149
Specifies the working directory for running checks.
@@ -153,7 +153,7 @@ Specifies the working directory for running checks.
153153
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
154154
is set.
155155
--
156-
[[rust-analyzer.checkOnSave.invocationStrategy]]rust-analyzer.checkOnSave.invocationStrategy (default: `"per_workspace"`)::
156+
[[rust-analyzer.check.invocationStrategy]]rust-analyzer.check.invocationStrategy (default: `"per_workspace"`)::
157157
+
158158
--
159159
Specifies the invocation strategy to use when running the checkOnSave command.
@@ -162,13 +162,13 @@ If `once` is set, the command will be executed once.
162162
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
163163
is set.
164164
--
165-
[[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`)::
165+
[[rust-analyzer.check.noDefaultFeatures]]rust-analyzer.check.noDefaultFeatures (default: `null`)::
166166
+
167167
--
168168
Whether to pass `--no-default-features` to Cargo. Defaults to
169169
`#rust-analyzer.cargo.noDefaultFeatures#`.
170170
--
171-
[[rust-analyzer.checkOnSave.overrideCommand]]rust-analyzer.checkOnSave.overrideCommand (default: `null`)::
171+
[[rust-analyzer.check.overrideCommand]]rust-analyzer.check.overrideCommand (default: `null`)::
172172
+
173173
--
174174
Override the command rust-analyzer uses instead of `cargo check` for
@@ -190,7 +190,7 @@ cargo check --workspace --message-format=json --all-targets
190190
```
191191
.
192192
--
193-
[[rust-analyzer.checkOnSave.target]]rust-analyzer.checkOnSave.target (default: `null`)::
193+
[[rust-analyzer.check.targets]]rust-analyzer.check.targets (default: `null`)::
194194
+
195195
--
196196
Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.

0 commit comments

Comments
 (0)