@@ -39,10 +39,7 @@ use crate::{
39
39
// - Toggles (be it binary true/false or with more options in-between) should almost always suffix as `_enable`
40
40
// - In general be wary of using the namespace of something verbatim, it prevents us from adding subkeys in the future
41
41
// - Don't use abbreviations unless really necessary
42
- // - foo_command = overrides the subcommand, foo_overrideCommand allows full overwriting
43
- // - We could in theory only use `command` and have it change behavior depending on whether its a string or array?
44
- // - TODO: conventions regarding config keys for commands and their args
45
- // - TODO: conventions regarding config polarity
42
+ // - foo_command = overrides the subcommand, foo_overrideCommand allows full overwriting, extra args only applies for foo_command
46
43
47
44
// Defines the server-side configuration of the rust-analyzer. We generate
48
45
// *parts* of VS Code's `package.json` config from this.
@@ -108,7 +105,7 @@ config_data! {
108
105
/// with `self` prefixed to them when inside a method.
109
106
completion_autoself_enable: bool = "true" ,
110
107
/// Whether to add parenthesis and argument snippets when completing function.
111
- completion_callable_snippets: CallableCompletionDef = "fillArguments " ,
108
+ completion_callable_snippets: Option < CallableCompletionDef > = "\" fill_arguments \" " ,
112
109
/// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
113
110
completion_postfix_enable: bool = "true" ,
114
111
/// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
@@ -217,13 +214,11 @@ config_data! {
217
214
/// Use markdown syntax for links in hover.
218
215
hover_links_enable: bool = "true" ,
219
216
220
- // TODO: this should be in granulatiry?
221
217
/// Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file.
222
218
imports_enforceGranularity: bool = "false" ,
223
219
/// How imports should be grouped into use statements.
224
220
imports_granularity: ImportGranularityDef = "\" crate\" " ,
225
221
/// Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import[following order]. Groups are separated by newlines.
226
- // TODO: Shouldn't be a bool
227
222
imports_group: bool = "true" ,
228
223
/// Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`.
229
224
imports_mergeIntoGlob: bool = "true" ,
@@ -353,7 +348,6 @@ config_data! {
353
348
354
349
/// Show documentation.
355
350
signatureInfo_documentation_enable: bool = "true" ,
356
- // TODO: needs a better name
357
351
/// Show full signature of the callable. Only shows parameters if disabled.
358
352
signatureInfo_signature_enable: bool = "true" ,
359
353
@@ -1002,11 +996,11 @@ impl Config {
1002
996
enable_private_editable : self . data . completion_privateEditable_enable ,
1003
997
add_call_parenthesis : matches ! (
1004
998
self . data. completion_callable_snippets,
1005
- CallableCompletionDef :: AddParentheses
999
+ Some ( CallableCompletionDef :: AddParentheses )
1006
1000
) ,
1007
1001
add_call_argument_snippets : matches ! (
1008
1002
self . data. completion_callable_snippets,
1009
- CallableCompletionDef :: FillArguments
1003
+ Some ( CallableCompletionDef :: FillArguments )
1010
1004
) ,
1011
1005
insert_use : self . insert_use_config ( ) ,
1012
1006
snippet_cap : SnippetCap :: new ( try_or_def ! (
@@ -1170,9 +1164,76 @@ impl Config {
1170
1164
}
1171
1165
}
1172
1166
}
1173
-
1174
1167
// Deserialization definitions
1175
1168
1169
+ macro_rules! create_bool_or_string_de {
1170
+ ( $ident: ident<$bool: literal, $string: literal>) => {
1171
+ fn $ident<' de, D >( d: D ) -> Result <( ) , D :: Error >
1172
+ where
1173
+ D : serde:: Deserializer <' de>,
1174
+ {
1175
+ struct V ;
1176
+ impl <' de> serde:: de:: Visitor <' de> for V {
1177
+ type Value = ( ) ;
1178
+
1179
+ fn expecting( & self , formatter: & mut fmt:: Formatter ) -> fmt:: Result {
1180
+ formatter. write_str( concat!(
1181
+ stringify!( $bool) ,
1182
+ " or \" " ,
1183
+ stringify!( $string) ,
1184
+ "\" "
1185
+ ) )
1186
+ }
1187
+
1188
+ fn visit_bool<E >( self , v: bool ) -> Result <Self :: Value , E >
1189
+ where
1190
+ E : serde:: de:: Error ,
1191
+ {
1192
+ match v {
1193
+ $bool => Ok ( ( ) ) ,
1194
+ _ => Err ( serde:: de:: Error :: invalid_value(
1195
+ serde:: de:: Unexpected :: Bool ( v) ,
1196
+ & self ,
1197
+ ) ) ,
1198
+ }
1199
+ }
1200
+
1201
+ fn visit_str<E >( self , v: & str ) -> Result <Self :: Value , E >
1202
+ where
1203
+ E : serde:: de:: Error ,
1204
+ {
1205
+ match v {
1206
+ $string => Ok ( ( ) ) ,
1207
+ _ => Err ( serde:: de:: Error :: invalid_value(
1208
+ serde:: de:: Unexpected :: Str ( v) ,
1209
+ & self ,
1210
+ ) ) ,
1211
+ }
1212
+ }
1213
+
1214
+ fn visit_enum<A >( self , a: A ) -> Result <Self :: Value , A :: Error >
1215
+ where
1216
+ A : serde:: de:: EnumAccess <' de>,
1217
+ {
1218
+ use serde:: de:: VariantAccess ;
1219
+ let ( variant, va) = a. variant:: <& ' de str >( ) ?;
1220
+ va. unit_variant( ) ?;
1221
+ match variant {
1222
+ $string => Ok ( ( ) ) ,
1223
+ _ => Err ( serde:: de:: Error :: invalid_value(
1224
+ serde:: de:: Unexpected :: Str ( variant) ,
1225
+ & self ,
1226
+ ) ) ,
1227
+ }
1228
+ }
1229
+ }
1230
+ d. deserialize_any( V )
1231
+ }
1232
+ } ;
1233
+ }
1234
+ create_bool_or_string_de ! ( true_or_always<true , "always" >) ;
1235
+ create_bool_or_string_de ! ( false_or_never<false , "never" >) ;
1236
+
1176
1237
#[ derive( Deserialize , Debug , Clone , Copy ) ]
1177
1238
#[ serde( rename_all = "snake_case" ) ]
1178
1239
enum SnippetScopeDef {
@@ -1243,21 +1304,16 @@ enum ManifestOrProjectJson {
1243
1304
#[ derive( Deserialize , Debug , Clone ) ]
1244
1305
#[ serde( rename_all = "snake_case" ) ]
1245
1306
pub enum ExprFillDefaultDef {
1246
- #[ serde( alias = "todo" ) ]
1247
1307
Todo ,
1248
- #[ serde( alias = "default" ) ]
1249
1308
Default ,
1250
1309
}
1251
1310
1252
1311
#[ derive( Deserialize , Debug , Clone ) ]
1253
1312
#[ serde( rename_all = "snake_case" ) ]
1254
1313
enum ImportGranularityDef {
1255
1314
Preserve ,
1256
- #[ serde( alias = "none" ) ]
1257
1315
Item ,
1258
- #[ serde( alias = "full" ) ]
1259
1316
Crate ,
1260
- #[ serde( alias = "last" ) ]
1261
1317
Module ,
1262
1318
}
1263
1319
@@ -1266,8 +1322,6 @@ enum ImportGranularityDef {
1266
1322
enum CallableCompletionDef {
1267
1323
FillArguments ,
1268
1324
AddParentheses ,
1269
- #[ serde( alias = "false" ) ]
1270
- None ,
1271
1325
}
1272
1326
1273
1327
#[ derive( Deserialize , Debug , Clone ) ]
@@ -1280,10 +1334,11 @@ enum CargoFeatures {
1280
1334
1281
1335
#[ derive( Deserialize , Debug , Clone ) ]
1282
1336
#[ serde( rename_all = "snake_case" ) ]
1337
+ #[ serde( untagged) ]
1283
1338
enum LifetimeElisionDef {
1284
- #[ serde( alias = "true " ) ]
1339
+ #[ serde( deserialize_with = "true_or_always " ) ]
1285
1340
Always ,
1286
- #[ serde( alias = "false " ) ]
1341
+ #[ serde( deserialize_with = "false_or_never " ) ]
1287
1342
Never ,
1288
1343
SkipTrivial ,
1289
1344
}
@@ -1545,14 +1600,38 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
1545
1600
"maximum" : 255
1546
1601
} ,
1547
1602
"LifetimeElisionDef" => set ! {
1548
- "type" : "string" ,
1603
+ "type" : [ "string" , "boolean" ] ,
1549
1604
"enum" : [ "always" , "never" , "skip_trivial" ] ,
1550
1605
"enumDescriptions" : [
1551
1606
"Always show lifetime elision hints." ,
1552
1607
"Never show lifetime elision hints." ,
1553
1608
"Only show lifetime elision hints if a return type is involved."
1554
1609
] ,
1555
1610
} ,
1611
+ "CargoFeatures" => set ! {
1612
+ "type" : [ "string" , "array" ] ,
1613
+ "items" : { "type" : "string" } ,
1614
+ "enum" : [ "all" ] ,
1615
+ "enumDescriptions" : [
1616
+ "Pass `--all-features` to cargo" ,
1617
+ ] ,
1618
+ } ,
1619
+ "Option<CargoFeatures>" => set ! {
1620
+ "type" : [ "string" , "array" , "null" ] ,
1621
+ "items" : { "type" : "string" } ,
1622
+ "enum" : [ "all" ] ,
1623
+ "enumDescriptions" : [
1624
+ "Pass `--all-features` to cargo" ,
1625
+ ] ,
1626
+ } ,
1627
+ "Option<CallableCompletionDef>" => set ! {
1628
+ "type" : [ "string" , "null" ] ,
1629
+ "enum" : [ "fill_arguments" , "add_parentheses" ] ,
1630
+ "enumDescriptions" : [
1631
+ "Add call parentheses and pre-fill arguments" ,
1632
+ "Add call parentheses" ,
1633
+ ] ,
1634
+ } ,
1556
1635
_ => panic ! ( "missing entry for {}: {}" , ty, default ) ,
1557
1636
}
1558
1637
0 commit comments