@@ -218,18 +218,20 @@ impl Completions {
218
218
{
219
219
tested_by ! ( inserts_parens_for_function_calls) ;
220
220
221
- let ( snippet, label) =
222
- if params. is_empty ( ) || has_self_param && params. len ( ) == 1 {
223
- ( format ! ( "{}()$0" , name) , format ! ( "{}()" , name) )
224
- } else {
225
- let function_params_snippet =
226
- join ( function_signature. parameter_names . iter ( ) . enumerate ( ) . map (
221
+ let ( snippet, label) = if params. is_empty ( ) || has_self_param && params. len ( ) == 1 {
222
+ ( format ! ( "{}()$0" , name) , format ! ( "{}()" , name) )
223
+ } else {
224
+ let to_skip = if has_self_param { 1 } else { 0 } ;
225
+ let function_params_snippet =
226
+ join (
227
+ function_signature. parameter_names . iter ( ) . skip ( to_skip) . enumerate ( ) . map (
227
228
|( index, param_name) | format ! ( "${{{}:{}}}" , index + 1 , param_name) ,
228
- ) )
229
- . separator ( ", " )
230
- . to_string ( ) ;
231
- ( format ! ( "{}({})$0" , name, function_params_snippet) , format ! ( "{}(…)" , name) )
232
- } ;
229
+ ) ,
230
+ )
231
+ . separator ( ", " )
232
+ . to_string ( ) ;
233
+ ( format ! ( "{}({})$0" , name, function_params_snippet) , format ! ( "{}(…)" , name) )
234
+ } ;
233
235
builder = builder. lookup_by ( name) . label ( label) . insert_snippet ( snippet) ;
234
236
}
235
237
@@ -307,8 +309,8 @@ mod tests {
307
309
308
310
use crate :: completion:: { do_completion, CompletionItem , CompletionKind } ;
309
311
310
- fn do_reference_completion ( code : & str ) -> Vec < CompletionItem > {
311
- do_completion ( code , CompletionKind :: Reference )
312
+ fn do_reference_completion ( ra_fixture : & str ) -> Vec < CompletionItem > {
313
+ do_completion ( ra_fixture , CompletionKind :: Reference )
312
314
}
313
315
314
316
#[ test]
@@ -530,6 +532,36 @@ mod tests {
530
532
) ;
531
533
}
532
534
535
+ #[ test]
536
+ fn parens_for_method_call ( ) {
537
+ assert_debug_snapshot ! (
538
+ do_reference_completion(
539
+ r"
540
+ struct S {}
541
+ impl S {
542
+ fn foo(&self, x: i32) {}
543
+ }
544
+ fn bar(s: &S) {
545
+ s.f<|>
546
+ }
547
+ "
548
+ ) ,
549
+ @r###"
550
+ [
551
+ CompletionItem {
552
+ label: "foo(…)",
553
+ source_range: [171; 172),
554
+ delete: [171; 172),
555
+ insert: "foo(${1:x})$0",
556
+ kind: Method,
557
+ lookup: "foo",
558
+ detail: "fn foo(&self, x: i32)",
559
+ },
560
+ ]
561
+ "###
562
+ )
563
+ }
564
+
533
565
#[ test]
534
566
fn dont_render_function_parens_in_use_item ( ) {
535
567
assert_debug_snapshot ! (
0 commit comments