@@ -9,7 +9,7 @@ use crate::completion::{
9
9
CompletionContext , CompletionItem , CompletionItemKind , CompletionKind , Completions ,
10
10
} ;
11
11
12
- use crate :: display:: { const_label, function_label , macro_label, type_label} ;
12
+ use crate :: display:: { const_label, macro_label, type_label, FunctionSignature } ;
13
13
14
14
impl Completions {
15
15
pub ( crate ) fn add_field (
@@ -198,7 +198,7 @@ impl Completions {
198
198
199
199
let name = name. unwrap_or_else ( || func. name ( ctx. db ) . to_string ( ) ) ;
200
200
let ast_node = func. source ( ctx. db ) . value ;
201
- let detail = function_label ( & ast_node) ;
201
+ let function_signature = FunctionSignature :: from ( & ast_node) ;
202
202
203
203
let mut builder =
204
204
CompletionItem :: new ( CompletionKind :: Reference , ctx. source_range ( ) , name. clone ( ) )
@@ -209,19 +209,27 @@ impl Completions {
209
209
} )
210
210
. set_documentation ( func. docs ( ctx. db ) )
211
211
. set_deprecated ( is_deprecated ( func, ctx. db ) )
212
- . detail ( detail ) ;
212
+ . detail ( function_signature . to_string ( ) ) ;
213
213
214
214
// Add `<>` for generic types
215
215
if ctx. use_item_syntax . is_none ( )
216
216
&& !ctx. is_call
217
217
&& ctx. db . feature_flags . get ( "completion.insertion.add-call-parenthesis" )
218
218
{
219
219
tested_by ! ( inserts_parens_for_function_calls) ;
220
- let ( snippet, label) = if params. is_empty ( ) || has_self_param && params. len ( ) == 1 {
221
- ( format ! ( "{}()$0" , name) , format ! ( "{}()" , name) )
222
- } else {
223
- ( format ! ( "{}($0)" , name) , format ! ( "{}(…)" , name) )
224
- } ;
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 (
227
+ |( index, param_name) | format ! ( "${{{}:{}}}" , index + 1 , param_name) ,
228
+ ) )
229
+ . separator ( ", " )
230
+ . to_string ( ) ;
231
+ ( format ! ( "{}({})$0" , name, function_params_snippet) , format ! ( "{}(…)" , name) )
232
+ } ;
225
233
builder = builder. lookup_by ( name) . label ( label) . insert_snippet ( snippet) ;
226
234
}
227
235
@@ -486,7 +494,7 @@ mod tests {
486
494
label: "with_args(…)",
487
495
source_range: [80; 85),
488
496
delete: [80; 85),
489
- insert: "with_args($0) ",
497
+ insert: "with_args(${1:x}, ${2:y})$0 ",
490
498
kind: Function,
491
499
lookup: "with_args",
492
500
detail: "fn with_args(x: i32, y: String)",
@@ -630,7 +638,7 @@ mod tests {
630
638
label: "foo(…)",
631
639
source_range: [61; 63),
632
640
delete: [61; 63),
633
- insert: "foo($0) ",
641
+ insert: "foo(${1:xs})$0 ",
634
642
kind: Function,
635
643
lookup: "foo",
636
644
detail: "fn foo(xs: Ve)",
@@ -659,7 +667,7 @@ mod tests {
659
667
label: "foo(…)",
660
668
source_range: [64; 66),
661
669
delete: [64; 66),
662
- insert: "foo($0) ",
670
+ insert: "foo(${1:xs})$0 ",
663
671
kind: Function,
664
672
lookup: "foo",
665
673
detail: "fn foo(xs: Ve)",
@@ -687,7 +695,7 @@ mod tests {
687
695
label: "foo(…)",
688
696
source_range: [68; 70),
689
697
delete: [68; 70),
690
- insert: "foo($0) ",
698
+ insert: "foo(${1:xs})$0 ",
691
699
kind: Function,
692
700
lookup: "foo",
693
701
detail: "fn foo(xs: Ve)",
@@ -715,7 +723,7 @@ mod tests {
715
723
label: "foo(…)",
716
724
source_range: [61; 63),
717
725
delete: [61; 63),
718
- insert: "foo($0) ",
726
+ insert: "foo(${1:xs})$0 ",
719
727
kind: Function,
720
728
lookup: "foo",
721
729
detail: "fn foo(xs: Ve<i128>)",
0 commit comments