22
33use hir:: HirDisplay ;
44use ide_db:: FxHashMap ;
5+ use itertools:: Either ;
56use syntax:: {
67 AstNode , Direction , SyntaxKind , TextRange , TextSize , algo,
78 ast:: { self , HasModuleItem } ,
@@ -24,8 +25,8 @@ pub(crate) fn complete_fn_param(
2425 ctx : & CompletionContext < ' _ > ,
2526 pattern_ctx : & PatternContext ,
2627) -> 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 ) ,
2930 _ => return None ,
3031 } ;
3132
@@ -45,7 +46,7 @@ pub(crate) fn complete_fn_param(
4546
4647 match kind {
4748 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) ;
4950 }
5051 ParamKind :: Closure ( closure) => {
5152 let stmt_list = closure. syntax ( ) . ancestors ( ) . find_map ( ast:: StmtList :: cast) ?;
@@ -62,7 +63,7 @@ fn fill_fn_params(
6263 ctx : & CompletionContext < ' _ > ,
6364 function : & ast:: Fn ,
6465 param_list : & ast:: ParamList ,
65- impl_ : & Option < ast:: Impl > ,
66+ impl_or_trait : & Option < Either < ast:: Impl , ast :: Trait > > ,
6667 mut add_new_item_to_acc : impl FnMut ( & str ) ,
6768) {
6869 let mut file_params = FxHashMap :: default ( ) ;
@@ -107,7 +108,7 @@ fn fill_fn_params(
107108 }
108109 remove_duplicated ( & mut file_params, param_list. params ( ) ) ;
109110 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 ) {
111112 self_completion_items. into_iter ( ) . for_each ( & mut add_new_item_to_acc) ;
112113 }
113114
@@ -161,9 +162,9 @@ fn remove_duplicated(
161162fn should_add_self_completions (
162163 cursor : TextSize ,
163164 param_list : & ast:: ParamList ,
164- impl_ : & Option < ast:: Impl > ,
165+ impl_or_trait : & Option < Either < ast:: Impl , ast :: Trait > > ,
165166) -> 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 ( ) {
167168 return false ;
168169 }
169170 match param_list. params ( ) . next ( ) {
0 commit comments