Skip to content

Commit

Permalink
Merge pull request #19221 from Giga-Bowser/generate-trait-impl-tabstop
Browse files Browse the repository at this point in the history
minor: Add tabstop to impl body in `generate_trait_impl` assist
  • Loading branch information
lnicola authored Feb 24, 2025
2 parents f6edb71 + 6739652 commit 3bb49be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions crates/ide-assists/src/handlers/generate_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
// data: T,
// }
//
// impl<T: Clone> ${0:_} for Ctx<T> {}
// impl<T: Clone> ${1:_} for Ctx<T> {$0}
// ```
pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let nominal = ctx.find_node_at_offset::<ast::Adt>()?;
Expand All @@ -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));
Expand Down Expand Up @@ -278,7 +282,7 @@ mod tests {
r#"
struct Foo {}
impl ${0:_} for Foo {}
impl ${1:_} for Foo {$0}
"#,
);
}
Expand All @@ -293,7 +297,7 @@ mod tests {
r#"
struct Foo<T: Clone> {}
impl<T: Clone> ${0:_} for Foo<T> {}
impl<T: Clone> ${1:_} for Foo<T> {$0}
"#,
);
}
Expand All @@ -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}
"#,
);
}
Expand All @@ -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}
"#,
);
}
Expand All @@ -341,7 +345,7 @@ mod tests {
r#"
struct Defaulted<T = i32> {}
impl<T> ${0:_} for Defaulted<T> {}
impl<T> ${1:_} for Defaulted<T> {$0}
"#,
);
}
Expand All @@ -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}
"#,
);
}
Expand All @@ -371,7 +375,7 @@ mod tests {
r#"
struct Defaulted<const N: i32 = 0> {}
impl<const N: i32> ${0:_} for Defaulted<N> {}
impl<const N: i32> ${1:_} for Defaulted<N> {$0}
"#,
);
}
Expand All @@ -398,10 +402,10 @@ mod tests {
inner: T,
}
impl<T> ${0:_} for Struct<T>
impl<T> ${1:_} for Struct<T>
where
T: Trait,
{
{$0
}
"#,
);
Expand Down Expand Up @@ -476,7 +480,7 @@ mod tests {
mod foo {
struct Bar {}
impl ${0:_} for Bar {}
impl ${1:_} for Bar {$0}
}
"#,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/tests/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ struct Ctx<T: Clone> {
data: T,
}
impl<T: Clone> ${0:_} for Ctx<T> {}
impl<T: Clone> ${1:_} for Ctx<T> {$0}
"#####,
)
}
Expand Down
4 changes: 2 additions & 2 deletions docs/book/src/assists_generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -2161,7 +2161,7 @@ struct Ctx<T: Clone> {
data: T,
}

impl<T: Clone> ${0:_} for Ctx<T> {}
impl<T: Clone> ${1:_} for Ctx<T> {}
```


Expand Down

0 comments on commit 3bb49be

Please sign in to comment.