@@ -15,8 +15,7 @@ use crate::{
1515
1616/// Complete repeated parameters, both name and type. For example, if all
1717/// functions in a file have a `spam: &mut Spam` parameter, a completion with
18- /// `spam: &mut Spam` insert text/label and `spam` lookup string will be
19- /// suggested.
18+ /// `spam: &mut Spam` insert text/label will be suggested.
2019///
2120/// Also complete parameters for closure or local functions from the surrounding defined locals.
2221pub ( crate ) fn complete_fn_param ( acc : & mut Completions , ctx : & CompletionContext ) -> Option < ( ) > {
@@ -26,14 +25,16 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
2625 } ;
2726
2827 let comma_wrapper = comma_wrapper ( ctx) ;
29- let mut add_new_item_to_acc = |label : & str , lookup : String | {
28+ let mut add_new_item_to_acc = |label : & str | {
3029 let mk_item = |label : & str , range : TextRange | {
3130 CompletionItem :: new ( CompletionItemKind :: Binding , range, label)
3231 } ;
3332 let item = match & comma_wrapper {
34- Some ( ( fmt, range, lookup ) ) => mk_item ( & fmt ( label) , * range) . lookup_by ( lookup ) . to_owned ( ) ,
35- None => mk_item ( label, ctx. source_range ( ) ) . lookup_by ( lookup ) . to_owned ( ) ,
33+ Some ( ( fmt, range) ) => mk_item ( & fmt ( label) , * range) ,
34+ None => mk_item ( label, ctx. source_range ( ) ) ,
3635 } ;
36+ // Completion lookup is omitted intentionally here.
37+ // See the full discussion: https://github.com/rust-lang/rust-analyzer/issues/12073
3738 item. add_to ( acc)
3839 } ;
3940
@@ -44,7 +45,7 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
4445 ParamKind :: Closure ( closure) => {
4546 let stmt_list = closure. syntax ( ) . ancestors ( ) . find_map ( ast:: StmtList :: cast) ?;
4647 params_from_stmt_list_scope ( ctx, stmt_list, |name, ty| {
47- add_new_item_to_acc ( & format ! ( "{name}: {ty}" ) , name . to_string ( ) ) ;
48+ add_new_item_to_acc ( & format ! ( "{name}: {ty}" ) ) ;
4849 } ) ;
4950 }
5051 }
@@ -56,7 +57,7 @@ fn fill_fn_params(
5657 ctx : & CompletionContext ,
5758 function : & ast:: Fn ,
5859 param_list : & ast:: ParamList ,
59- mut add_new_item_to_acc : impl FnMut ( & str , String ) ,
60+ mut add_new_item_to_acc : impl FnMut ( & str ) ,
6061) {
6162 let mut file_params = FxHashMap :: default ( ) ;
6263
@@ -96,18 +97,13 @@ fn fill_fn_params(
9697 file_params. entry ( format ! ( "{name}: {ty}" ) ) . or_insert ( name. to_string ( ) ) ;
9798 } ) ;
9899 }
99-
100100 remove_duplicated ( & mut file_params, param_list. params ( ) ) ;
101101 let self_completion_items = [ "self" , "&self" , "mut self" , "&mut self" ] ;
102102 if should_add_self_completions ( ctx, param_list) {
103- self_completion_items
104- . into_iter ( )
105- . for_each ( |self_item| add_new_item_to_acc ( self_item, self_item. to_string ( ) ) ) ;
103+ self_completion_items. into_iter ( ) . for_each ( |self_item| add_new_item_to_acc ( self_item) ) ;
106104 }
107105
108- file_params
109- . into_iter ( )
110- . for_each ( |( whole_param, binding) | add_new_item_to_acc ( & whole_param, binding) ) ;
106+ file_params. keys ( ) . for_each ( |whole_param| add_new_item_to_acc ( whole_param) ) ;
111107}
112108
113109fn params_from_stmt_list_scope (
@@ -161,7 +157,7 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: &ast::ParamL
161157 inside_impl && no_params
162158}
163159
164- fn comma_wrapper ( ctx : & CompletionContext ) -> Option < ( impl Fn ( & str ) -> String , TextRange , String ) > {
160+ fn comma_wrapper ( ctx : & CompletionContext ) -> Option < ( impl Fn ( & str ) -> String , TextRange ) > {
165161 let param = ctx. token . ancestors ( ) . find ( |node| node. kind ( ) == SyntaxKind :: PARAM ) ?;
166162
167163 let next_token_kind = {
@@ -183,9 +179,5 @@ fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, Te
183179 matches ! ( prev_token_kind, SyntaxKind :: COMMA | SyntaxKind :: L_PAREN | SyntaxKind :: PIPE ) ;
184180 let leading = if has_leading_comma { "" } else { ", " } ;
185181
186- Some ( (
187- move |label : & _ | ( format ! ( "{}{}{}" , leading, label, trailing) ) ,
188- param. text_range ( ) ,
189- format ! ( "{}{}" , leading, param. text( ) ) ,
190- ) )
182+ Some ( ( move |label : & _ | ( format ! ( "{}{}{}" , leading, label, trailing) ) , param. text_range ( ) ) )
191183}
0 commit comments