Skip to content

Commit ce9bd57

Browse files
committed
Rename checkOnSave settings to check
1 parent 557418e commit ce9bd57

File tree

4 files changed

+274
-281
lines changed

4 files changed

+274
-281
lines changed

crates/rust-analyzer/src/config.rs

+72-79
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,67 @@ config_data! {
124124
/// Unsets `#[cfg(test)]` for the specified crates.
125125
cargo_unsetTest: Vec<String> = "[\"core\"]",
126126

127-
/// Run the flycheck command for diagnostics on save.
127+
/// Run the check command for diagnostics on save.
128128
checkOnSave | checkOnSave_enable: bool = "true",
129129

130+
/// Check all targets and tests (`--all-targets`).
131+
check_allTargets | checkOnSave_allTargets: bool = "true",
132+
/// Cargo command to use for `cargo check`.
133+
check_command | checkOnSave_command: String = "\"check\"",
134+
/// Extra arguments for `cargo check`.
135+
check_extraArgs | checkOnSave_extraArgs: Vec<String> = "[]",
136+
/// Extra environment variables that will be set when running `cargo check`.
137+
/// Extends `#rust-analyzer.cargo.extraEnv#`.
138+
check_extraEnv | checkOnSave_extraEnv: FxHashMap<String, String> = "{}",
139+
/// List of features to activate. Defaults to
140+
/// `#rust-analyzer.cargo.features#`.
141+
///
142+
/// Set to `"all"` to pass `--all-features` to Cargo.
143+
check_features | checkOnSave_features: Option<CargoFeaturesDef> = "null",
144+
/// Specifies the working directory for running checks.
145+
/// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
146+
// FIXME: Ideally we would support this in some way
147+
/// This falls back to "root" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.
148+
/// - "root": run checks in the project's root directory.
149+
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
150+
/// is set.
151+
check_invocationLocation | checkOnSave_invocationLocation: InvocationLocation = "\"workspace\"",
152+
/// Specifies the invocation strategy to use when running the checkOnSave command.
153+
/// If `per_workspace` is set, the command will be executed for each workspace.
154+
/// If `once` is set, the command will be executed once.
155+
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
156+
/// is set.
157+
check_invocationStrategy | checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
158+
/// Whether to pass `--no-default-features` to Cargo. Defaults to
159+
/// `#rust-analyzer.cargo.noDefaultFeatures#`.
160+
check_noDefaultFeatures | checkOnSave_noDefaultFeatures: Option<bool> = "null",
161+
/// Override the command rust-analyzer uses instead of `cargo check` for
162+
/// diagnostics on save. The command is required to output json and
163+
/// should therefore include `--message-format=json` or a similar option.
164+
///
165+
/// If you're changing this because you're using some tool wrapping
166+
/// Cargo, you might also want to change
167+
/// `#rust-analyzer.cargo.buildScripts.overrideCommand#`.
168+
///
169+
/// If there are multiple linked projects, this command is invoked for
170+
/// each of them, with the working directory being the project root
171+
/// (i.e., the folder containing the `Cargo.toml`).
172+
///
173+
/// An example command would be:
174+
///
175+
/// ```bash
176+
/// cargo check --workspace --message-format=json --all-targets
177+
/// ```
178+
/// .
179+
check_overrideCommand | checkOnSave_overrideCommand: Option<Vec<String>> = "null",
180+
/// Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.
181+
///
182+
/// Can be a single target, e.g. `"x86_64-unknown-linux-gnu"` or a list of targets, e.g.
183+
/// `["aarch64-apple-darwin", "x86_64-apple-darwin"]`.
184+
///
185+
/// Aliased as `"checkOnSave.targets"`.
186+
check_targets | checkOnSave_targets | checkOnSave_target: Option<CheckOnSaveTargets> = "null",
187+
130188
/// Toggles the additional completions that automatically add imports when completed.
131189
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
132190
completion_autoimport_enable: bool = "true",
@@ -211,64 +269,6 @@ config_data! {
211269
/// Controls file watching implementation.
212270
files_watcher: FilesWatcherDef = "\"client\"",
213271

214-
/// Check all targets and tests (`--all-targets`).
215-
flycheck_allTargets | checkOnSave_allTargets: bool = "true",
216-
/// Cargo command to use for `cargo check`.
217-
flycheck_command | checkOnSave_command: String = "\"check\"",
218-
/// Extra arguments for `cargo check`.
219-
flycheck_extraArgs | checkOnSave_extraArgs: Vec<String> = "[]",
220-
/// Extra environment variables that will be set when running `cargo check`.
221-
/// Extends `#rust-analyzer.cargo.extraEnv#`.
222-
flycheck_extraEnv | checkOnSave_extraEnv: FxHashMap<String, String> = "{}",
223-
/// List of features to activate. Defaults to
224-
/// `#rust-analyzer.cargo.features#`.
225-
///
226-
/// Set to `"all"` to pass `--all-features` to Cargo.
227-
flycheck_features | checkOnSave_features: Option<CargoFeaturesDef> = "null",
228-
/// Specifies the working directory for running checks.
229-
/// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
230-
// FIXME: Ideally we would support this in some way
231-
/// This falls back to "root" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.
232-
/// - "root": run checks in the project's root directory.
233-
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
234-
/// is set.
235-
flycheck_invocationLocation | checkOnSave_invocationLocation: InvocationLocation = "\"workspace\"",
236-
/// Specifies the invocation strategy to use when running the checkOnSave command.
237-
/// If `per_workspace` is set, the command will be executed for each workspace.
238-
/// If `once` is set, the command will be executed once.
239-
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
240-
/// is set.
241-
flycheck_invocationStrategy | checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
242-
/// Whether to pass `--no-default-features` to Cargo. Defaults to
243-
/// `#rust-analyzer.cargo.noDefaultFeatures#`.
244-
flycheck_noDefaultFeatures | checkOnSave_noDefaultFeatures: Option<bool> = "null",
245-
/// Override the command rust-analyzer uses instead of `cargo check` for
246-
/// diagnostics on save. The command is required to output json and
247-
/// should therefore include `--message-format=json` or a similar option.
248-
///
249-
/// If you're changing this because you're using some tool wrapping
250-
/// Cargo, you might also want to change
251-
/// `#rust-analyzer.cargo.buildScripts.overrideCommand#`.
252-
///
253-
/// If there are multiple linked projects, this command is invoked for
254-
/// each of them, with the working directory being the project root
255-
/// (i.e., the folder containing the `Cargo.toml`).
256-
///
257-
/// An example command would be:
258-
///
259-
/// ```bash
260-
/// cargo check --workspace --message-format=json --all-targets
261-
/// ```
262-
/// .
263-
flycheck_overrideCommand | checkOnSave_overrideCommand: Option<Vec<String>> = "null",
264-
/// Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.
265-
///
266-
/// Can be a single target, e.g. `"x86_64-unknown-linux-gnu"` or a list of targets, e.g.
267-
/// `["aarch64-apple-darwin", "x86_64-apple-darwin"]`.
268-
///
269-
/// Aliased as `"checkOnSave.targets"`.
270-
flycheck_targets | checkOnSave_targets | checkOnSave_target: Option<CheckOnSaveTargets> = "null",
271-
272272
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
273273
highlightRelated_breakPoints_enable: bool = "true",
274274
/// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).
@@ -768,9 +768,9 @@ impl Config {
768768

769769
fn validate(&self, error_sink: &mut Vec<(String, serde_json::Error)>) {
770770
use serde::de::Error;
771-
if self.data.flycheck_command.is_empty() {
771+
if self.data.check_command.is_empty() {
772772
error_sink.push((
773-
"/flycheck/command".to_string(),
773+
"/check/command".to_string(),
774774
serde_json::Error::custom("expected a non-empty string"),
775775
));
776776
}
@@ -1015,7 +1015,7 @@ impl Config {
10151015

10161016
pub fn check_on_save_extra_env(&self) -> FxHashMap<String, String> {
10171017
let mut extra_env = self.data.cargo_extraEnv.clone();
1018-
extra_env.extend(self.data.flycheck_extraEnv.clone());
1018+
extra_env.extend(self.data.check_extraEnv.clone());
10191019
extra_env
10201020
}
10211021

@@ -1127,21 +1127,21 @@ impl Config {
11271127
}
11281128

11291129
pub fn flycheck(&self) -> FlycheckConfig {
1130-
match &self.data.flycheck_overrideCommand {
1130+
match &self.data.check_overrideCommand {
11311131
Some(args) if !args.is_empty() => {
11321132
let mut args = args.clone();
11331133
let command = args.remove(0);
11341134
FlycheckConfig::CustomCommand {
11351135
command,
11361136
args,
11371137
extra_env: self.check_on_save_extra_env(),
1138-
invocation_strategy: match self.data.flycheck_invocationStrategy {
1138+
invocation_strategy: match self.data.check_invocationStrategy {
11391139
InvocationStrategy::Once => flycheck::InvocationStrategy::Once,
11401140
InvocationStrategy::PerWorkspace => {
11411141
flycheck::InvocationStrategy::PerWorkspace
11421142
}
11431143
},
1144-
invocation_location: match self.data.flycheck_invocationLocation {
1144+
invocation_location: match self.data.check_invocationLocation {
11451145
InvocationLocation::Root => {
11461146
flycheck::InvocationLocation::Root(self.root_path.clone())
11471147
}
@@ -1150,35 +1150,35 @@ impl Config {
11501150
}
11511151
}
11521152
Some(_) | None => FlycheckConfig::CargoCommand {
1153-
command: self.data.flycheck_command.clone(),
1153+
command: self.data.check_command.clone(),
11541154
target_triples: self
11551155
.data
1156-
.flycheck_targets
1156+
.check_targets
11571157
.clone()
11581158
.and_then(|targets| match &targets.0[..] {
11591159
[] => None,
11601160
targets => Some(targets.into()),
11611161
})
11621162
.unwrap_or_else(|| self.data.cargo_target.clone().into_iter().collect()),
1163-
all_targets: self.data.flycheck_allTargets,
1163+
all_targets: self.data.check_allTargets,
11641164
no_default_features: self
11651165
.data
1166-
.flycheck_noDefaultFeatures
1166+
.check_noDefaultFeatures
11671167
.unwrap_or(self.data.cargo_noDefaultFeatures),
11681168
all_features: matches!(
1169-
self.data.flycheck_features.as_ref().unwrap_or(&self.data.cargo_features),
1169+
self.data.check_features.as_ref().unwrap_or(&self.data.cargo_features),
11701170
CargoFeaturesDef::All
11711171
),
11721172
features: match self
11731173
.data
1174-
.flycheck_features
1174+
.check_features
11751175
.clone()
11761176
.unwrap_or_else(|| self.data.cargo_features.clone())
11771177
{
11781178
CargoFeaturesDef::All => vec![],
11791179
CargoFeaturesDef::Selected(it) => it,
11801180
},
1181-
extra_args: self.data.flycheck_extraArgs.clone(),
1181+
extra_args: self.data.check_extraArgs.clone(),
11821182
extra_env: self.check_on_save_extra_env(),
11831183
},
11841184
}
@@ -1847,13 +1847,6 @@ fn get_field<T: DeserializeOwned>(
18471847
}
18481848

18491849
fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value {
1850-
for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
1851-
fn key(f: &str) -> &str {
1852-
f.splitn(2, '_').next().unwrap()
1853-
}
1854-
assert!(key(f1) <= key(f2), "wrong field order: {:?} {:?}", f1, f2);
1855-
}
1856-
18571850
let map = fields
18581851
.iter()
18591852
.map(|(field, ty, doc, default)| {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
108108
merge(json, json!({ "cargo": { "features": "all" } }));
109109
}
110110

111-
// checkOnSave_allFeatures, checkOnSave_features -> flycheck_features
111+
// checkOnSave_allFeatures, checkOnSave_features -> check_features
112112
if let Some(Value::Bool(true)) = copy.pointer("/checkOnSave/allFeatures") {
113-
merge(json, json!({ "flycheck": { "features": "all" } }));
113+
merge(json, json!({ "check": { "features": "all" } }));
114114
}
115115

116116
// completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets
@@ -126,13 +126,13 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
126126
merge(json, json!({ "completion": { "callable": {"snippets": res }} }));
127127

128128
// 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_* -> flycheck_*
129+
// checkOnSave_* -> check_*
130130
if let Some(Value::Object(obj)) = copy.pointer("/checkOnSave") {
131131
// checkOnSave_enable -> checkOnSave
132132
if let Some(b @ Value::Bool(_)) = obj.get("enable") {
133133
merge(json, json!({ "checkOnSave": b }));
134134
}
135-
merge(json, json!({ "flycheck": obj }));
135+
merge(json, json!({ "check": obj }));
136136
}
137137
}
138138

0 commit comments

Comments
 (0)