@@ -79,7 +79,7 @@ pub struct CompletionItem {
79
79
// FIXME: We shouldn't expose Mutability here (that is HIR types at all), its fine for now though
80
80
// until we have more splitting completions in which case we should think about
81
81
// 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 ) > ,
83
83
84
84
/// The import data to add to completion's edits.
85
85
/// (ImportPath, LastSegment)
@@ -128,8 +128,15 @@ impl fmt::Debug for CompletionItem {
128
128
s. field ( "relevance" , & self . relevance ) ;
129
129
}
130
130
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) ) ;
133
140
}
134
141
if self . trigger_call_info {
135
142
s. field ( "trigger_call_info" , & true ) ;
@@ -400,6 +407,12 @@ impl CompletionItemKind {
400
407
}
401
408
}
402
409
410
+ #[ derive( Copy , Clone , Debug ) ]
411
+ pub enum CompletionItemRefMode {
412
+ Reference ( Mutability ) ,
413
+ Dereference ,
414
+ }
415
+
403
416
impl CompletionItem {
404
417
pub ( crate ) fn new (
405
418
kind : impl Into < CompletionItemKind > ,
@@ -441,15 +454,14 @@ impl CompletionItem {
441
454
let mut relevance = self . relevance ;
442
455
relevance. type_match = Some ( CompletionRelevanceTypeMatch :: Exact ) ;
443
456
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)
453
465
} )
454
466
}
455
467
}
@@ -473,7 +485,7 @@ pub(crate) struct Builder {
473
485
deprecated : bool ,
474
486
trigger_call_info : bool ,
475
487
relevance : CompletionRelevance ,
476
- ref_match : Option < ( Mutability , TextSize ) > ,
488
+ ref_match : Option < ( CompletionItemRefMode , TextSize ) > ,
477
489
edition : Edition ,
478
490
}
479
491
@@ -657,8 +669,12 @@ impl Builder {
657
669
self . imports_to_add . push ( import_to_add) ;
658
670
self
659
671
}
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) ) ;
662
678
self
663
679
}
664
680
}
0 commit comments