@@ -383,8 +383,7 @@ config_data! {
383
383
/// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
384
384
completion_privateEditable_enable: bool = false ,
385
385
/// Custom completion snippets.
386
- // NOTE: Keep this list in sync with the feature docs of user snippets.
387
- completion_snippets_custom: FxHashMap <String , SnippetDef > = FxHashMap :: default ( ) ,
386
+ completion_snippets_custom: FxHashMap <String , SnippetDef > = SnippetDef :: default_snippets( ) ,
388
387
389
388
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
390
389
highlightRelated_breakPoints_enable: bool = true ,
@@ -1957,7 +1956,7 @@ mod de_unit_v {
1957
1956
named_unit_variant ! ( both) ;
1958
1957
}
1959
1958
1960
- #[ derive( Serialize , Deserialize , Debug , Clone , Copy ) ]
1959
+ #[ derive( Serialize , Deserialize , Debug , Clone , Copy , PartialEq ) ]
1961
1960
#[ serde( rename_all = "snake_case" ) ]
1962
1961
enum SnippetScopeDef {
1963
1962
Expr ,
@@ -1974,47 +1973,121 @@ impl Default for SnippetScopeDef {
1974
1973
#[ derive( Serialize , Deserialize , Debug , Clone , Default ) ]
1975
1974
#[ serde( default ) ]
1976
1975
struct SnippetDef {
1977
- #[ serde( deserialize_with = "single_or_array" ) ]
1976
+ #[ serde( with = "single_or_array" ) ]
1977
+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
1978
1978
prefix : Vec < String > ,
1979
- #[ serde( deserialize_with = "single_or_array" ) ]
1979
+
1980
+ #[ serde( with = "single_or_array" ) ]
1981
+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
1980
1982
postfix : Vec < String > ,
1981
- description : Option < String > ,
1982
- #[ serde( deserialize_with = "single_or_array" ) ]
1983
+
1984
+ #[ serde( with = "single_or_array" ) ]
1985
+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
1983
1986
body : Vec < String > ,
1984
- #[ serde( deserialize_with = "single_or_array" ) ]
1987
+
1988
+ #[ serde( with = "single_or_array" ) ]
1989
+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
1985
1990
requires : Vec < String > ,
1991
+
1992
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1993
+ description : Option < String > ,
1994
+
1986
1995
scope : SnippetScopeDef ,
1987
1996
}
1988
1997
1989
- fn single_or_array < ' de , D > ( deserializer : D ) -> Result < Vec < String > , D :: Error >
1990
- where
1991
- D : serde:: Deserializer < ' de > ,
1992
- {
1993
- struct SingleOrVec ;
1998
+ impl SnippetDef {
1999
+ fn default_snippets ( ) -> FxHashMap < String , SnippetDef > {
2000
+ serde_json:: from_str (
2001
+ r#"{
2002
+ "Arc::new": {
2003
+ "postfix": "arc",
2004
+ "body": "Arc::new(${receiver})",
2005
+ "requires": "std::sync::Arc",
2006
+ "description": "Put the expression into an `Arc`",
2007
+ "scope": "expr"
2008
+ },
2009
+ "Rc::new": {
2010
+ "postfix": "rc",
2011
+ "body": "Rc::new(${receiver})",
2012
+ "requires": "std::rc::Rc",
2013
+ "description": "Put the expression into an `Rc`",
2014
+ "scope": "expr"
2015
+ },
2016
+ "Box::pin": {
2017
+ "postfix": "pinbox",
2018
+ "body": "Box::pin(${receiver})",
2019
+ "requires": "std::boxed::Box",
2020
+ "description": "Put the expression into a pinned `Box`",
2021
+ "scope": "expr"
2022
+ },
2023
+ "Ok": {
2024
+ "postfix": "ok",
2025
+ "body": "Ok(${receiver})",
2026
+ "description": "Wrap the expression in a `Result::Ok`",
2027
+ "scope": "expr"
2028
+ },
2029
+ "Err": {
2030
+ "postfix": "err",
2031
+ "body": "Err(${receiver})",
2032
+ "description": "Wrap the expression in a `Result::Err`",
2033
+ "scope": "expr"
2034
+ },
2035
+ "Some": {
2036
+ "postfix": "some",
2037
+ "body": "Some(${receiver})",
2038
+ "description": "Wrap the expression in an `Option::Some`",
2039
+ "scope": "expr"
2040
+ }
2041
+ }"# ,
2042
+ )
2043
+ . unwrap ( )
2044
+ }
2045
+ }
2046
+
2047
+ mod single_or_array {
2048
+ use serde:: { Deserialize , Serialize } ;
1994
2049
1995
- impl < ' de > serde:: de:: Visitor < ' de > for SingleOrVec {
1996
- type Value = Vec < String > ;
2050
+ pub fn deserialize < ' de , D > ( deserializer : D ) -> Result < Vec < String > , D :: Error >
2051
+ where
2052
+ D : serde:: Deserializer < ' de > ,
2053
+ {
2054
+ struct SingleOrVec ;
1997
2055
1998
- fn expecting ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1999
- formatter. write_str ( "string or array of strings" )
2000
- }
2056
+ impl < ' de > serde:: de:: Visitor < ' de > for SingleOrVec {
2057
+ type Value = Vec < String > ;
2001
2058
2002
- fn visit_str < E > ( self , value : & str ) -> Result < Self :: Value , E >
2003
- where
2004
- E : serde:: de:: Error ,
2005
- {
2006
- Ok ( vec ! [ value. to_owned( ) ] )
2007
- }
2059
+ fn expecting ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
2060
+ formatter. write_str ( "string or array of strings" )
2061
+ }
2008
2062
2009
- fn visit_seq < A > ( self , seq : A ) -> Result < Self :: Value , A :: Error >
2010
- where
2011
- A : serde:: de:: SeqAccess < ' de > ,
2012
- {
2013
- Deserialize :: deserialize ( serde:: de:: value:: SeqAccessDeserializer :: new ( seq) )
2063
+ fn visit_str < E > ( self , value : & str ) -> Result < Self :: Value , E >
2064
+ where
2065
+ E : serde:: de:: Error ,
2066
+ {
2067
+ Ok ( vec ! [ value. to_owned( ) ] )
2068
+ }
2069
+
2070
+ fn visit_seq < A > ( self , seq : A ) -> Result < Self :: Value , A :: Error >
2071
+ where
2072
+ A : serde:: de:: SeqAccess < ' de > ,
2073
+ {
2074
+ Deserialize :: deserialize ( serde:: de:: value:: SeqAccessDeserializer :: new ( seq) )
2075
+ }
2014
2076
}
2077
+
2078
+ deserializer. deserialize_any ( SingleOrVec )
2015
2079
}
2016
2080
2017
- deserializer. deserialize_any ( SingleOrVec )
2081
+ pub fn serialize < S > ( vec : & Vec < String > , serializer : S ) -> Result < S :: Ok , S :: Error >
2082
+ where
2083
+ S : serde:: Serializer ,
2084
+ {
2085
+ match & vec[ ..] {
2086
+ // [] case is handled by skip_serializing_if
2087
+ [ single] => serializer. serialize_str ( & single) ,
2088
+ slice => slice. serialize ( serializer) ,
2089
+ }
2090
+ }
2018
2091
}
2019
2092
2020
2093
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
@@ -2064,7 +2137,7 @@ enum InvocationStrategy {
2064
2137
}
2065
2138
2066
2139
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2067
- struct CheckOnSaveTargets ( #[ serde( deserialize_with = "single_or_array" ) ] Vec < String > ) ;
2140
+ struct CheckOnSaveTargets ( #[ serde( with = "single_or_array" ) ] Vec < String > ) ;
2068
2141
2069
2142
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2070
2143
#[ serde( rename_all = "snake_case" ) ]
@@ -2249,7 +2322,7 @@ macro_rules! _config_data {
2249
2322
let field = stringify!( $field) ;
2250
2323
let ty = stringify!( $ty) ;
2251
2324
let default =
2252
- serde_json:: to_string ( & { let default_: $ty = $default; default_ } ) . unwrap( ) ;
2325
+ serde_json:: to_string_pretty ( & { let default_: $ty = $default; default_ } ) . unwrap( ) ;
2253
2326
2254
2327
( field, ty, & [ $( $doc) ,* ] , default )
2255
2328
} , ) *
0 commit comments