From 6739652af7499d26def900b63d1b04c56a340a50 Mon Sep 17 00:00:00 2001 From: Giga Bowser <45986823+Giga-Bowser@users.noreply.github.com> Date: Mon, 24 Feb 2025 13:37:06 -0500 Subject: [PATCH] minor: Add tabstop to impl body in `generate_trait_impl` assist --- .../ide-assists/src/handlers/generate_impl.rs | 26 +++++++++++-------- crates/ide-assists/src/tests/generated.rs | 2 +- docs/book/src/assists_generated.md | 4 +-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/ide-assists/src/handlers/generate_impl.rs b/crates/ide-assists/src/handlers/generate_impl.rs index 7b7dac9a3d6c..4439830947ad 100644 --- a/crates/ide-assists/src/handlers/generate_impl.rs +++ b/crates/ide-assists/src/handlers/generate_impl.rs @@ -78,7 +78,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio // data: T, // } // -// impl ${0:_} for Ctx {} +// impl ${1:_} for Ctx {$0} // ``` pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let nominal = ctx.find_node_at_offset::()?; @@ -102,6 +102,10 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> if let Some(trait_) = impl_.trait_() { edit.add_placeholder_snippet(cap, trait_); } + + if let Some(l_curly) = impl_.assoc_item_list().and_then(|it| it.l_curly_token()) { + edit.add_tabstop_after_token(cap, l_curly); + } } insert_impl(impl_, &edit.make_mut(nominal)); @@ -278,7 +282,7 @@ mod tests { r#" struct Foo {} - impl ${0:_} for Foo {} + impl ${1:_} for Foo {$0} "#, ); } @@ -293,7 +297,7 @@ mod tests { r#" struct Foo {} - impl ${0:_} for Foo {} + impl ${1:_} for Foo {$0} "#, ); } @@ -308,7 +312,7 @@ mod tests { r#" struct Foo<'a, T: Foo<'a>> {} - impl<'a, T: Foo<'a>> ${0:_} for Foo<'a, T> {} + impl<'a, T: Foo<'a>> ${1:_} for Foo<'a, T> {$0} "#, ); } @@ -326,7 +330,7 @@ mod tests { struct Foo<'a, T: Foo<'a>> {} #[cfg(feature = "foo")] - impl<'a, T: Foo<'a>> ${0:_} for Foo<'a, T> {} + impl<'a, T: Foo<'a>> ${1:_} for Foo<'a, T> {$0} "#, ); } @@ -341,7 +345,7 @@ mod tests { r#" struct Defaulted {} - impl ${0:_} for Defaulted {} + impl ${1:_} for Defaulted {$0} "#, ); } @@ -356,7 +360,7 @@ mod tests { r#" struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {} - impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b, const S: usize> ${0:_} for Defaulted<'a, 'b, T, S> {} + impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b, const S: usize> ${1:_} for Defaulted<'a, 'b, T, S> {$0} "#, ); } @@ -371,7 +375,7 @@ mod tests { r#" struct Defaulted {} - impl ${0:_} for Defaulted {} + impl ${1:_} for Defaulted {$0} "#, ); } @@ -398,10 +402,10 @@ mod tests { inner: T, } - impl ${0:_} for Struct + impl ${1:_} for Struct where T: Trait, - { + {$0 } "#, ); @@ -476,7 +480,7 @@ mod tests { mod foo { struct Bar {} - impl ${0:_} for Bar {} + impl ${1:_} for Bar {$0} } "#, ); diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index 0662527a387d..74ae126adae8 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -1961,7 +1961,7 @@ struct Ctx { data: T, } -impl ${0:_} for Ctx {} +impl ${1:_} for Ctx {$0} "#####, ) } diff --git a/docs/book/src/assists_generated.md b/docs/book/src/assists_generated.md index 9d68a873ffef..52da98dbd21d 100644 --- a/docs/book/src/assists_generated.md +++ b/docs/book/src/assists_generated.md @@ -280,7 +280,7 @@ fn main() { ### `apply_demorgan_iterator` -**Source:** [apply_demorgan.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/apply_demorgan.rs#L132) +**Source:** [apply_demorgan.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/apply_demorgan.rs#L147) Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) to `Iterator::all` and `Iterator::any`. @@ -2161,7 +2161,7 @@ struct Ctx { data: T, } -impl ${0:_} for Ctx {} +impl ${1:_} for Ctx {┃} ```