@@ -75,6 +75,8 @@ config_data! {
7575 /// How many worker threads to handle priming caches. The default `0` means to pick automatically.
7676 cachePriming_numThreads: NumThreads = NumThreads :: Physical ,
7777
78+ /// Custom completion snippets.
79+ completion_snippets_custom: FxHashMap <String , SnippetDef > = Config :: completion_snippets_default( ) ,
7880
7981
8082 /// These directories will be ignored by rust-analyzer. They are
@@ -438,48 +440,6 @@ config_data! {
438440 completion_postfix_enable: bool = true ,
439441 /// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
440442 completion_privateEditable_enable: bool = false ,
441- /// Custom completion snippets.
442- completion_snippets_custom: FxHashMap <String , SnippetDef > = serde_json:: from_str( r#"{
443- "Arc::new": {
444- "postfix": "arc",
445- "body": "Arc::new(${receiver})",
446- "requires": "std::sync::Arc",
447- "description": "Put the expression into an `Arc`",
448- "scope": "expr"
449- },
450- "Rc::new": {
451- "postfix": "rc",
452- "body": "Rc::new(${receiver})",
453- "requires": "std::rc::Rc",
454- "description": "Put the expression into an `Rc`",
455- "scope": "expr"
456- },
457- "Box::pin": {
458- "postfix": "pinbox",
459- "body": "Box::pin(${receiver})",
460- "requires": "std::boxed::Box",
461- "description": "Put the expression into a pinned `Box`",
462- "scope": "expr"
463- },
464- "Ok": {
465- "postfix": "ok",
466- "body": "Ok(${receiver})",
467- "description": "Wrap the expression in a `Result::Ok`",
468- "scope": "expr"
469- },
470- "Err": {
471- "postfix": "err",
472- "body": "Err(${receiver})",
473- "description": "Wrap the expression in a `Result::Err`",
474- "scope": "expr"
475- },
476- "Some": {
477- "postfix": "some",
478- "body": "Some(${receiver})",
479- "description": "Wrap the expression in an `Option::Some`",
480- "scope": "expr"
481- }
482- }"# ) . unwrap( ) ,
483443 /// Whether to enable term search based snippets like `Some(foo.bar().baz())`.
484444 completion_termSearch_enable: bool = false ,
485445 /// Term search fuel in "units of work" for autocompletion (Defaults to 1000).
@@ -889,7 +849,7 @@ impl Config {
889849 // IMPORTANT : This holds as long as ` completion_snippets_custom` is declared `client`.
890850 config. snippets . clear ( ) ;
891851
892- let snips = self . completion_snippets_custom ( None ) . to_owned ( ) ;
852+ let snips = self . completion_snippets_custom ( ) . to_owned ( ) ;
893853
894854 for ( name, def) in snips. iter ( ) {
895855 if def. prefix . is_empty ( ) && def. postfix . is_empty ( ) {
@@ -1266,7 +1226,7 @@ pub struct NotificationsConfig {
12661226 pub cargo_toml_not_found : bool ,
12671227}
12681228
1269- #[ derive( Debug , Clone ) ]
1229+ #[ derive( Deserialize , Serialize , Debug , Clone ) ]
12701230pub enum RustfmtConfig {
12711231 Rustfmt { extra_args : Vec < String > , enable_range_formatting : bool } ,
12721232 CustomCommand { command : String , args : Vec < String > } ,
@@ -1897,6 +1857,53 @@ impl Config {
18971857 }
18981858 }
18991859
1860+ pub ( crate ) fn completion_snippets_default ( ) -> FxHashMap < String , SnippetDef > {
1861+ serde_json:: from_str (
1862+ r#"{
1863+ "Arc::new": {
1864+ "postfix": "arc",
1865+ "body": "Arc::new(${receiver})",
1866+ "requires": "std::sync::Arc",
1867+ "description": "Put the expression into an `Arc`",
1868+ "scope": "expr"
1869+ },
1870+ "Rc::new": {
1871+ "postfix": "rc",
1872+ "body": "Rc::new(${receiver})",
1873+ "requires": "std::rc::Rc",
1874+ "description": "Put the expression into an `Rc`",
1875+ "scope": "expr"
1876+ },
1877+ "Box::pin": {
1878+ "postfix": "pinbox",
1879+ "body": "Box::pin(${receiver})",
1880+ "requires": "std::boxed::Box",
1881+ "description": "Put the expression into a pinned `Box`",
1882+ "scope": "expr"
1883+ },
1884+ "Ok": {
1885+ "postfix": "ok",
1886+ "body": "Ok(${receiver})",
1887+ "description": "Wrap the expression in a `Result::Ok`",
1888+ "scope": "expr"
1889+ },
1890+ "Err": {
1891+ "postfix": "err",
1892+ "body": "Err(${receiver})",
1893+ "description": "Wrap the expression in a `Result::Err`",
1894+ "scope": "expr"
1895+ },
1896+ "Some": {
1897+ "postfix": "some",
1898+ "body": "Some(${receiver})",
1899+ "description": "Wrap the expression in an `Option::Some`",
1900+ "scope": "expr"
1901+ }
1902+ }"# ,
1903+ )
1904+ . unwrap ( )
1905+ }
1906+
19001907 pub fn rustfmt ( & self , source_root_id : Option < SourceRootId > ) -> RustfmtConfig {
19011908 match & self . rustfmt_overrideCommand ( source_root_id) {
19021909 Some ( args) if !args. is_empty ( ) => {
0 commit comments