From ecb15ca7173a6d416c9f74af06f71cf003cdd597 Mon Sep 17 00:00:00 2001 From: Mihail Mihov Date: Wed, 9 Nov 2022 23:43:07 +0200 Subject: [PATCH 1/3] Add assist to generate trait impl's --- .../src/handlers/generate_trait_impl.rs | 226 ++++++++++++++++++ crates/ide-assists/src/lib.rs | 2 + crates/ide-assists/src/tests/generated.rs | 21 ++ 3 files changed, 249 insertions(+) create mode 100644 crates/ide-assists/src/handlers/generate_trait_impl.rs diff --git a/crates/ide-assists/src/handlers/generate_trait_impl.rs b/crates/ide-assists/src/handlers/generate_trait_impl.rs new file mode 100644 index 0000000000..7b1ee5b5c3 --- /dev/null +++ b/crates/ide-assists/src/handlers/generate_trait_impl.rs @@ -0,0 +1,226 @@ +use syntax::ast::{self, AstNode, HasName}; + +use crate::{utils::generate_trait_impl_text, AssistContext, AssistId, AssistKind, Assists}; + +// Assist: generate_trait_impl +// +// Adds a new trait impl for a type. +// +// ``` +// struct $0Ctx { +// data: T, +// } +// ``` +// -> +// ``` +// struct Ctx { +// data: T, +// } +// +// impl $0 for Ctx { +// +// } +// ``` +pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { + let nominal = ctx.find_node_at_offset::()?; + let name = nominal.name()?; + let target = nominal.syntax().text_range(); + + if let Some(_) = ctx.find_node_at_offset::() { + return None; + } + + acc.add( + AssistId("generate_trait_impl", AssistKind::Generate), + format!("Generate trait impl for `{name}`"), + target, + |edit| { + let start_offset = nominal.syntax().text_range().end(); + match ctx.config.snippet_cap { + Some(cap) => { + let snippet = generate_trait_impl_text(&nominal, "$0", ""); + edit.insert_snippet(cap, start_offset, snippet); + } + None => { + let text = generate_trait_impl_text(&nominal, "", ""); + edit.insert(start_offset, text); + } + } + }, + ) +} + +#[cfg(test)] +mod tests { + use crate::tests::{check_assist, check_assist_target}; + + use super::*; + + #[test] + fn test_add_trait_impl() { + check_assist( + generate_trait_impl, + r#" + struct Foo$0 {} + "#, + r#" + struct Foo {} + + impl $0 for Foo { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_generics() { + check_assist( + generate_trait_impl, + r#" + struct Foo$0 {} + "#, + r#" + struct Foo {} + + impl $0 for Foo { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_generics_and_lifetime_parameters() { + check_assist( + generate_trait_impl, + r#" + struct Foo<'a, T: Foo<'a>>$0 {} + "#, + r#" + struct Foo<'a, T: Foo<'a>> {} + + impl<'a, T: Foo<'a>> $0 for Foo<'a, T> { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_attributes() { + check_assist( + generate_trait_impl, + r#" + #[cfg(feature = "foo")] + struct Foo<'a, T: Foo$0<'a>> {} + "#, + r#" + #[cfg(feature = "foo")] + struct Foo<'a, T: Foo<'a>> {} + + #[cfg(feature = "foo")] + impl<'a, T: Foo<'a>> $0 for Foo<'a, T> { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_default_generic() { + check_assist( + generate_trait_impl, + r#" + struct Defaulted$0 {} + "#, + r#" + struct Defaulted {} + + impl $0 for Defaulted { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_constrained_default_generic() { + check_assist( + generate_trait_impl, + r#" + struct Defaulted$0<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {} + "#, + 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> { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_const_defaulted_generic() { + check_assist( + generate_trait_impl, + r#" + struct Defaulted$0 {} + "#, + r#" + struct Defaulted {} + + impl $0 for Defaulted { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_trait_constraint() { + check_assist( + generate_trait_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 $0 for Struct + where + T: Trait, + { + + } + "#, + ); + } + + #[test] + fn add_trait_impl_target() { + check_assist_target( + generate_trait_impl, + r#" + struct SomeThingIrrelevant; + /// Has a lifetime parameter + struct Foo$0<'a, T: Foo<'a>> {} + struct EvenMoreIrrelevant; + "#, + "/// Has a lifetime parameter\nstruct Foo<'a, T: Foo<'a>> {}", + ); + } +} diff --git a/crates/ide-assists/src/lib.rs b/crates/ide-assists/src/lib.rs index 387cc63142..e3c483cf0a 100644 --- a/crates/ide-assists/src/lib.rs +++ b/crates/ide-assists/src/lib.rs @@ -152,6 +152,7 @@ mod handlers { mod generate_function; mod generate_getter; mod generate_impl; + mod generate_trait_impl; mod generate_is_empty_from_len; mod generate_new; mod generate_setter; @@ -247,6 +248,7 @@ mod handlers { generate_from_impl_for_enum::generate_from_impl_for_enum, generate_function::generate_function, generate_impl::generate_impl, + generate_trait_impl::generate_trait_impl, generate_is_empty_from_len::generate_is_empty_from_len, generate_new::generate_new, inline_call::inline_call, diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index c09317572a..67657b61bb 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -1341,6 +1341,27 @@ impl Person { ) } +#[test] +fn doctest_generate_trait_impl() { + check_doc_test( + "generate_trait_impl", + r#####" +struct $0Ctx { + data: T, +} +"#####, + r#####" +struct Ctx { + data: T, +} + +impl $0 for Ctx { + +} +"#####, + ) +} + #[test] fn doctest_inline_call() { check_doc_test( From 0bd11f817136f372b30a328ccf71c0bb0c68ef21 Mon Sep 17 00:00:00 2001 From: Mihail Mihov Date: Thu, 10 Nov 2022 00:01:29 +0200 Subject: [PATCH 2/3] Reduce trigger range of `generate_impl` assist and update tests --- .../ide-assists/src/handlers/generate_impl.rs | 280 ++++++++++-------- crates/ide-assists/src/tests/generated.rs | 4 +- 2 files changed, 160 insertions(+), 124 deletions(-) diff --git a/crates/ide-assists/src/handlers/generate_impl.rs b/crates/ide-assists/src/handlers/generate_impl.rs index 9af26c04eb..1bea220f38 100644 --- a/crates/ide-assists/src/handlers/generate_impl.rs +++ b/crates/ide-assists/src/handlers/generate_impl.rs @@ -7,8 +7,8 @@ use crate::{utils::generate_impl_text, AssistContext, AssistId, AssistKind, Assi // Adds a new inherent impl for a type. // // ``` -// struct Ctx { -// data: T,$0 +// struct Ctx$0 { +// data: T, // } // ``` // -> @@ -26,6 +26,10 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio let name = nominal.name()?; let target = nominal.syntax().text_range(); + if let Some(_) = ctx.find_node_at_offset::() { + return None; + } + acc.add( AssistId("generate_impl", AssistKind::Generate), format!("Generate impl for `{name}`"), @@ -52,139 +56,171 @@ mod tests { use super::*; - // FIXME: break up into separate test fns #[test] fn test_add_impl() { - check_assist( - generate_impl, - "struct Foo {$0}\n", - "struct Foo {}\n\nimpl Foo {\n $0\n}\n", - ); - check_assist( - generate_impl, - "struct Foo {$0}", - "struct Foo {}\n\nimpl Foo {\n $0\n}", - ); - check_assist( - generate_impl, - "struct Foo<'a, T: Foo<'a>> {$0}", - "struct Foo<'a, T: Foo<'a>> {}\n\nimpl<'a, T: Foo<'a>> Foo<'a, T> {\n $0\n}", - ); check_assist( generate_impl, r#" - struct MyOwnArray {}$0"#, + struct Foo$0 {} + "#, r#" - struct MyOwnArray {} + struct Foo {} - impl MyOwnArray { - $0 - }"#, - ); - check_assist( - generate_impl, - r#" - #[cfg(feature = "foo")] - struct Foo<'a, T: Foo<'a>> {$0}"#, - r#" - #[cfg(feature = "foo")] - struct Foo<'a, T: Foo<'a>> {} - - #[cfg(feature = "foo")] - impl<'a, T: Foo<'a>> Foo<'a, T> { - $0 - }"#, - ); - - check_assist( - generate_impl, - r#" - #[cfg(not(feature = "foo"))] - struct Foo<'a, T: Foo<'a>> {$0}"#, - r#" - #[cfg(not(feature = "foo"))] - struct Foo<'a, T: Foo<'a>> {} - - #[cfg(not(feature = "foo"))] - impl<'a, T: Foo<'a>> Foo<'a, T> { - $0 - }"#, - ); - - check_assist( - generate_impl, - r#" - struct Defaulted {}$0"#, - r#" - struct Defaulted {} - - impl Defaulted { - $0 - }"#, - ); - - check_assist( - generate_impl, - r#" - struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {}$0"#, - 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> Defaulted<'a, 'b, T, S> { - $0 - }"#, - ); - - check_assist( - generate_impl, - r#" - struct Defaulted {}$0"#, - r#" - struct Defaulted {} - - impl Defaulted { - $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 -}"#, + impl Foo { + $0 + } + "#, ); } #[test] - fn add_impl_target() { + fn test_add_impl_with_generics() { + check_assist( + generate_impl, + r#" + struct Foo$0 {} + "#, + r#" + struct Foo {} + + impl Foo { + $0 + } + "#, + ); + } + + #[test] + fn test_add_impl_with_generics_and_lifetime_parameters() { + check_assist( + generate_impl, + r#" + struct Foo<'a, T: Foo<'a>>$0 {} + "#, + r#" + struct Foo<'a, T: Foo<'a>> {} + + impl<'a, T: Foo<'a>> Foo<'a, T> { + $0 + } + "#, + ); + } + + #[test] + fn test_add_impl_with_attributes() { + check_assist( + generate_impl, + r#" + #[cfg(feature = "foo")] + struct Foo<'a, T: Foo$0<'a>> {} + "#, + r#" + #[cfg(feature = "foo")] + struct Foo<'a, T: Foo<'a>> {} + + #[cfg(feature = "foo")] + impl<'a, T: Foo<'a>> Foo<'a, T> { + $0 + } + "#, + ); + } + + #[test] + fn test_add_impl_with_default_generic() { + check_assist( + generate_impl, + r#" + struct Defaulted$0 {} + "#, + r#" + struct Defaulted {} + + impl Defaulted { + $0 + } + "#, + ); + } + + #[test] + fn test_add_impl_with_constrained_default_generic() { + check_assist( + generate_impl, + r#" + struct Defaulted$0<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {} + "#, + 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> Defaulted<'a, 'b, T, S> { + $0 + } + "#, + ); + } + + #[test] + fn test_add_impl_with_const_defaulted_generic() { + check_assist( + generate_impl, + r#" + struct Defaulted$0 {} + "#, + r#" + struct Defaulted {} + + impl Defaulted { + $0 + } + "#, + ); + } + + #[test] + fn test_add_impl_with_trait_constraint() { + 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] + fn add_trait_impl_target() { check_assist_target( generate_impl, - " -struct SomeThingIrrelevant; -/// Has a lifetime parameter -struct Foo<'a, T: Foo<'a>> {$0} -struct EvenMoreIrrelevant; -", - "/// Has a lifetime parameter -struct Foo<'a, T: Foo<'a>> {}", + r#" + struct SomeThingIrrelevant; + /// Has a lifetime parameter + struct Foo$0<'a, T: Foo<'a>> {} + struct EvenMoreIrrelevant; + "#, + "/// Has a lifetime parameter\nstruct Foo<'a, T: Foo<'a>> {}", ); } } diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index 67657b61bb..d797f07767 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -1249,8 +1249,8 @@ fn doctest_generate_impl() { check_doc_test( "generate_impl", r#####" -struct Ctx { - data: T,$0 +struct Ctx$0 { + data: T, } "#####, r#####" From 469f620b064d2935c741222927dc955da395532b Mon Sep 17 00:00:00 2001 From: Mihail Mihov Date: Mon, 21 Nov 2022 22:58:01 +0200 Subject: [PATCH 3/3] Combine `generate_impl` and `generate_trait_impl` into a single file --- .../ide-assists/src/handlers/generate_impl.rs | 223 ++++++++++++++++- .../src/handlers/generate_trait_impl.rs | 226 ------------------ crates/ide-assists/src/lib.rs | 3 +- 3 files changed, 222 insertions(+), 230 deletions(-) delete mode 100644 crates/ide-assists/src/handlers/generate_trait_impl.rs diff --git a/crates/ide-assists/src/handlers/generate_impl.rs b/crates/ide-assists/src/handlers/generate_impl.rs index 1bea220f38..690c97e26d 100644 --- a/crates/ide-assists/src/handlers/generate_impl.rs +++ b/crates/ide-assists/src/handlers/generate_impl.rs @@ -1,6 +1,9 @@ use syntax::ast::{self, AstNode, HasName}; -use crate::{utils::generate_impl_text, AssistContext, AssistId, AssistKind, Assists}; +use crate::{ + utils::{generate_impl_text, generate_trait_impl_text}, + AssistContext, AssistId, AssistKind, Assists, +}; // Assist: generate_impl // @@ -50,6 +53,54 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio ) } +// Assist: generate_trait_impl +// +// Adds a new trait impl for a type. +// +// ``` +// struct $0Ctx { +// data: T, +// } +// ``` +// -> +// ``` +// struct Ctx { +// data: T, +// } +// +// impl $0 for Ctx { +// +// } +// ``` +pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { + let nominal = ctx.find_node_at_offset::()?; + let name = nominal.name()?; + let target = nominal.syntax().text_range(); + + if let Some(_) = ctx.find_node_at_offset::() { + return None; + } + + acc.add( + AssistId("generate_trait_impl", AssistKind::Generate), + format!("Generate trait impl for `{name}`"), + target, + |edit| { + let start_offset = nominal.syntax().text_range().end(); + match ctx.config.snippet_cap { + Some(cap) => { + let snippet = generate_trait_impl_text(&nominal, "$0", ""); + edit.insert_snippet(cap, start_offset, snippet); + } + None => { + let text = generate_trait_impl_text(&nominal, "", ""); + edit.insert(start_offset, text); + } + } + }, + ) +} + #[cfg(test)] mod tests { use crate::tests::{check_assist, check_assist_target}; @@ -211,7 +262,7 @@ mod tests { } #[test] - fn add_trait_impl_target() { + fn add_impl_target() { check_assist_target( generate_impl, r#" @@ -223,4 +274,172 @@ mod tests { "/// Has a lifetime parameter\nstruct Foo<'a, T: Foo<'a>> {}", ); } + + #[test] + fn test_add_trait_impl() { + check_assist( + generate_trait_impl, + r#" + struct Foo$0 {} + "#, + r#" + struct Foo {} + + impl $0 for Foo { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_generics() { + check_assist( + generate_trait_impl, + r#" + struct Foo$0 {} + "#, + r#" + struct Foo {} + + impl $0 for Foo { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_generics_and_lifetime_parameters() { + check_assist( + generate_trait_impl, + r#" + struct Foo<'a, T: Foo<'a>>$0 {} + "#, + r#" + struct Foo<'a, T: Foo<'a>> {} + + impl<'a, T: Foo<'a>> $0 for Foo<'a, T> { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_attributes() { + check_assist( + generate_trait_impl, + r#" + #[cfg(feature = "foo")] + struct Foo<'a, T: Foo$0<'a>> {} + "#, + r#" + #[cfg(feature = "foo")] + struct Foo<'a, T: Foo<'a>> {} + + #[cfg(feature = "foo")] + impl<'a, T: Foo<'a>> $0 for Foo<'a, T> { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_default_generic() { + check_assist( + generate_trait_impl, + r#" + struct Defaulted$0 {} + "#, + r#" + struct Defaulted {} + + impl $0 for Defaulted { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_constrained_default_generic() { + check_assist( + generate_trait_impl, + r#" + struct Defaulted$0<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {} + "#, + 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> { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_const_defaulted_generic() { + check_assist( + generate_trait_impl, + r#" + struct Defaulted$0 {} + "#, + r#" + struct Defaulted {} + + impl $0 for Defaulted { + + } + "#, + ); + } + + #[test] + fn test_add_trait_impl_with_trait_constraint() { + check_assist( + generate_trait_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 $0 for Struct + where + T: Trait, + { + + } + "#, + ); + } + + #[test] + fn add_trait_impl_target() { + check_assist_target( + generate_trait_impl, + r#" + struct SomeThingIrrelevant; + /// Has a lifetime parameter + struct Foo$0<'a, T: Foo<'a>> {} + struct EvenMoreIrrelevant; + "#, + "/// Has a lifetime parameter\nstruct Foo<'a, T: Foo<'a>> {}", + ); + } } diff --git a/crates/ide-assists/src/handlers/generate_trait_impl.rs b/crates/ide-assists/src/handlers/generate_trait_impl.rs deleted file mode 100644 index 7b1ee5b5c3..0000000000 --- a/crates/ide-assists/src/handlers/generate_trait_impl.rs +++ /dev/null @@ -1,226 +0,0 @@ -use syntax::ast::{self, AstNode, HasName}; - -use crate::{utils::generate_trait_impl_text, AssistContext, AssistId, AssistKind, Assists}; - -// Assist: generate_trait_impl -// -// Adds a new trait impl for a type. -// -// ``` -// struct $0Ctx { -// data: T, -// } -// ``` -// -> -// ``` -// struct Ctx { -// data: T, -// } -// -// impl $0 for Ctx { -// -// } -// ``` -pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { - let nominal = ctx.find_node_at_offset::()?; - let name = nominal.name()?; - let target = nominal.syntax().text_range(); - - if let Some(_) = ctx.find_node_at_offset::() { - return None; - } - - acc.add( - AssistId("generate_trait_impl", AssistKind::Generate), - format!("Generate trait impl for `{name}`"), - target, - |edit| { - let start_offset = nominal.syntax().text_range().end(); - match ctx.config.snippet_cap { - Some(cap) => { - let snippet = generate_trait_impl_text(&nominal, "$0", ""); - edit.insert_snippet(cap, start_offset, snippet); - } - None => { - let text = generate_trait_impl_text(&nominal, "", ""); - edit.insert(start_offset, text); - } - } - }, - ) -} - -#[cfg(test)] -mod tests { - use crate::tests::{check_assist, check_assist_target}; - - use super::*; - - #[test] - fn test_add_trait_impl() { - check_assist( - generate_trait_impl, - r#" - struct Foo$0 {} - "#, - r#" - struct Foo {} - - impl $0 for Foo { - - } - "#, - ); - } - - #[test] - fn test_add_trait_impl_with_generics() { - check_assist( - generate_trait_impl, - r#" - struct Foo$0 {} - "#, - r#" - struct Foo {} - - impl $0 for Foo { - - } - "#, - ); - } - - #[test] - fn test_add_trait_impl_with_generics_and_lifetime_parameters() { - check_assist( - generate_trait_impl, - r#" - struct Foo<'a, T: Foo<'a>>$0 {} - "#, - r#" - struct Foo<'a, T: Foo<'a>> {} - - impl<'a, T: Foo<'a>> $0 for Foo<'a, T> { - - } - "#, - ); - } - - #[test] - fn test_add_trait_impl_with_attributes() { - check_assist( - generate_trait_impl, - r#" - #[cfg(feature = "foo")] - struct Foo<'a, T: Foo$0<'a>> {} - "#, - r#" - #[cfg(feature = "foo")] - struct Foo<'a, T: Foo<'a>> {} - - #[cfg(feature = "foo")] - impl<'a, T: Foo<'a>> $0 for Foo<'a, T> { - - } - "#, - ); - } - - #[test] - fn test_add_trait_impl_with_default_generic() { - check_assist( - generate_trait_impl, - r#" - struct Defaulted$0 {} - "#, - r#" - struct Defaulted {} - - impl $0 for Defaulted { - - } - "#, - ); - } - - #[test] - fn test_add_trait_impl_with_constrained_default_generic() { - check_assist( - generate_trait_impl, - r#" - struct Defaulted$0<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {} - "#, - 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> { - - } - "#, - ); - } - - #[test] - fn test_add_trait_impl_with_const_defaulted_generic() { - check_assist( - generate_trait_impl, - r#" - struct Defaulted$0 {} - "#, - r#" - struct Defaulted {} - - impl $0 for Defaulted { - - } - "#, - ); - } - - #[test] - fn test_add_trait_impl_with_trait_constraint() { - check_assist( - generate_trait_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 $0 for Struct - where - T: Trait, - { - - } - "#, - ); - } - - #[test] - fn add_trait_impl_target() { - check_assist_target( - generate_trait_impl, - r#" - struct SomeThingIrrelevant; - /// Has a lifetime parameter - struct Foo$0<'a, T: Foo<'a>> {} - struct EvenMoreIrrelevant; - "#, - "/// Has a lifetime parameter\nstruct Foo<'a, T: Foo<'a>> {}", - ); - } -} diff --git a/crates/ide-assists/src/lib.rs b/crates/ide-assists/src/lib.rs index e3c483cf0a..b12f99cc53 100644 --- a/crates/ide-assists/src/lib.rs +++ b/crates/ide-assists/src/lib.rs @@ -152,7 +152,6 @@ mod handlers { mod generate_function; mod generate_getter; mod generate_impl; - mod generate_trait_impl; mod generate_is_empty_from_len; mod generate_new; mod generate_setter; @@ -248,7 +247,7 @@ mod handlers { generate_from_impl_for_enum::generate_from_impl_for_enum, generate_function::generate_function, generate_impl::generate_impl, - generate_trait_impl::generate_trait_impl, + generate_impl::generate_trait_impl, generate_is_empty_from_len::generate_is_empty_from_len, generate_new::generate_new, inline_call::inline_call,