@@ -141,8 +141,8 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
141
141
// }
142
142
//
143
143
// impl Foo for ${1:_} {
144
- // $0fn foo(&self) -> i32 {
145
- // todo !()
144
+ // fn foo(&self) -> i32 {
145
+ // $0todo !()
146
146
// }
147
147
// }
148
148
// ```
@@ -206,8 +206,10 @@ pub(crate) fn generate_impl_trait(acc: &mut Assists, ctx: &AssistContext<'_>) ->
206
206
edit. add_placeholder_snippet ( cap, ty) ;
207
207
}
208
208
209
- if let Some ( item) = impl_. assoc_item_list ( ) . and_then ( |it| it. assoc_items ( ) . next ( ) ) {
210
- edit. add_tabstop_before ( cap, item) ;
209
+ if let Some ( expr) =
210
+ impl_. assoc_item_list ( ) . and_then ( |it| it. assoc_items ( ) . find_map ( extract_expr) )
211
+ {
212
+ edit. add_tabstop_before ( cap, expr) ;
211
213
} else if let Some ( l_curly) =
212
214
impl_. assoc_item_list ( ) . and_then ( |it| it. l_curly_token ( ) )
213
215
{
@@ -220,6 +222,13 @@ pub(crate) fn generate_impl_trait(acc: &mut Assists, ctx: &AssistContext<'_>) ->
220
222
)
221
223
}
222
224
225
+ fn extract_expr ( item : ast:: AssocItem ) -> Option < ast:: Expr > {
226
+ let ast:: AssocItem :: Fn ( f) = item else {
227
+ return None ;
228
+ } ;
229
+ f. body ( ) ?. tail_expr ( )
230
+ }
231
+
223
232
#[ cfg( test) ]
224
233
mod tests {
225
234
use crate :: tests:: { check_assist, check_assist_target} ;
@@ -616,8 +625,8 @@ mod tests {
616
625
}
617
626
618
627
impl Foo for ${1:_} {
619
- $0fn foo(&self) -> i32 {
620
- todo !()
628
+ fn foo(&self) -> i32 {
629
+ $0todo !()
621
630
}
622
631
}
623
632
"# ,
@@ -647,8 +656,8 @@ mod tests {
647
656
}
648
657
649
658
impl Foo<${1:_}> for ${2:_} {
650
- $0fn foo(&self) -> _ {
651
- todo !()
659
+ fn foo(&self) -> _ {
660
+ $0todo !()
652
661
}
653
662
}
654
663
"# ,
@@ -674,8 +683,8 @@ mod tests {
674
683
}
675
684
676
685
impl Foo<${1:_}, ${2:_}> for ${3:_} {
677
- $0fn foo(&self) -> _ {
678
- todo !()
686
+ fn foo(&self) -> _ {
687
+ $0todo !()
679
688
}
680
689
}
681
690
"# ,
@@ -709,8 +718,8 @@ mod tests {
709
718
}
710
719
711
720
impl Foo for ${1:_} {
712
- $0fn foo(&self) -> i32 {
713
- todo !()
721
+ fn foo(&self) -> i32 {
722
+ $0todo !()
714
723
}
715
724
}
716
725
"# ,
@@ -736,10 +745,10 @@ mod tests {
736
745
}
737
746
738
747
impl Foo for ${1:_} {
739
- $0type Output;
748
+ type Output;
740
749
741
750
fn foo(&self) -> Self::Output {
742
- todo !()
751
+ $0todo !()
743
752
}
744
753
}
745
754
"# ,
0 commit comments