@@ -450,6 +450,7 @@ impl CompletionItem {
450450 ref_match : None ,
451451 imports_to_add : Default :: default ( ) ,
452452 doc_aliases : vec ! [ ] ,
453+ adds_text : None ,
453454 edition,
454455 }
455456 }
@@ -486,6 +487,7 @@ pub(crate) struct Builder {
486487 imports_to_add : SmallVec < [ LocatedImport ; 1 ] > ,
487488 trait_name : Option < SmolStr > ,
488489 doc_aliases : Vec < SmolStr > ,
490+ adds_text : Option < SmolStr > ,
489491 label : SmolStr ,
490492 insert_text : Option < String > ,
491493 is_snippet : bool ,
@@ -526,9 +528,16 @@ impl Builder {
526528 let insert_text = self . insert_text . unwrap_or_else ( || label. to_string ( ) ) ;
527529
528530 let mut detail_left = None ;
531+ let mut to_detail_left = |args : fmt:: Arguments < ' _ > | {
532+ let detail_left = detail_left. get_or_insert_with ( String :: new) ;
533+ if !detail_left. is_empty ( ) {
534+ detail_left. push ( ' ' ) ;
535+ }
536+ format_to ! ( detail_left, "{args}" )
537+ } ;
529538 if !self . doc_aliases . is_empty ( ) {
530539 let doc_aliases = self . doc_aliases . iter ( ) . join ( ", " ) ;
531- detail_left = Some ( format ! ( "(alias {doc_aliases})" ) ) ;
540+ to_detail_left ( format_args ! ( "(alias {doc_aliases})" ) ) ;
532541 let lookup_doc_aliases = self
533542 . doc_aliases
534543 . iter ( )
@@ -548,22 +557,17 @@ impl Builder {
548557 lookup = format_smolstr ! ( "{lookup}{lookup_doc_aliases}" ) ;
549558 }
550559 }
560+ if let Some ( adds_text) = self . adds_text {
561+ to_detail_left ( format_args ! ( "(adds {})" , adds_text. trim( ) ) ) ;
562+ }
551563 if let [ import_edit] = & * self . imports_to_add {
552564 // snippets can have multiple imports, but normal completions only have up to one
553- let detail_left = detail_left. get_or_insert_with ( String :: new) ;
554- format_to ! (
555- detail_left,
556- "{}(use {})" ,
557- if detail_left. is_empty( ) { "" } else { " " } ,
565+ to_detail_left ( format_args ! (
566+ "(use {})" ,
558567 import_edit. import_path. display( db, self . edition)
559- ) ;
568+ ) ) ;
560569 } else if let Some ( trait_name) = self . trait_name {
561- let detail_left = detail_left. get_or_insert_with ( String :: new) ;
562- format_to ! (
563- detail_left,
564- "{}(as {trait_name})" ,
565- if detail_left. is_empty( ) { "" } else { " " } ,
566- ) ;
570+ to_detail_left ( format_args ! ( "(as {trait_name})" ) ) ;
567571 }
568572
569573 let text_edit = match self . text_edit {
@@ -613,6 +617,10 @@ impl Builder {
613617 self . doc_aliases = doc_aliases;
614618 self
615619 }
620+ pub ( crate ) fn adds_text ( & mut self , adds_text : SmolStr ) -> & mut Builder {
621+ self . adds_text = Some ( adds_text) ;
622+ self
623+ }
616624 pub ( crate ) fn insert_text ( & mut self , insert_text : impl Into < String > ) -> & mut Builder {
617625 self . insert_text = Some ( insert_text. into ( ) ) ;
618626 self
0 commit comments