@@ -75,6 +75,8 @@ config_data! {
75
75
/// How many worker threads to handle priming caches. The default `0` means to pick automatically.
76
76
cachePriming_numThreads: NumThreads = NumThreads :: Physical ,
77
77
78
+ /// Custom completion snippets.
79
+ completion_snippets_custom: FxHashMap <String , SnippetDef > = Config :: completion_snippets_default( ) ,
78
80
79
81
80
82
/// These directories will be ignored by rust-analyzer. They are
@@ -442,48 +444,6 @@ config_data! {
442
444
completion_postfix_enable: bool = true ,
443
445
/// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
444
446
completion_privateEditable_enable: bool = false ,
445
- /// Custom completion snippets.
446
- completion_snippets_custom: FxHashMap <String , SnippetDef > = serde_json:: from_str( r#"{
447
- "Arc::new": {
448
- "postfix": "arc",
449
- "body": "Arc::new(${receiver})",
450
- "requires": "std::sync::Arc",
451
- "description": "Put the expression into an `Arc`",
452
- "scope": "expr"
453
- },
454
- "Rc::new": {
455
- "postfix": "rc",
456
- "body": "Rc::new(${receiver})",
457
- "requires": "std::rc::Rc",
458
- "description": "Put the expression into an `Rc`",
459
- "scope": "expr"
460
- },
461
- "Box::pin": {
462
- "postfix": "pinbox",
463
- "body": "Box::pin(${receiver})",
464
- "requires": "std::boxed::Box",
465
- "description": "Put the expression into a pinned `Box`",
466
- "scope": "expr"
467
- },
468
- "Ok": {
469
- "postfix": "ok",
470
- "body": "Ok(${receiver})",
471
- "description": "Wrap the expression in a `Result::Ok`",
472
- "scope": "expr"
473
- },
474
- "Err": {
475
- "postfix": "err",
476
- "body": "Err(${receiver})",
477
- "description": "Wrap the expression in a `Result::Err`",
478
- "scope": "expr"
479
- },
480
- "Some": {
481
- "postfix": "some",
482
- "body": "Some(${receiver})",
483
- "description": "Wrap the expression in an `Option::Some`",
484
- "scope": "expr"
485
- }
486
- }"# ) . unwrap( ) ,
487
447
/// Whether to enable term search based snippets like `Some(foo.bar().baz())`.
488
448
completion_termSearch_enable: bool = false ,
489
449
/// Term search fuel in "units of work" for autocompletion (Defaults to 1000).
@@ -893,7 +853,7 @@ impl Config {
893
853
// IMPORTANT : This holds as long as ` completion_snippets_custom` is declared `client`.
894
854
config. snippets . clear ( ) ;
895
855
896
- let snips = self . completion_snippets_custom ( None ) . to_owned ( ) ;
856
+ let snips = self . completion_snippets_custom ( ) . to_owned ( ) ;
897
857
898
858
for ( name, def) in snips. iter ( ) {
899
859
if def. prefix . is_empty ( ) && def. postfix . is_empty ( ) {
@@ -1270,7 +1230,7 @@ pub struct NotificationsConfig {
1270
1230
pub cargo_toml_not_found : bool ,
1271
1231
}
1272
1232
1273
- #[ derive( Debug , Clone ) ]
1233
+ #[ derive( Deserialize , Serialize , Debug , Clone ) ]
1274
1234
pub enum RustfmtConfig {
1275
1235
Rustfmt { extra_args : Vec < String > , enable_range_formatting : bool } ,
1276
1236
CustomCommand { command : String , args : Vec < String > } ,
@@ -1902,6 +1862,53 @@ impl Config {
1902
1862
}
1903
1863
}
1904
1864
1865
+ pub ( crate ) fn completion_snippets_default ( ) -> FxHashMap < String , SnippetDef > {
1866
+ serde_json:: from_str (
1867
+ r#"{
1868
+ "Arc::new": {
1869
+ "postfix": "arc",
1870
+ "body": "Arc::new(${receiver})",
1871
+ "requires": "std::sync::Arc",
1872
+ "description": "Put the expression into an `Arc`",
1873
+ "scope": "expr"
1874
+ },
1875
+ "Rc::new": {
1876
+ "postfix": "rc",
1877
+ "body": "Rc::new(${receiver})",
1878
+ "requires": "std::rc::Rc",
1879
+ "description": "Put the expression into an `Rc`",
1880
+ "scope": "expr"
1881
+ },
1882
+ "Box::pin": {
1883
+ "postfix": "pinbox",
1884
+ "body": "Box::pin(${receiver})",
1885
+ "requires": "std::boxed::Box",
1886
+ "description": "Put the expression into a pinned `Box`",
1887
+ "scope": "expr"
1888
+ },
1889
+ "Ok": {
1890
+ "postfix": "ok",
1891
+ "body": "Ok(${receiver})",
1892
+ "description": "Wrap the expression in a `Result::Ok`",
1893
+ "scope": "expr"
1894
+ },
1895
+ "Err": {
1896
+ "postfix": "err",
1897
+ "body": "Err(${receiver})",
1898
+ "description": "Wrap the expression in a `Result::Err`",
1899
+ "scope": "expr"
1900
+ },
1901
+ "Some": {
1902
+ "postfix": "some",
1903
+ "body": "Some(${receiver})",
1904
+ "description": "Wrap the expression in an `Option::Some`",
1905
+ "scope": "expr"
1906
+ }
1907
+ }"# ,
1908
+ )
1909
+ . unwrap ( )
1910
+ }
1911
+
1905
1912
pub fn rustfmt ( & self , source_root_id : Option < SourceRootId > ) -> RustfmtConfig {
1906
1913
match & self . rustfmt_overrideCommand ( source_root_id) {
1907
1914
Some ( args) if !args. is_empty ( ) => {
0 commit comments