about summary refs log tree commit diff
diff options
context:
space:
mode:
author1hakusai1 <1hakusai1@gmail.com>2024-12-12 18:55:14 +0900
committer1hakusai1 <1hakusai1@gmail.com>2024-12-12 18:55:14 +0900
commit41bd955f8eec2c879992feb87da2d17083bce4d2 (patch)
tree9242994aa20435741e47463172823d2dfa10ddde
parent96d97611e2d142752786babd0a89aea48529a328 (diff)
downloadrust-41bd955f8eec2c879992feb87da2d17083bce4d2.tar.gz
rust-41bd955f8eec2c879992feb87da2d17083bce4d2.zip
Generate implementation with items even if snippet text edit is disabled
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
index 248f18789ce..2dec876215c 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/src/tools/rust-analyzer/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,