@@ -124,39 +124,40 @@ config_data! {
124
124
/// Unsets `#[cfg(test)]` for the specified crates.
125
125
cargo_unsetTest: Vec <String > = "[\" core\" ]" ,
126
126
127
+ /// Run the check command for diagnostics on save.
128
+ checkOnSave | checkOnSave_enable: bool = "true" ,
129
+
127
130
/// Check all targets and tests (`--all-targets`).
128
- checkOnSave_allTargets: bool = "true" ,
131
+ check_allTargets | checkOnSave_allTargets: bool = "true" ,
129
132
/// 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\" " ,
133
134
/// Extra arguments for `cargo check`.
134
- checkOnSave_extraArgs: Vec <String > = "[]" ,
135
+ check_extraArgs | checkOnSave_extraArgs: Vec <String > = "[]" ,
135
136
/// Extra environment variables that will be set when running `cargo check`.
136
137
/// Extends `#rust-analyzer.cargo.extraEnv#`.
137
- checkOnSave_extraEnv: FxHashMap <String , String > = "{}" ,
138
+ check_extraEnv | checkOnSave_extraEnv: FxHashMap <String , String > = "{}" ,
138
139
/// List of features to activate. Defaults to
139
140
/// `#rust-analyzer.cargo.features#`.
140
141
///
141
142
/// Set to `"all"` to pass `--all-features` to Cargo.
142
- checkOnSave_features: Option <CargoFeaturesDef > = "null" ,
143
+ check_features | checkOnSave_features: Option <CargoFeaturesDef > = "null" ,
143
144
/// Specifies the working directory for running checks.
144
145
/// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
145
146
// FIXME: Ideally we would support this in some way
146
147
/// This falls back to "root" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.
147
148
/// - "root": run checks in the project's root directory.
148
149
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
149
150
/// is set.
150
- checkOnSave_invocationLocation: InvocationLocation = "\" workspace\" " ,
151
+ check_invocationLocation | checkOnSave_invocationLocation: InvocationLocation = "\" workspace\" " ,
151
152
/// Specifies the invocation strategy to use when running the checkOnSave command.
152
153
/// If `per_workspace` is set, the command will be executed for each workspace.
153
154
/// If `once` is set, the command will be executed once.
154
155
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
155
156
/// is set.
156
- checkOnSave_invocationStrategy: InvocationStrategy = "\" per_workspace\" " ,
157
+ check_invocationStrategy | checkOnSave_invocationStrategy: InvocationStrategy = "\" per_workspace\" " ,
157
158
/// Whether to pass `--no-default-features` to Cargo. Defaults to
158
159
/// `#rust-analyzer.cargo.noDefaultFeatures#`.
159
- checkOnSave_noDefaultFeatures: Option <bool > = "null" ,
160
+ check_noDefaultFeatures | checkOnSave_noDefaultFeatures: Option <bool > = "null" ,
160
161
/// Override the command rust-analyzer uses instead of `cargo check` for
161
162
/// diagnostics on save. The command is required to output json and
162
163
/// should therefore include `--message-format=json` or a similar option.
@@ -175,14 +176,14 @@ config_data! {
175
176
/// cargo check --workspace --message-format=json --all-targets
176
177
/// ```
177
178
/// .
178
- checkOnSave_overrideCommand: Option <Vec <String >> = "null" ,
179
+ check_overrideCommand | checkOnSave_overrideCommand: Option <Vec <String >> = "null" ,
179
180
/// Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.
180
181
///
181
182
/// Can be a single target, e.g. `"x86_64-unknown-linux-gnu"` or a list of targets, e.g.
182
183
/// `["aarch64-apple-darwin", "x86_64-apple-darwin"]`.
183
184
///
184
185
/// Aliased as `"checkOnSave.targets"`.
185
- checkOnSave_target | checkOnSave_targets: Option <CheckOnSaveTargets > = "null" ,
186
+ check_targets | checkOnSave_targets | checkOnSave_target : Option <CheckOnSaveTargets > = "null" ,
186
187
187
188
/// Toggles the additional completions that automatically add imports when completed.
188
189
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -791,9 +792,9 @@ impl Config {
791
792
792
793
fn validate ( & self , error_sink : & mut Vec < ( String , serde_json:: Error ) > ) {
793
794
use serde:: de:: Error ;
794
- if self . data . checkOnSave_command . is_empty ( ) {
795
+ if self . data . check_command . is_empty ( ) {
795
796
error_sink. push ( (
796
- "/checkOnSave /command" . to_string ( ) ,
797
+ "/check /command" . to_string ( ) ,
797
798
serde_json:: Error :: custom ( "expected a non-empty string" ) ,
798
799
) ) ;
799
800
}
@@ -1038,7 +1039,7 @@ impl Config {
1038
1039
1039
1040
pub fn check_on_save_extra_env ( & self ) -> FxHashMap < String , String > {
1040
1041
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 ( ) ) ;
1042
1043
extra_env
1043
1044
}
1044
1045
@@ -1150,21 +1151,21 @@ impl Config {
1150
1151
}
1151
1152
1152
1153
pub fn flycheck ( & self ) -> FlycheckConfig {
1153
- match & self . data . checkOnSave_overrideCommand {
1154
+ match & self . data . check_overrideCommand {
1154
1155
Some ( args) if !args. is_empty ( ) => {
1155
1156
let mut args = args. clone ( ) ;
1156
1157
let command = args. remove ( 0 ) ;
1157
1158
FlycheckConfig :: CustomCommand {
1158
1159
command,
1159
1160
args,
1160
1161
extra_env : self . check_on_save_extra_env ( ) ,
1161
- invocation_strategy : match self . data . checkOnSave_invocationStrategy {
1162
+ invocation_strategy : match self . data . check_invocationStrategy {
1162
1163
InvocationStrategy :: Once => flycheck:: InvocationStrategy :: Once ,
1163
1164
InvocationStrategy :: PerWorkspace => {
1164
1165
flycheck:: InvocationStrategy :: PerWorkspace
1165
1166
}
1166
1167
} ,
1167
- invocation_location : match self . data . checkOnSave_invocationLocation {
1168
+ invocation_location : match self . data . check_invocationLocation {
1168
1169
InvocationLocation :: Root => {
1169
1170
flycheck:: InvocationLocation :: Root ( self . root_path . clone ( ) )
1170
1171
}
@@ -1173,42 +1174,42 @@ impl Config {
1173
1174
}
1174
1175
}
1175
1176
Some ( _) | None => FlycheckConfig :: CargoCommand {
1176
- command : self . data . checkOnSave_command . clone ( ) ,
1177
+ command : self . data . check_command . clone ( ) ,
1177
1178
target_triples : self
1178
1179
. data
1179
- . checkOnSave_target
1180
+ . check_targets
1180
1181
. clone ( )
1181
1182
. and_then ( |targets| match & targets. 0 [ ..] {
1182
1183
[ ] => None ,
1183
1184
targets => Some ( targets. into ( ) ) ,
1184
1185
} )
1185
1186
. 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 ,
1187
1188
no_default_features : self
1188
1189
. data
1189
- . checkOnSave_noDefaultFeatures
1190
+ . check_noDefaultFeatures
1190
1191
. unwrap_or ( self . data . cargo_noDefaultFeatures ) ,
1191
1192
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) ,
1193
1194
CargoFeaturesDef :: All
1194
1195
) ,
1195
1196
features : match self
1196
1197
. data
1197
- . checkOnSave_features
1198
+ . check_features
1198
1199
. clone ( )
1199
1200
. unwrap_or_else ( || self . data . cargo_features . clone ( ) )
1200
1201
{
1201
1202
CargoFeaturesDef :: All => vec ! [ ] ,
1202
1203
CargoFeaturesDef :: Selected ( it) => it,
1203
1204
} ,
1204
- extra_args : self . data . checkOnSave_extraArgs . clone ( ) ,
1205
+ extra_args : self . data . check_extraArgs . clone ( ) ,
1205
1206
extra_env : self . check_on_save_extra_env ( ) ,
1206
1207
} ,
1207
1208
}
1208
1209
}
1209
1210
1210
1211
pub fn check_on_save ( & self ) -> bool {
1211
- self . data . checkOnSave_enable
1212
+ self . data . checkOnSave
1212
1213
}
1213
1214
1214
1215
pub fn runnables ( & self ) -> RunnablesConfig {
@@ -1886,35 +1887,30 @@ fn get_field<T: DeserializeOwned>(
1886
1887
alias : Option < & ' static str > ,
1887
1888
default : & str ,
1888
1889
) -> T {
1889
- let default = serde_json:: from_str ( default) . unwrap ( ) ;
1890
1890
// XXX: check alias first, to work-around the VS Code where it pre-fills the
1891
1891
// defaults instead of sending an empty object.
1892
1892
alias
1893
1893
. into_iter ( )
1894
1894
. chain ( iter:: once ( field) )
1895
- . find_map ( move |field| {
1895
+ . filter_map ( move |field| {
1896
1896
let mut pointer = field. replace ( '_' , "/" ) ;
1897
1897
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
+ }
1906
1909
} )
1907
- . unwrap_or ( default)
1910
+ . unwrap_or_else ( || serde_json :: from_str ( default) . unwrap ( ) )
1908
1911
}
1909
1912
1910
1913
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
-
1918
1914
let map = fields
1919
1915
. iter ( )
1920
1916
. map ( |( field, ty, doc, default) | {
@@ -1988,15 +1984,6 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
1988
1984
"type" : [ "null" , "array" ] ,
1989
1985
"items" : { "type" : "string" } ,
1990
1986
} ,
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
- } ,
2000
1987
"ExprFillDefaultDef" => set ! {
2001
1988
"type" : "string" ,
2002
1989
"enum" : [ "todo" , "default" ] ,
0 commit comments