File tree Expand file tree Collapse file tree 4 files changed +16
-21
lines changed
crates/ide_completion/src Expand file tree Collapse file tree 4 files changed +16
-21
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,7 @@ impl CompletionItem {
295
295
label,
296
296
insert_text : None ,
297
297
is_snippet : false ,
298
+ trait_name : None ,
298
299
detail : None ,
299
300
documentation : None ,
300
301
lookup : None ,
@@ -398,6 +399,7 @@ pub(crate) struct Builder {
398
399
source_range : TextRange ,
399
400
completion_kind : CompletionKind ,
400
401
import_to_add : Option < ImportEdit > ,
402
+ trait_name : Option < String > ,
401
403
label : String ,
402
404
insert_text : Option < String > ,
403
405
is_snippet : bool ,
@@ -434,6 +436,8 @@ impl Builder {
434
436
} else {
435
437
format_to ! ( label, " ({})" , original_path)
436
438
}
439
+ } else if let Some ( trait_name) = self . trait_name {
440
+ format_to ! ( label, " ({})" , trait_name)
437
441
}
438
442
439
443
let text_edit = match self . text_edit {
@@ -468,6 +472,10 @@ impl Builder {
468
472
self . label = label. into ( ) ;
469
473
self
470
474
}
475
+ pub ( crate ) fn trait_name ( & mut self , trait_name : impl Into < String > ) -> & mut Builder {
476
+ self . trait_name = Some ( trait_name. into ( ) ) ;
477
+ self
478
+ }
471
479
pub ( crate ) fn insert_text ( & mut self , insert_text : impl Into < String > ) -> & mut Builder {
472
480
self . insert_text = Some ( insert_text. into ( ) ) ;
473
481
self
Original file line number Diff line number Diff line change 1
1
//! Renderer for `const` fields.
2
2
3
- use hir:: { AsAssocItem , HasSource , ModuleDef } ;
3
+ use hir:: { AsAssocItem , HasSource } ;
4
4
use ide_db:: SymbolKind ;
5
5
use syntax:: {
6
6
ast:: { Const , NameOwner } ,
@@ -49,11 +49,8 @@ impl<'a> ConstRender<'a> {
49
49
let db = self . ctx . db ( ) ;
50
50
if let Some ( actm) = self . const_ . as_assoc_item ( db) {
51
51
if let Some ( trt) = actm. containing_trait_or_trait_impl ( db) {
52
- let module = self . ctx . completion . scope . module ( ) . unwrap ( ) ;
53
- if let Some ( path) = module. find_use_path ( db, ModuleDef :: Trait ( trt) ) {
54
- item. label ( format ! ( "{} ({})" , name. clone( ) , path) ) ;
55
- item. insert_text ( name. clone ( ) ) ;
56
- }
52
+ item. trait_name ( trt. name ( db) . to_string ( ) ) ;
53
+ item. insert_text ( name. clone ( ) ) ;
57
54
}
58
55
}
59
56
Original file line number Diff line number Diff line change 1
1
//! Renderer for function calls.
2
2
3
- use hir:: { AsAssocItem , HasSource , HirDisplay , ModuleDef } ;
3
+ use hir:: { AsAssocItem , HasSource , HirDisplay } ;
4
4
use ide_db:: SymbolKind ;
5
5
use itertools:: Itertools ;
6
6
use syntax:: ast:: Fn ;
@@ -79,14 +79,7 @@ impl<'a> FunctionRender<'a> {
79
79
let db = self . ctx . db ( ) ;
80
80
if let Some ( actm) = self . func . as_assoc_item ( db) {
81
81
if let Some ( trt) = actm. containing_trait_or_trait_impl ( db) {
82
- let module = self . ctx . completion . scope . module ( ) . unwrap ( ) ;
83
- if let Some ( path) = module. find_use_path ( db, ModuleDef :: Trait ( trt) ) {
84
- item. label ( format ! (
85
- "{} ({})" ,
86
- item. clone( ) . build( ) . label( ) . to_owned( ) ,
87
- path
88
- ) ) ;
89
- }
82
+ item. trait_name ( trt. name ( db) . to_string ( ) ) ;
90
83
}
91
84
}
92
85
}
Original file line number Diff line number Diff line change 1
1
//! Renderer for type aliases.
2
2
3
- use hir:: { AsAssocItem , HasSource , ModuleDef } ;
3
+ use hir:: { AsAssocItem , HasSource } ;
4
4
use ide_db:: SymbolKind ;
5
5
use syntax:: {
6
6
ast:: { NameOwner , TypeAlias } ,
@@ -62,11 +62,8 @@ impl<'a> TypeAliasRender<'a> {
62
62
let db = self . ctx . db ( ) ;
63
63
if let Some ( actm) = self . type_alias . as_assoc_item ( db) {
64
64
if let Some ( trt) = actm. containing_trait_or_trait_impl ( db) {
65
- let module = self . ctx . completion . scope . module ( ) . unwrap ( ) ;
66
- if let Some ( path) = module. find_use_path ( db, ModuleDef :: Trait ( trt) ) {
67
- item. label ( format ! ( "{} ({})" , name. clone( ) , path) ) ;
68
- item. insert_text ( name. clone ( ) ) ;
69
- }
65
+ item. trait_name ( trt. name ( db) . to_string ( ) ) ;
66
+ item. insert_text ( name. clone ( ) ) ;
70
67
}
71
68
}
72
69
You can’t perform that action at this time.
0 commit comments