@@ -15,8 +15,7 @@ use crate::{
15
15
16
16
/// Complete repeated parameters, both name and type. For example, if all
17
17
/// 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.
20
19
///
21
20
/// Also complete parameters for closure or local functions from the surrounding defined locals.
22
21
pub ( 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)
26
25
} ;
27
26
28
27
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 | {
30
29
let mk_item = |label : & str , range : TextRange | {
31
30
CompletionItem :: new ( CompletionItemKind :: Binding , range, label)
32
31
} ;
33
32
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 ( ) ) ,
36
35
} ;
36
+ // Completion lookup is omitted intentionally here.
37
+ // See the full discussion: https://github.com/rust-lang/rust-analyzer/issues/12073
37
38
item. add_to ( acc)
38
39
} ;
39
40
@@ -44,7 +45,7 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
44
45
ParamKind :: Closure ( closure) => {
45
46
let stmt_list = closure. syntax ( ) . ancestors ( ) . find_map ( ast:: StmtList :: cast) ?;
46
47
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}" ) ) ;
48
49
} ) ;
49
50
}
50
51
}
@@ -56,7 +57,7 @@ fn fill_fn_params(
56
57
ctx : & CompletionContext ,
57
58
function : & ast:: Fn ,
58
59
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 ) ,
60
61
) {
61
62
let mut file_params = FxHashMap :: default ( ) ;
62
63
@@ -96,18 +97,13 @@ fn fill_fn_params(
96
97
file_params. entry ( format ! ( "{name}: {ty}" ) ) . or_insert ( name. to_string ( ) ) ;
97
98
} ) ;
98
99
}
99
-
100
100
remove_duplicated ( & mut file_params, param_list. params ( ) ) ;
101
101
let self_completion_items = [ "self" , "&self" , "mut self" , "&mut self" ] ;
102
102
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) ) ;
106
104
}
107
105
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) ) ;
111
107
}
112
108
113
109
fn params_from_stmt_list_scope (
@@ -161,7 +157,7 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: &ast::ParamL
161
157
inside_impl && no_params
162
158
}
163
159
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 ) > {
165
161
let param = ctx. token . ancestors ( ) . find ( |node| node. kind ( ) == SyntaxKind :: PARAM ) ?;
166
162
167
163
let next_token_kind = {
@@ -183,9 +179,5 @@ fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, Te
183
179
matches ! ( prev_token_kind, SyntaxKind :: COMMA | SyntaxKind :: L_PAREN | SyntaxKind :: PIPE ) ;
184
180
let leading = if has_leading_comma { "" } else { ", " } ;
185
181
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 ( ) ) )
191
183
}
0 commit comments