2
2
3
3
use hir:: HirDisplay ;
4
4
use ide_db:: FxHashMap ;
5
+ use itertools:: Either ;
5
6
use syntax:: {
6
7
AstNode , Direction , SyntaxKind , TextRange , TextSize , algo,
7
8
ast:: { self , HasModuleItem } ,
@@ -24,8 +25,8 @@ pub(crate) fn complete_fn_param(
24
25
ctx : & CompletionContext < ' _ > ,
25
26
pattern_ctx : & PatternContext ,
26
27
) -> Option < ( ) > {
27
- let ( ParamContext { param_list, kind, .. } , impl_ ) = match pattern_ctx {
28
- PatternContext { param_ctx : Some ( kind) , impl_ , .. } => ( kind, impl_ ) ,
28
+ let ( ParamContext { param_list, kind, .. } , impl_or_trait ) = match pattern_ctx {
29
+ PatternContext { param_ctx : Some ( kind) , impl_or_trait , .. } => ( kind, impl_or_trait ) ,
29
30
_ => return None ,
30
31
} ;
31
32
@@ -45,7 +46,7 @@ pub(crate) fn complete_fn_param(
45
46
46
47
match kind {
47
48
ParamKind :: Function ( function) => {
48
- fill_fn_params ( ctx, function, param_list, impl_ , add_new_item_to_acc) ;
49
+ fill_fn_params ( ctx, function, param_list, impl_or_trait , add_new_item_to_acc) ;
49
50
}
50
51
ParamKind :: Closure ( closure) => {
51
52
let stmt_list = closure. syntax ( ) . ancestors ( ) . find_map ( ast:: StmtList :: cast) ?;
@@ -62,7 +63,7 @@ fn fill_fn_params(
62
63
ctx : & CompletionContext < ' _ > ,
63
64
function : & ast:: Fn ,
64
65
param_list : & ast:: ParamList ,
65
- impl_ : & Option < ast:: Impl > ,
66
+ impl_or_trait : & Option < Either < ast:: Impl , ast :: Trait > > ,
66
67
mut add_new_item_to_acc : impl FnMut ( & str ) ,
67
68
) {
68
69
let mut file_params = FxHashMap :: default ( ) ;
@@ -107,7 +108,7 @@ fn fill_fn_params(
107
108
}
108
109
remove_duplicated ( & mut file_params, param_list. params ( ) ) ;
109
110
let self_completion_items = [ "self" , "&self" , "mut self" , "&mut self" ] ;
110
- if should_add_self_completions ( ctx. token . text_range ( ) . start ( ) , param_list, impl_ ) {
111
+ if should_add_self_completions ( ctx. token . text_range ( ) . start ( ) , param_list, impl_or_trait ) {
111
112
self_completion_items. into_iter ( ) . for_each ( & mut add_new_item_to_acc) ;
112
113
}
113
114
@@ -161,9 +162,9 @@ fn remove_duplicated(
161
162
fn should_add_self_completions (
162
163
cursor : TextSize ,
163
164
param_list : & ast:: ParamList ,
164
- impl_ : & Option < ast:: Impl > ,
165
+ impl_or_trait : & Option < Either < ast:: Impl , ast :: Trait > > ,
165
166
) -> bool {
166
- if impl_ . is_none ( ) || param_list. self_param ( ) . is_some ( ) {
167
+ if impl_or_trait . is_none ( ) || param_list. self_param ( ) . is_some ( ) {
167
168
return false ;
168
169
}
169
170
match param_list. params ( ) . next ( ) {
0 commit comments