@@ -39,10 +39,7 @@ use crate::{
3939// - Toggles (be it binary true/false or with more options in-between) should almost always suffix as `_enable`
4040// - In general be wary of using the namespace of something verbatim, it prevents us from adding subkeys in the future
4141// - 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
4643
4744// Defines the server-side configuration of the rust-analyzer. We generate
4845// *parts* of VS Code's `package.json` config from this.
@@ -108,7 +105,7 @@ config_data! {
108105 /// with `self` prefixed to them when inside a method.
109106 completion_autoself_enable: bool = "true" ,
110107 /// Whether to add parenthesis and argument snippets when completing function.
111- completion_callable_snippets: CallableCompletionDef = "fillArguments " ,
108+ completion_callable_snippets: Option < CallableCompletionDef > = "\" fill_arguments \" " ,
112109 /// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
113110 completion_postfix_enable: bool = "true" ,
114111 /// 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! {
217214 /// Use markdown syntax for links in hover.
218215 hover_links_enable: bool = "true" ,
219216
220- // TODO: this should be in granulatiry?
221217 /// 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.
222218 imports_enforceGranularity: bool = "false" ,
223219 /// How imports should be grouped into use statements.
224220 imports_granularity: ImportGranularityDef = "\" crate\" " ,
225221 /// 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
227222 imports_group: bool = "true" ,
228223 /// Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`.
229224 imports_mergeIntoGlob: bool = "true" ,
@@ -353,7 +348,6 @@ config_data! {
353348
354349 /// Show documentation.
355350 signatureInfo_documentation_enable: bool = "true" ,
356- // TODO: needs a better name
357351 /// Show full signature of the callable. Only shows parameters if disabled.
358352 signatureInfo_signature_enable: bool = "true" ,
359353
@@ -1002,11 +996,11 @@ impl Config {
1002996 enable_private_editable : self . data . completion_privateEditable_enable ,
1003997 add_call_parenthesis : matches ! (
1004998 self . data. completion_callable_snippets,
1005- CallableCompletionDef :: AddParentheses
999+ Some ( CallableCompletionDef :: AddParentheses )
10061000 ) ,
10071001 add_call_argument_snippets : matches ! (
10081002 self . data. completion_callable_snippets,
1009- CallableCompletionDef :: FillArguments
1003+ Some ( CallableCompletionDef :: FillArguments )
10101004 ) ,
10111005 insert_use : self . insert_use_config ( ) ,
10121006 snippet_cap : SnippetCap :: new ( try_or_def ! (
@@ -1170,9 +1164,76 @@ impl Config {
11701164 }
11711165 }
11721166}
1173-
11741167// Deserialization definitions
11751168
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+
11761237#[ derive( Deserialize , Debug , Clone , Copy ) ]
11771238#[ serde( rename_all = "snake_case" ) ]
11781239enum SnippetScopeDef {
@@ -1243,21 +1304,16 @@ enum ManifestOrProjectJson {
12431304#[ derive( Deserialize , Debug , Clone ) ]
12441305#[ serde( rename_all = "snake_case" ) ]
12451306pub enum ExprFillDefaultDef {
1246- #[ serde( alias = "todo" ) ]
12471307 Todo ,
1248- #[ serde( alias = "default" ) ]
12491308 Default ,
12501309}
12511310
12521311#[ derive( Deserialize , Debug , Clone ) ]
12531312#[ serde( rename_all = "snake_case" ) ]
12541313enum ImportGranularityDef {
12551314 Preserve ,
1256- #[ serde( alias = "none" ) ]
12571315 Item ,
1258- #[ serde( alias = "full" ) ]
12591316 Crate ,
1260- #[ serde( alias = "last" ) ]
12611317 Module ,
12621318}
12631319
@@ -1266,8 +1322,6 @@ enum ImportGranularityDef {
12661322enum CallableCompletionDef {
12671323 FillArguments ,
12681324 AddParentheses ,
1269- #[ serde( alias = "false" ) ]
1270- None ,
12711325}
12721326
12731327#[ derive( Deserialize , Debug , Clone ) ]
@@ -1280,10 +1334,11 @@ enum CargoFeatures {
12801334
12811335#[ derive( Deserialize , Debug , Clone ) ]
12821336#[ serde( rename_all = "snake_case" ) ]
1337+ #[ serde( untagged) ]
12831338enum LifetimeElisionDef {
1284- #[ serde( alias = "true " ) ]
1339+ #[ serde( deserialize_with = "true_or_always " ) ]
12851340 Always ,
1286- #[ serde( alias = "false " ) ]
1341+ #[ serde( deserialize_with = "false_or_never " ) ]
12871342 Never ,
12881343 SkipTrivial ,
12891344}
@@ -1545,14 +1600,38 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
15451600 "maximum" : 255
15461601 } ,
15471602 "LifetimeElisionDef" => set ! {
1548- "type" : "string" ,
1603+ "type" : [ "string" , "boolean" ] ,
15491604 "enum" : [ "always" , "never" , "skip_trivial" ] ,
15501605 "enumDescriptions" : [
15511606 "Always show lifetime elision hints." ,
15521607 "Never show lifetime elision hints." ,
15531608 "Only show lifetime elision hints if a return type is involved."
15541609 ] ,
15551610 } ,
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+ } ,
15561635 _ => panic ! ( "missing entry for {}: {}" , ty, default ) ,
15571636 }
15581637
0 commit comments