@@ -12,8 +12,8 @@ use ide_db::{
1212    SymbolKind , 
1313} ; 
1414use  smallvec:: SmallVec ; 
15- use  stdx:: { format_to ,   impl_from,  never} ; 
16- use  syntax:: { algo,  TextRange } ; 
15+ use  stdx:: { impl_from,  never} ; 
16+ use  syntax:: { algo,  SmolStr ,   TextRange } ; 
1717use  text_edit:: TextEdit ; 
1818
1919/// `CompletionItem` describes a single completion variant in the editor pop-up. 
@@ -22,7 +22,7 @@ use text_edit::TextEdit;
2222#[ derive( Clone ) ]  
2323pub  struct  CompletionItem  { 
2424    /// Label in the completion pop up which identifies completion. 
25-      label :  String , 
25+      label :  SmolStr , 
2626    /// Range of identifier that is being completed. 
2727     /// 
2828     /// It should be used primarily for UI, but we also use this to convert 
@@ -46,7 +46,7 @@ pub struct CompletionItem {
4646     /// 
4747     /// That is, in `foo.bar$0` lookup of `abracadabra` will be accepted (it 
4848     /// contains `bar` sub sequence), and `quux` will rejected. 
49-      lookup :  Option < String > , 
49+      lookup :  Option < SmolStr > , 
5050
5151    /// Additional info to show in the UI pop up. 
5252     detail :  Option < String > , 
@@ -268,7 +268,7 @@ impl CompletionItem {
268268    pub ( crate )  fn  new ( 
269269        kind :  impl  Into < CompletionItemKind > , 
270270        source_range :  TextRange , 
271-         label :  impl  Into < String > , 
271+         label :  impl  Into < SmolStr > , 
272272    )  -> Builder  { 
273273        let  label = label. into ( ) ; 
274274        Builder  { 
@@ -379,13 +379,13 @@ impl ImportEdit {
379379pub ( crate )  struct  Builder  { 
380380    source_range :  TextRange , 
381381    imports_to_add :  SmallVec < [ ImportEdit ;  1 ] > , 
382-     trait_name :  Option < String > , 
383-     label :  String , 
382+     trait_name :  Option < SmolStr > , 
383+     label :  SmolStr , 
384384    insert_text :  Option < String > , 
385385    is_snippet :  bool , 
386386    detail :  Option < String > , 
387387    documentation :  Option < Documentation > , 
388-     lookup :  Option < String > , 
388+     lookup :  Option < SmolStr > , 
389389    kind :  CompletionItemKind , 
390390    text_edit :  Option < TextEdit > , 
391391    deprecated :  bool , 
@@ -400,25 +400,21 @@ impl Builder {
400400
401401        let  mut  label = self . label ; 
402402        let  mut  lookup = self . lookup ; 
403-         let  mut   insert_text = self . insert_text ; 
403+         let  insert_text = self . insert_text . unwrap_or_else ( || label . to_string ( ) ) ; 
404404
405405        if  let  [ import_edit]  = & * self . imports_to_add  { 
406406            // snippets can have multiple imports, but normal completions only have up to one 
407407            if  let  Some ( original_path)  = import_edit. import . original_path . as_ref ( )  { 
408408                lookup = lookup. or_else ( || Some ( label. clone ( ) ) ) ; 
409-                 insert_text = insert_text. or_else ( || Some ( label. clone ( ) ) ) ; 
410-                 format_to ! ( label,  " (use {})" ,  original_path) 
409+                 label = SmolStr :: from ( format ! ( "{} (use {})" ,  label,  original_path) ) ; 
411410            } 
412411        }  else  if  let  Some ( trait_name)  = self . trait_name  { 
413-             insert_text = insert_text. or_else ( || Some ( label. clone ( ) ) ) ; 
414-             format_to ! ( label,  " (as {})" ,  trait_name) 
412+             label = SmolStr :: from ( format ! ( "{} (as {})" ,  label,  trait_name) ) ; 
415413        } 
416414
417415        let  text_edit = match  self . text_edit  { 
418416            Some ( it)  => it, 
419-             None  => { 
420-                 TextEdit :: replace ( self . source_range ,  insert_text. unwrap_or_else ( || label. clone ( ) ) ) 
421-             } 
417+             None  => TextEdit :: replace ( self . source_range ,  insert_text) , 
422418        } ; 
423419
424420        CompletionItem  { 
@@ -437,16 +433,16 @@ impl Builder {
437433            import_to_add :  self . imports_to_add , 
438434        } 
439435    } 
440-     pub ( crate )  fn  lookup_by ( & mut  self ,  lookup :  impl  Into < String > )  -> & mut  Builder  { 
436+     pub ( crate )  fn  lookup_by ( & mut  self ,  lookup :  impl  Into < SmolStr > )  -> & mut  Builder  { 
441437        self . lookup  = Some ( lookup. into ( ) ) ; 
442438        self 
443439    } 
444-     pub ( crate )  fn  label ( & mut  self ,  label :  impl  Into < String > )  -> & mut  Builder  { 
440+     pub ( crate )  fn  label ( & mut  self ,  label :  impl  Into < SmolStr > )  -> & mut  Builder  { 
445441        self . label  = label. into ( ) ; 
446442        self 
447443    } 
448-     pub ( crate )  fn  trait_name ( & mut  self ,  trait_name :  impl   Into < String > )  -> & mut  Builder  { 
449-         self . trait_name  = Some ( trait_name. into ( ) ) ; 
444+     pub ( crate )  fn  trait_name ( & mut  self ,  trait_name :  SmolStr )  -> & mut  Builder  { 
445+         self . trait_name  = Some ( trait_name) ; 
450446        self 
451447    } 
452448    pub ( crate )  fn  insert_text ( & mut  self ,  insert_text :  impl  Into < String > )  -> & mut  Builder  { 
0 commit comments