From d8559588c0a38ef1c2cfcb297b520469e6765c80 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sat, 20 Feb 2021 15:05:01 +0100 Subject: fix(assist): display where predicates when we want to generate impl Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/assists/src/handlers/generate_impl.rs | 25 +++++++++++++++++++++++++ crates/assists/src/utils.rs | 9 ++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'crates/assists') diff --git a/crates/assists/src/handlers/generate_impl.rs b/crates/assists/src/handlers/generate_impl.rs index 16a600e6f..a8e3c4fc2 100644 --- a/crates/assists/src/handlers/generate_impl.rs +++ b/crates/assists/src/handlers/generate_impl.rs @@ -122,6 +122,31 @@ mod tests { $0 }"#, ); + + check_assist( + generate_impl, + r#"pub trait Trait {} +struct Struct$0 +where + T: Trait, +{ + inner: T, +}"#, + r#"pub trait Trait {} +struct Struct +where + T: Trait, +{ + inner: T, +} + +impl Struct +where + T: Trait, +{ + $0 +}"#, + ); } #[test] diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 8418e6e12..0074da741 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -421,7 +421,14 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", ")) } - format_to!(buf, " {{\n{}\n}}", code); + match adt.where_clause() { + Some(where_clause) => { + format_to!(buf, "\n{}\n{{\n{}\n}}", where_clause, code); + } + None => { + format_to!(buf, " {{\n{}\n}}", code); + } + } buf } -- cgit v1.2.3