Change tabstop to method tail_expr
diff --git a/crates/ide-assists/src/handlers/generate_impl.rs b/crates/ide-assists/src/handlers/generate_impl.rs
index ba95fe5..e72062b 100644
--- a/crates/ide-assists/src/handlers/generate_impl.rs
+++ b/crates/ide-assists/src/handlers/generate_impl.rs
@@ -141,8 +141,8 @@
// }
//
// impl Foo for ${1:_} {
-// $0fn foo(&self) -> i32 {
-// todo!()
+// fn foo(&self) -> i32 {
+// $0todo!()
// }
// }
// ```
@@ -206,8 +206,10 @@
edit.add_placeholder_snippet(cap, ty);
}
- if let Some(item) = impl_.assoc_item_list().and_then(|it| it.assoc_items().next()) {
- edit.add_tabstop_before(cap, item);
+ if let Some(expr) =
+ impl_.assoc_item_list().and_then(|it| it.assoc_items().find_map(extract_expr))
+ {
+ edit.add_tabstop_before(cap, expr);
} else if let Some(l_curly) =
impl_.assoc_item_list().and_then(|it| it.l_curly_token())
{
@@ -220,6 +222,13 @@
)
}
+fn extract_expr(item: ast::AssocItem) -> Option<ast::Expr> {
+ let ast::AssocItem::Fn(f) = item else {
+ return None;
+ };
+ f.body()?.tail_expr()
+}
+
#[cfg(test)]
mod tests {
use crate::tests::{check_assist, check_assist_target};
@@ -616,8 +625,8 @@
}
impl Foo for ${1:_} {
- $0fn foo(&self) -> i32 {
- todo!()
+ fn foo(&self) -> i32 {
+ $0todo!()
}
}
"#,
@@ -647,8 +656,8 @@
}
impl Foo<${1:_}> for ${2:_} {
- $0fn foo(&self) -> _ {
- todo!()
+ fn foo(&self) -> _ {
+ $0todo!()
}
}
"#,
@@ -674,8 +683,8 @@
}
impl Foo<${1:_}, ${2:_}> for ${3:_} {
- $0fn foo(&self) -> _ {
- todo!()
+ fn foo(&self) -> _ {
+ $0todo!()
}
}
"#,
@@ -709,8 +718,8 @@
}
impl Foo for ${1:_} {
- $0fn foo(&self) -> i32 {
- todo!()
+ fn foo(&self) -> i32 {
+ $0todo!()
}
}
"#,
@@ -736,10 +745,10 @@
}
impl Foo for ${1:_} {
- $0type Output;
+ type Output;
fn foo(&self) -> Self::Output {
- todo!()
+ $0todo!()
}
}
"#,
diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs
index 7c88677..b63571c 100644
--- a/crates/ide-assists/src/tests/generated.rs
+++ b/crates/ide-assists/src/tests/generated.rs
@@ -1895,8 +1895,8 @@
}
impl Foo for ${1:_} {
- $0fn foo(&self) -> i32 {
- todo!()
+ fn foo(&self) -> i32 {
+ $0todo!()
}
}
"#####,