@@ -26,6 +26,10 @@ use crate::{
26
26
pub struct CompletionItem {
27
27
/// Label in the completion pop up which identifies completion.
28
28
pub label : SmolStr ,
29
+ /// Addition label details in the completion pop up that are
30
+ /// displayed and aligned on the right side after the label.
31
+ pub label_detail : Option < SmolStr > ,
32
+
29
33
/// Range of identifier that is being completed.
30
34
///
31
35
/// It should be used primarily for UI, but we also use this to convert
@@ -425,13 +429,14 @@ impl Builder {
425
429
pub ( crate ) fn build ( self , db : & RootDatabase ) -> CompletionItem {
426
430
let _p = profile:: span ( "item::Builder::build" ) ;
427
431
428
- let mut label = self . label ;
432
+ let label = self . label ;
433
+ let mut label_detail = None ;
429
434
let mut lookup = self . lookup . unwrap_or_else ( || label. clone ( ) ) ;
430
435
let insert_text = self . insert_text . unwrap_or_else ( || label. to_string ( ) ) ;
431
436
432
437
if !self . doc_aliases . is_empty ( ) {
433
438
let doc_aliases = self . doc_aliases . iter ( ) . join ( ", " ) ;
434
- label = SmolStr :: from ( format ! ( "{label} (alias {doc_aliases})" ) ) ;
439
+ label_detail . replace ( SmolStr :: from ( format ! ( " (alias {doc_aliases})" ) ) ) ;
435
440
let lookup_doc_aliases = self
436
441
. doc_aliases
437
442
. iter ( )
@@ -454,10 +459,17 @@ impl Builder {
454
459
if let [ import_edit] = & * self . imports_to_add {
455
460
// snippets can have multiple imports, but normal completions only have up to one
456
461
if let Some ( original_path) = import_edit. original_path . as_ref ( ) {
457
- label = SmolStr :: from ( format ! ( "{label} (use {})" , original_path. display( db) ) ) ;
462
+ label_detail. replace ( SmolStr :: from ( format ! (
463
+ "{} (use {})" ,
464
+ label_detail. as_deref( ) . unwrap_or_default( ) ,
465
+ original_path. display( db)
466
+ ) ) ) ;
458
467
}
459
468
} else if let Some ( trait_name) = self . trait_name {
460
- label = SmolStr :: from ( format ! ( "{label} (as {trait_name})" ) ) ;
469
+ label_detail. replace ( SmolStr :: from ( format ! (
470
+ "{} (as {trait_name})" ,
471
+ label_detail. as_deref( ) . unwrap_or_default( ) ,
472
+ ) ) ) ;
461
473
}
462
474
463
475
let text_edit = match self . text_edit {
@@ -479,6 +491,7 @@ impl Builder {
479
491
CompletionItem {
480
492
source_range : self . source_range ,
481
493
label,
494
+ label_detail,
482
495
text_edit,
483
496
is_snippet : self . is_snippet ,
484
497
detail : self . detail ,
0 commit comments