@@ -59,7 +59,7 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
59
59
let function = ctx. token . ancestors ( ) . find_map ( ast:: Fn :: cast) ?;
60
60
let param_list = function. param_list ( ) ?;
61
61
62
- remove_duplicated ( & mut file_params, param_list. params ( ) ) ? ;
62
+ remove_duplicated ( & mut file_params, param_list. params ( ) ) ;
63
63
64
64
let self_completion_items = [ "self" , "&self" , "mut self" , "&mut self" ] ;
65
65
if should_add_self_completions ( ctx, param_list) {
@@ -69,24 +69,24 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
69
69
}
70
70
71
71
file_params. into_iter ( ) . try_for_each ( |( whole_param, binding) | {
72
- Some ( add_new_item_to_acc ( ctx, acc, surround_with_commas ( ctx, whole_param) ? , binding) )
72
+ Some ( add_new_item_to_acc ( ctx, acc, surround_with_commas ( ctx, whole_param) , binding) )
73
73
} ) ?;
74
74
75
75
Some ( ( ) )
76
76
}
77
77
78
78
fn remove_duplicated (
79
79
file_params : & mut FxHashMap < String , String > ,
80
- mut fn_params : ast:: AstChildren < ast:: Param > ,
81
- ) -> Option < ( ) > {
82
- fn_params. try_for_each ( |param| {
80
+ fn_params : ast:: AstChildren < ast:: Param > ,
81
+ ) {
82
+ fn_params. for_each ( |param| {
83
83
let whole_param = param. syntax ( ) . text ( ) . to_string ( ) ;
84
84
file_params. remove ( & whole_param) ;
85
85
86
- let binding = param. pat ( ) ? . syntax ( ) . text ( ) . to_string ( ) ;
87
-
88
- file_params. retain ( |_, v| v != & binding) ;
89
- Some ( ( ) )
86
+ if let Some ( pattern ) = param. pat ( ) {
87
+ let binding = pattern . syntax ( ) . text ( ) . to_string ( ) ;
88
+ file_params. retain ( |_, v| v != & binding) ;
89
+ }
90
90
} )
91
91
}
92
92
@@ -97,13 +97,20 @@ fn should_add_self_completions(ctx: &CompletionContext, param_list: ast::ParamLi
97
97
inside_impl && no_params
98
98
}
99
99
100
- fn surround_with_commas ( ctx : & CompletionContext , param : String ) -> Option < String > {
100
+ fn surround_with_commas ( ctx : & CompletionContext , param : String ) -> String {
101
+ match fallible_surround_with_commas ( ctx, & param) {
102
+ Some ( surrounded) => surrounded,
103
+ // fallback to the original parameter
104
+ None => param,
105
+ }
106
+ }
107
+
108
+ fn fallible_surround_with_commas ( ctx : & CompletionContext , param : & str ) -> Option < String > {
101
109
let next_token = {
102
110
let t = ctx. token . next_token ( ) ?;
103
- if !matches ! ( t. kind( ) , SyntaxKind :: WHITESPACE ) {
104
- t
105
- } else {
106
- t. next_token ( ) ?
111
+ match t. kind ( ) {
112
+ SyntaxKind :: WHITESPACE => t. next_token ( ) ?,
113
+ _ => t,
107
114
}
108
115
} ;
109
116
0 commit comments