@@ -36,8 +36,8 @@ use crate::{
36
36
// bar("", baz());
37
37
// }
38
38
//
39
- // fn bar(arg: &str, baz: Baz) {
40
- // ${0: todo!()}
39
+ // fn bar(arg: &str, baz: Baz) ${0:-> ()} {
40
+ // todo!()
41
41
// }
42
42
//
43
43
// ```
@@ -80,21 +80,19 @@ pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext) -> Optio
80
80
81
81
struct FunctionTemplate {
82
82
insert_offset : TextSize ,
83
- placeholder_expr : ast:: MacroCall ,
84
83
leading_ws : String ,
85
84
fn_def : ast:: Fn ,
85
+ ret_type : ast:: RetType ,
86
86
trailing_ws : String ,
87
87
file : FileId ,
88
88
}
89
89
90
90
impl FunctionTemplate {
91
91
fn to_string ( & self , cap : Option < SnippetCap > ) -> String {
92
92
let f = match cap {
93
- Some ( cap) => render_snippet (
94
- cap,
95
- self . fn_def . syntax ( ) ,
96
- Cursor :: Replace ( self . placeholder_expr . syntax ( ) ) ,
97
- ) ,
93
+ Some ( cap) => {
94
+ render_snippet ( cap, self . fn_def . syntax ( ) , Cursor :: Replace ( self . ret_type . syntax ( ) ) )
95
+ }
98
96
None => self . fn_def . to_string ( ) ,
99
97
} ;
100
98
format ! ( "{}{}{}" , self . leading_ws, f, self . trailing_ws)
@@ -141,8 +139,14 @@ impl FunctionBuilder {
141
139
let placeholder_expr = make:: expr_todo ( ) ;
142
140
let fn_body = make:: block_expr ( vec ! [ ] , Some ( placeholder_expr) ) ;
143
141
let visibility = if self . needs_pub { Some ( make:: visibility_pub_crate ( ) ) } else { None } ;
144
- let mut fn_def =
145
- make:: fn_ ( visibility, self . fn_name , self . type_params , self . params , fn_body) ;
142
+ let mut fn_def = make:: fn_ (
143
+ visibility,
144
+ self . fn_name ,
145
+ self . type_params ,
146
+ self . params ,
147
+ fn_body,
148
+ Some ( make:: ret_type ( make:: ty ( "()" ) ) ) ,
149
+ ) ;
146
150
let leading_ws;
147
151
let trailing_ws;
148
152
@@ -163,12 +167,10 @@ impl FunctionBuilder {
163
167
}
164
168
} ;
165
169
166
- let placeholder_expr =
167
- fn_def. syntax ( ) . descendants ( ) . find_map ( ast:: MacroCall :: cast) . unwrap ( ) ;
168
170
FunctionTemplate {
169
171
insert_offset,
170
- placeholder_expr,
171
172
leading_ws,
173
+ ret_type : fn_def. ret_type ( ) . unwrap ( ) ,
172
174
fn_def,
173
175
trailing_ws,
174
176
file : self . file ,
@@ -349,8 +351,8 @@ fn foo() {
349
351
bar();
350
352
}
351
353
352
- fn bar() {
353
- ${0: todo!()}
354
+ fn bar() ${0:-> ()} {
355
+ todo!()
354
356
}
355
357
" ,
356
358
)
@@ -376,8 +378,8 @@ impl Foo {
376
378
}
377
379
}
378
380
379
- fn bar() {
380
- ${0: todo!()}
381
+ fn bar() ${0:-> ()} {
382
+ todo!()
381
383
}
382
384
" ,
383
385
)
@@ -400,8 +402,8 @@ fn foo1() {
400
402
bar();
401
403
}
402
404
403
- fn bar() {
404
- ${0: todo!()}
405
+ fn bar() ${0:-> ()} {
406
+ todo!()
405
407
}
406
408
407
409
fn foo2() {}
@@ -426,8 +428,8 @@ mod baz {
426
428
bar();
427
429
}
428
430
429
- fn bar() {
430
- ${0: todo!()}
431
+ fn bar() ${0:-> ()} {
432
+ todo!()
431
433
}
432
434
}
433
435
" ,
@@ -452,8 +454,8 @@ fn foo() {
452
454
bar(baz());
453
455
}
454
456
455
- fn bar(baz: Baz) {
456
- ${0: todo!()}
457
+ fn bar(baz: Baz) ${0:-> ()} {
458
+ todo!()
457
459
}
458
460
" ,
459
461
) ;
@@ -485,8 +487,8 @@ impl Baz {
485
487
}
486
488
}
487
489
488
- fn bar(baz: Baz) {
489
- ${0: todo!()}
490
+ fn bar(baz: Baz) ${0:-> ()} {
491
+ todo!()
490
492
}
491
493
" ,
492
494
)
@@ -506,8 +508,8 @@ fn foo() {
506
508
bar("bar")
507
509
}
508
510
509
- fn bar(arg: &str) {
510
- ${0: todo!()}
511
+ fn bar(arg: &str) ${0:-> ()} {
512
+ todo!()
511
513
}
512
514
"# ,
513
515
)
@@ -527,8 +529,8 @@ fn foo() {
527
529
bar('x')
528
530
}
529
531
530
- fn bar(arg: char) {
531
- ${0: todo!()}
532
+ fn bar(arg: char) ${0:-> ()} {
533
+ todo!()
532
534
}
533
535
"# ,
534
536
)
@@ -548,8 +550,8 @@ fn foo() {
548
550
bar(42)
549
551
}
550
552
551
- fn bar(arg: i32) {
552
- ${0: todo!()}
553
+ fn bar(arg: i32) ${0:-> ()} {
554
+ todo!()
553
555
}
554
556
" ,
555
557
)
@@ -569,8 +571,8 @@ fn foo() {
569
571
bar(42 as u8)
570
572
}
571
573
572
- fn bar(arg: u8) {
573
- ${0: todo!()}
574
+ fn bar(arg: u8) ${0:-> ()} {
575
+ todo!()
574
576
}
575
577
" ,
576
578
)
@@ -594,8 +596,8 @@ fn foo() {
594
596
bar(x as u8)
595
597
}
596
598
597
- fn bar(x: u8) {
598
- ${0: todo!()}
599
+ fn bar(x: u8) ${0:-> ()} {
600
+ todo!()
599
601
}
600
602
" ,
601
603
)
@@ -617,8 +619,8 @@ fn foo() {
617
619
bar(worble)
618
620
}
619
621
620
- fn bar(worble: ()) {
621
- ${0: todo!()}
622
+ fn bar(worble: ()) ${0:-> ()} {
623
+ todo!()
622
624
}
623
625
" ,
624
626
)
@@ -646,8 +648,8 @@ fn baz() {
646
648
bar(foo())
647
649
}
648
650
649
- fn bar(foo: impl Foo) {
650
- ${0: todo!()}
651
+ fn bar(foo: impl Foo) ${0:-> ()} {
652
+ todo!()
651
653
}
652
654
" ,
653
655
)
@@ -673,8 +675,8 @@ fn foo() {
673
675
bar(&baz())
674
676
}
675
677
676
- fn bar(baz: &Baz) {
677
- ${0: todo!()}
678
+ fn bar(baz: &Baz) ${0:-> ()} {
679
+ todo!()
678
680
}
679
681
" ,
680
682
)
@@ -702,8 +704,8 @@ fn foo() {
702
704
bar(Baz::baz())
703
705
}
704
706
705
- fn bar(baz: Baz::Bof) {
706
- ${0: todo!()}
707
+ fn bar(baz: Baz::Bof) ${0:-> ()} {
708
+ todo!()
707
709
}
708
710
" ,
709
711
)
@@ -725,8 +727,8 @@ fn foo<T>(t: T) {
725
727
bar(t)
726
728
}
727
729
728
- fn bar<T>(t: T) {
729
- ${0: todo!()}
730
+ fn bar<T>(t: T) ${0:-> ()} {
731
+ todo!()
730
732
}
731
733
" ,
732
734
)
@@ -756,8 +758,8 @@ fn foo() {
756
758
bar(Baz::new);
757
759
}
758
760
759
- fn bar(arg: fn() -> Baz) {
760
- ${0: todo!()}
761
+ fn bar(arg: fn() -> Baz) ${0:-> ()} {
762
+ todo!()
761
763
}
762
764
" ,
763
765
)
@@ -781,8 +783,8 @@ fn foo() {
781
783
bar(closure)
782
784
}
783
785
784
- fn bar(closure: impl Fn(i64) -> i64) {
785
- ${0: todo!()}
786
+ fn bar(closure: impl Fn(i64) -> i64) ${0:-> ()} {
787
+ todo!()
786
788
}
787
789
" ,
788
790
)
@@ -802,8 +804,8 @@ fn foo() {
802
804
bar(baz)
803
805
}
804
806
805
- fn bar(baz: ()) {
806
- ${0: todo!()}
807
+ fn bar(baz: ()) ${0:-> ()} {
808
+ todo!()
807
809
}
808
810
" ,
809
811
)
@@ -827,8 +829,8 @@ fn foo() {
827
829
bar(baz(), baz())
828
830
}
829
831
830
- fn bar(baz_1: Baz, baz_2: Baz) {
831
- ${0: todo!()}
832
+ fn bar(baz_1: Baz, baz_2: Baz) ${0:-> ()} {
833
+ todo!()
832
834
}
833
835
" ,
834
836
)
@@ -852,8 +854,8 @@ fn foo() {
852
854
bar(baz(), baz(), "foo", "bar")
853
855
}
854
856
855
- fn bar(baz_1: Baz, baz_2: Baz, arg_1: &str, arg_2: &str) {
856
- ${0: todo!()}
857
+ fn bar(baz_1: Baz, baz_2: Baz, arg_1: &str, arg_2: &str) ${0:-> ()} {
858
+ todo!()
857
859
}
858
860
"# ,
859
861
)
@@ -872,8 +874,8 @@ fn foo() {
872
874
" ,
873
875
r"
874
876
mod bar {
875
- pub(crate) fn my_fn() {
876
- ${0: todo!()}
877
+ pub(crate) fn my_fn() ${0:-> ()} {
878
+ todo!()
877
879
}
878
880
}
879
881
@@ -911,8 +913,8 @@ fn bar() {
911
913
baz(foo)
912
914
}
913
915
914
- fn baz(foo: foo::Foo) {
915
- ${0: todo!()}
916
+ fn baz(foo: foo::Foo) ${0:-> ()} {
917
+ todo!()
916
918
}
917
919
" ,
918
920
)
@@ -935,8 +937,8 @@ fn foo() {
935
937
mod bar {
936
938
fn something_else() {}
937
939
938
- pub(crate) fn my_fn() {
939
- ${0: todo!()}
940
+ pub(crate) fn my_fn() ${0:-> ()} {
941
+ todo!()
940
942
}
941
943
}
942
944
@@ -963,8 +965,8 @@ fn foo() {
963
965
r"
964
966
mod bar {
965
967
mod baz {
966
- pub(crate) fn my_fn() {
967
- ${0: todo!()}
968
+ pub(crate) fn my_fn() ${0:-> ()} {
969
+ todo!()
968
970
}
969
971
}
970
972
}
@@ -992,8 +994,8 @@ fn main() {
992
994
r"
993
995
994
996
995
- pub(crate) fn bar() {
996
- ${0: todo!()}
997
+ pub(crate) fn bar() ${0:-> ()} {
998
+ todo!()
997
999
}" ,
998
1000
)
999
1001
}
0 commit comments