@@ -79,7 +79,7 @@ pub struct CompletionItem {
7979 // FIXME: We shouldn't expose Mutability here (that is HIR types at all), its fine for now though
8080 // until we have more splitting completions in which case we should think about
8181 // generalizing this. See https://github.com/rust-lang/rust-analyzer/issues/12571
82- pub ref_match : Option < ( Mutability , TextSize ) > ,
82+ pub ref_match : Option < ( CompletionItemRefMode , TextSize ) > ,
8383
8484 /// The import data to add to completion's edits.
8585 /// (ImportPath, LastSegment)
@@ -128,8 +128,15 @@ impl fmt::Debug for CompletionItem {
128128 s. field ( "relevance" , & self . relevance ) ;
129129 }
130130
131- if let Some ( ( mutability, offset) ) = & self . ref_match {
132- s. field ( "ref_match" , & format ! ( "&{}@{offset:?}" , mutability. as_keyword_for_ref( ) ) ) ;
131+ if let Some ( ( ref_mode, offset) ) = self . ref_match {
132+ let prefix = match ref_mode {
133+ CompletionItemRefMode :: Reference ( mutability) => match mutability {
134+ Mutability :: Shared => "&" ,
135+ Mutability :: Mut => "&mut " ,
136+ } ,
137+ CompletionItemRefMode :: Dereference => "*" ,
138+ } ;
139+ s. field ( "ref_match" , & format ! ( "{}@{offset:?}" , prefix) ) ;
133140 }
134141 if self . trigger_call_info {
135142 s. field ( "trigger_call_info" , & true ) ;
@@ -400,6 +407,12 @@ impl CompletionItemKind {
400407 }
401408}
402409
410+ #[ derive( Copy , Clone , Debug ) ]
411+ pub enum CompletionItemRefMode {
412+ Reference ( Mutability ) ,
413+ Dereference ,
414+ }
415+
403416impl CompletionItem {
404417 pub ( crate ) fn new (
405418 kind : impl Into < CompletionItemKind > ,
@@ -441,15 +454,14 @@ impl CompletionItem {
441454 let mut relevance = self . relevance ;
442455 relevance. type_match = Some ( CompletionRelevanceTypeMatch :: Exact ) ;
443456
444- self . ref_match . map ( |( mutability, offset) | {
445- (
446- format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , self . label. primary) ,
447- ide_db:: text_edit:: Indel :: insert (
448- offset,
449- format ! ( "&{}" , mutability. as_keyword_for_ref( ) ) ,
450- ) ,
451- relevance,
452- )
457+ self . ref_match . map ( |( mode, offset) | {
458+ let prefix = match mode {
459+ CompletionItemRefMode :: Reference ( Mutability :: Shared ) => "&" ,
460+ CompletionItemRefMode :: Reference ( Mutability :: Mut ) => "&mut " ,
461+ CompletionItemRefMode :: Dereference => "*" ,
462+ } ;
463+ let label = format ! ( "{prefix}{}" , self . label. primary) ;
464+ ( label, ide_db:: text_edit:: Indel :: insert ( offset, String :: from ( prefix) ) , relevance)
453465 } )
454466 }
455467}
@@ -473,7 +485,7 @@ pub(crate) struct Builder {
473485 deprecated : bool ,
474486 trigger_call_info : bool ,
475487 relevance : CompletionRelevance ,
476- ref_match : Option < ( Mutability , TextSize ) > ,
488+ ref_match : Option < ( CompletionItemRefMode , TextSize ) > ,
477489 edition : Edition ,
478490}
479491
@@ -657,8 +669,12 @@ impl Builder {
657669 self . imports_to_add . push ( import_to_add) ;
658670 self
659671 }
660- pub ( crate ) fn ref_match ( & mut self , mutability : Mutability , offset : TextSize ) -> & mut Builder {
661- self . ref_match = Some ( ( mutability, offset) ) ;
672+ pub ( crate ) fn ref_match (
673+ & mut self ,
674+ ref_mode : CompletionItemRefMode ,
675+ offset : TextSize ,
676+ ) -> & mut Builder {
677+ self . ref_match = Some ( ( ref_mode, offset) ) ;
662678 self
663679 }
664680}
0 commit comments