@@ -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,13 +25,13 @@ 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
} ;
37
36
item. add_to ( acc)
38
37
} ;
@@ -44,7 +43,7 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
44
43
ParamKind :: Closure ( closure) => {
45
44
let stmt_list = closure. syntax ( ) . ancestors ( ) . find_map ( ast:: StmtList :: cast) ?;
46
45
params_from_stmt_list_scope ( ctx, stmt_list, |name, ty| {
47
- add_new_item_to_acc ( & format ! ( "{name}: {ty}" ) , name . to_string ( ) ) ;
46
+ add_new_item_to_acc ( & format ! ( "{name}: {ty}" ) ) ;
48
47
} ) ;
49
48
}
50
49
}
@@ -56,7 +55,7 @@ fn fill_fn_params(
56
55
ctx : & CompletionContext ,
57
56
function : & ast:: Fn ,
58
57
param_list : & ast:: ParamList ,
59
- mut add_new_item_to_acc : impl FnMut ( & str , String ) ,
58
+ mut add_new_item_to_acc : impl FnMut ( & str ) ,
60
59
) {
61
60
let mut file_params = FxHashMap :: default ( ) ;
62
61
@@ -96,18 +95,13 @@ fn fill_fn_params(
96
95
file_params. entry ( format ! ( "{name}: {ty}" ) ) . or_insert ( name. to_string ( ) ) ;
97
96
} ) ;
98
97
}
99
-
100
98
remove_duplicated ( & mut file_params, param_list. params ( ) ) ;
101
99
let self_completion_items = [ "self" , "&self" , "mut self" , "&mut self" ] ;
102
100
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 ( ) ) ) ;
101
+ self_completion_items. into_iter ( ) . for_each ( |self_item| add_new_item_to_acc ( self_item) ) ;
106
102
}
107
103
108
- file_params
109
- . into_iter ( )
110
- . for_each ( |( whole_param, binding) | add_new_item_to_acc ( & whole_param, binding) ) ;
104
+ file_params. keys ( ) . for_each ( |whole_param| add_new_item_to_acc ( whole_param) ) ;
111
105
}
112
106
113
107
fn params_from_stmt_list_scope (
@@ -161,16 +155,16 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: &ast::ParamL
161
155
inside_impl && no_params
162
156
}
163
157
164
- fn comma_wrapper ( ctx : & CompletionContext ) -> Option < ( impl Fn ( & str ) -> String , TextRange , String ) > {
158
+ fn comma_wrapper ( ctx : & CompletionContext ) -> Option < ( impl Fn ( & str ) -> String , TextRange ) > {
165
159
let param = ctx. token . ancestors ( ) . find ( |node| node. kind ( ) == SyntaxKind :: PARAM ) ?;
166
-
160
+ let is_mut_token = ( ctx . token . kind ( ) == SyntaxKind :: MUT_KW ) . then ( || & ctx . token ) ;
167
161
let next_token_kind = {
168
- let t = param. last_token ( ) ?. next_token ( ) ?;
162
+ let t = is_mut_token . or ( param. last_token ( ) . as_ref ( ) ) ?. next_token ( ) ?;
169
163
let t = algo:: skip_whitespace_token ( t, Direction :: Next ) ?;
170
164
t. kind ( )
171
165
} ;
172
166
let prev_token_kind = {
173
- let t = param. first_token ( ) ?. prev_token ( ) ?;
167
+ let t = param. first_token ( ) . as_ref ( ) ?. prev_token ( ) ?;
174
168
let t = algo:: skip_whitespace_token ( t, Direction :: Prev ) ?;
175
169
t. kind ( )
176
170
} ;
@@ -185,7 +179,6 @@ fn comma_wrapper(ctx: &CompletionContext) -> Option<(impl Fn(&str) -> String, Te
185
179
186
180
Some ( (
187
181
move |label : & _ | ( format ! ( "{}{}{}" , leading, label, trailing) ) ,
188
- param. text_range ( ) ,
189
- format ! ( "{}{}" , leading, param. text( ) ) ,
182
+ is_mut_token. map ( |token| token. text_range ( ) ) . unwrap_or_else ( || param. text_range ( ) ) ,
190
183
) )
191
184
}
0 commit comments