@@ -134,8 +134,8 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
134
134
// }
135
135
//
136
136
// impl Foo for ${1:_} {
137
- // $0fn foo(&self) -> i32 {
138
- // todo !()
137
+ // fn foo(&self) -> i32 {
138
+ // $0todo !()
139
139
// }
140
140
// }
141
141
// ```
@@ -199,8 +199,10 @@ pub(crate) fn generate_impl_trait(acc: &mut Assists, ctx: &AssistContext<'_>) ->
199
199
edit. add_placeholder_snippet ( cap, ty) ;
200
200
}
201
201
202
- if let Some ( item) = impl_. assoc_item_list ( ) . and_then ( |it| it. assoc_items ( ) . next ( ) ) {
203
- edit. add_tabstop_before ( cap, item) ;
202
+ if let Some ( expr) =
203
+ impl_. assoc_item_list ( ) . and_then ( |it| it. assoc_items ( ) . find_map ( extract_expr) )
204
+ {
205
+ edit. add_tabstop_before ( cap, expr) ;
204
206
} else if let Some ( l_curly) =
205
207
impl_. assoc_item_list ( ) . and_then ( |it| it. l_curly_token ( ) )
206
208
{
@@ -213,6 +215,13 @@ pub(crate) fn generate_impl_trait(acc: &mut Assists, ctx: &AssistContext<'_>) ->
213
215
)
214
216
}
215
217
218
+ fn extract_expr ( item : ast:: AssocItem ) -> Option < ast:: Expr > {
219
+ let ast:: AssocItem :: Fn ( f) = item else {
220
+ return None ;
221
+ } ;
222
+ f. body ( ) ?. tail_expr ( )
223
+ }
224
+
216
225
#[ cfg( test) ]
217
226
mod tests {
218
227
use crate :: tests:: { check_assist, check_assist_target} ;
@@ -609,8 +618,8 @@ mod tests {
609
618
}
610
619
611
620
impl Foo for ${1:_} {
612
- $0fn foo(&self) -> i32 {
613
- todo !()
621
+ fn foo(&self) -> i32 {
622
+ $0todo !()
614
623
}
615
624
}
616
625
"# ,
@@ -640,8 +649,8 @@ mod tests {
640
649
}
641
650
642
651
impl Foo<${1:_}> for ${2:_} {
643
- $0fn foo(&self) -> _ {
644
- todo !()
652
+ fn foo(&self) -> _ {
653
+ $0todo !()
645
654
}
646
655
}
647
656
"# ,
@@ -667,8 +676,8 @@ mod tests {
667
676
}
668
677
669
678
impl Foo<${1:_}, ${2:_}> for ${3:_} {
670
- $0fn foo(&self) -> _ {
671
- todo !()
679
+ fn foo(&self) -> _ {
680
+ $0todo !()
672
681
}
673
682
}
674
683
"# ,
@@ -702,8 +711,8 @@ mod tests {
702
711
}
703
712
704
713
impl Foo for ${1:_} {
705
- $0fn foo(&self) -> i32 {
706
- todo !()
714
+ fn foo(&self) -> i32 {
715
+ $0todo !()
707
716
}
708
717
}
709
718
"# ,
@@ -729,10 +738,10 @@ mod tests {
729
738
}
730
739
731
740
impl Foo for ${1:_} {
732
- $0type Output;
741
+ type Output;
733
742
734
743
fn foo(&self) -> Self::Output {
735
- todo !()
744
+ $0todo !()
736
745
}
737
746
}
738
747
"# ,
0 commit comments