@@ -30,6 +30,7 @@ use project_model::{
30
30
} ;
31
31
use rustc_hash:: { FxHashMap , FxHashSet } ;
32
32
use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
33
+ use std:: collections:: BTreeMap ;
33
34
use toml;
34
35
use vfs:: { AbsPath , AbsPathBuf , FileId } ;
35
36
@@ -141,7 +142,7 @@ config_data! {
141
142
// than `checkOnSave_target`
142
143
cargo_target: Option <String > = None ,
143
144
/// Unsets the implicit `#[cfg(test)]` for the specified crates.
144
- cargo_unsetTest: Vec <String > = vec! [ "core" . to_string ( ) ] ,
145
+ cargo_unsetTest: Vec <String > = @from_str : r#" ["core"]"# ,
145
146
146
147
/// Run the check command for diagnostics on save.
147
148
checkOnSave | checkOnSave_enable: bool = true ,
@@ -383,7 +384,48 @@ config_data! {
383
384
/// 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
385
completion_privateEditable_enable: bool = false ,
385
386
/// Custom completion snippets.
386
- completion_snippets_custom: FxHashMap <String , SnippetDef > = SnippetDef :: default_snippets( ) ,
387
+ // NOTE: we use BTreeMap for deterministic serialization ordering
388
+ completion_snippets_custom: BTreeMap <String , SnippetDef > = @from_str: r#"{
389
+ "Arc::new": {
390
+ "postfix": "arc",
391
+ "body": "Arc::new(${receiver})",
392
+ "requires": "std::sync::Arc",
393
+ "description": "Put the expression into an `Arc`",
394
+ "scope": "expr"
395
+ },
396
+ "Rc::new": {
397
+ "postfix": "rc",
398
+ "body": "Rc::new(${receiver})",
399
+ "requires": "std::rc::Rc",
400
+ "description": "Put the expression into an `Rc`",
401
+ "scope": "expr"
402
+ },
403
+ "Box::pin": {
404
+ "postfix": "pinbox",
405
+ "body": "Box::pin(${receiver})",
406
+ "requires": "std::boxed::Box",
407
+ "description": "Put the expression into a pinned `Box`",
408
+ "scope": "expr"
409
+ },
410
+ "Ok": {
411
+ "postfix": "ok",
412
+ "body": "Ok(${receiver})",
413
+ "description": "Wrap the expression in a `Result::Ok`",
414
+ "scope": "expr"
415
+ },
416
+ "Err": {
417
+ "postfix": "err",
418
+ "body": "Err(${receiver})",
419
+ "description": "Wrap the expression in a `Result::Err`",
420
+ "scope": "expr"
421
+ },
422
+ "Some": {
423
+ "postfix": "some",
424
+ "body": "Some(${receiver})",
425
+ "description": "Wrap the expression in an `Option::Some`",
426
+ "scope": "expr"
427
+ }
428
+ }"# ,
387
429
388
430
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
389
431
highlightRelated_breakPoints_enable: bool = true ,
@@ -2015,55 +2057,6 @@ struct SnippetDef {
2015
2057
scope : SnippetScopeDef ,
2016
2058
}
2017
2059
2018
- impl SnippetDef {
2019
- fn default_snippets ( ) -> FxHashMap < String , SnippetDef > {
2020
- serde_json:: from_str (
2021
- r#"{
2022
- "Arc::new": {
2023
- "postfix": "arc",
2024
- "body": "Arc::new(${receiver})",
2025
- "requires": "std::sync::Arc",
2026
- "description": "Put the expression into an `Arc`",
2027
- "scope": "expr"
2028
- },
2029
- "Rc::new": {
2030
- "postfix": "rc",
2031
- "body": "Rc::new(${receiver})",
2032
- "requires": "std::rc::Rc",
2033
- "description": "Put the expression into an `Rc`",
2034
- "scope": "expr"
2035
- },
2036
- "Box::pin": {
2037
- "postfix": "pinbox",
2038
- "body": "Box::pin(${receiver})",
2039
- "requires": "std::boxed::Box",
2040
- "description": "Put the expression into a pinned `Box`",
2041
- "scope": "expr"
2042
- },
2043
- "Ok": {
2044
- "postfix": "ok",
2045
- "body": "Ok(${receiver})",
2046
- "description": "Wrap the expression in a `Result::Ok`",
2047
- "scope": "expr"
2048
- },
2049
- "Err": {
2050
- "postfix": "err",
2051
- "body": "Err(${receiver})",
2052
- "description": "Wrap the expression in a `Result::Err`",
2053
- "scope": "expr"
2054
- },
2055
- "Some": {
2056
- "postfix": "some",
2057
- "body": "Some(${receiver})",
2058
- "description": "Wrap the expression in an `Option::Some`",
2059
- "scope": "expr"
2060
- }
2061
- }"# ,
2062
- )
2063
- . unwrap ( )
2064
- }
2065
- }
2066
-
2067
2060
mod single_or_array {
2068
2061
use serde:: { Deserialize , Serialize } ;
2069
2062
@@ -2309,12 +2302,33 @@ pub enum TargetDirectory {
2309
2302
Directory ( PathBuf ) ,
2310
2303
}
2311
2304
2305
+ macro_rules! _default_val {
2306
+ ( @from_str: $s: literal, $ty: ty) => { {
2307
+ let default_: $ty = serde_json:: from_str( & $s) . unwrap( ) ;
2308
+ default_
2309
+ } } ;
2310
+ ( $default: expr, $ty: ty) => { {
2311
+ let default_: $ty = $default;
2312
+ default_
2313
+ } } ;
2314
+ }
2315
+
2316
+ macro_rules! _default_str {
2317
+ ( @from_str: $s: literal, $_ty: ty) => {
2318
+ $s. to_string( )
2319
+ } ;
2320
+ ( $default: expr, $ty: ty) => { {
2321
+ let val = default_val!( $default, $ty) ;
2322
+ serde_json:: to_string_pretty( & val) . unwrap( )
2323
+ } } ;
2324
+ }
2325
+
2312
2326
macro_rules! _config_data {
2313
2327
// modname is for the tests
2314
2328
( $modname: ident: struct $name: ident {
2315
2329
$(
2316
2330
$( #[ doc=$doc: literal] ) *
2317
- $field: ident $( | $alias: ident) * : $ty: ty = $default: expr,
2331
+ $field: ident $( | $alias: ident) * : $ty: ty = $( @$marker : ident : ) ? $ default: expr,
2318
2332
) *
2319
2333
} ) => {
2320
2334
#[ allow( non_snake_case) ]
@@ -2329,7 +2343,7 @@ macro_rules! _config_data {
2329
2343
error_sink,
2330
2344
stringify!( $field) ,
2331
2345
None $( . or( Some ( stringify!( $alias) ) ) ) * ,
2332
- { let default_ : $ty = $ default; default_ } ,
2346
+ default_val! ( $ ( @$marker : ) ? $ default, $ty ) ,
2333
2347
) ,
2334
2348
) * }
2335
2349
}
@@ -2342,7 +2356,7 @@ macro_rules! _config_data {
2342
2356
error_sink,
2343
2357
stringify!( $field) ,
2344
2358
None $( . or( Some ( stringify!( $alias) ) ) ) * ,
2345
- { let default_ : $ty = $ default; default_ } ,
2359
+ default_val! ( $ ( @$marker : ) ? $ default, $ty ) ,
2346
2360
) ,
2347
2361
) * }
2348
2362
}
@@ -2352,8 +2366,7 @@ macro_rules! _config_data {
2352
2366
$( {
2353
2367
let field = stringify!( $field) ;
2354
2368
let ty = stringify!( $ty) ;
2355
- let default =
2356
- serde_json:: to_string_pretty( & { let default_: $ty = $default; default_ } ) . unwrap( ) ;
2369
+ let default = default_str!( $( @$marker: ) ? $default, $ty) ;
2357
2370
2358
2371
( field, ty, & [ $( $doc) ,* ] , default )
2359
2372
} , ) *
@@ -2371,6 +2384,8 @@ macro_rules! _config_data {
2371
2384
} ;
2372
2385
}
2373
2386
use _config_data as config_data;
2387
+ use _default_str as default_str;
2388
+ use _default_val as default_val;
2374
2389
2375
2390
#[ derive( Debug , Clone , Serialize ) ]
2376
2391
struct ConfigData {
@@ -2545,7 +2560,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
2545
2560
"FxHashMap<Box<str>, Box<[Box<str>]>>" => set ! {
2546
2561
"type" : "object" ,
2547
2562
} ,
2548
- "FxHashMap <String, SnippetDef>" => set ! {
2563
+ "BTreeMap <String, SnippetDef>" => set ! {
2549
2564
"type" : "object" ,
2550
2565
} ,
2551
2566
"FxHashMap<String, String>" => set ! {
0 commit comments