Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs')
-rw-r--r--crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
index 248f18789c..2dec876215 100644
--- a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -139,7 +139,7 @@ fn add_assist(
let trait_path = make::ty_path(replace_trait_path.clone());
match (ctx.config.snippet_cap, impl_def_with_items) {
- (None, _) => {
+ (None, None) => {
let impl_def = generate_trait_impl(adt, trait_path);
ted::insert_all(
@@ -147,6 +147,12 @@ fn add_assist(
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
);
}
+ (None, Some((impl_def, _))) => {
+ ted::insert_all(
+ insert_after,
+ vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
+ );
+ }
(Some(cap), None) => {
let impl_def = generate_trait_impl(adt, trait_path);
@@ -272,7 +278,7 @@ fn update_attribute(
#[cfg(test)]
mod tests {
- use crate::tests::{check_assist, check_assist_not_applicable};
+ use crate::tests::{check_assist, check_assist_no_snippet_cap, check_assist_not_applicable};
use super::*;
@@ -301,6 +307,30 @@ impl core::fmt::Debug for Foo {
)
}
#[test]
+ fn add_custom_impl_without_snippet() {
+ check_assist_no_snippet_cap(
+ replace_derive_with_manual_impl,
+ r#"
+//- minicore: fmt, derive
+#[derive(Debu$0g)]
+struct Foo {
+ bar: String,
+}
+"#,
+ r#"
+struct Foo {
+ bar: String,
+}
+
+impl core::fmt::Debug for Foo {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ f.debug_struct("Foo").field("bar", &self.bar).finish()
+ }
+}
+"#,
+ )
+ }
+ #[test]
fn add_custom_impl_debug_tuple_struct() {
check_assist(
replace_derive_with_manual_impl,