about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDropDemBits <r3usrlnd@gmail.com>2022-08-18 11:25:13 -0400
committerDropDemBits <r3usrlnd@gmail.com>2022-08-19 09:27:29 -0400
commit7d777759bf5615411496eb9d1f73c5c43540b150 (patch)
treea3315599644473ee132fad477750184070c01c6c
parent6669ea81c329b3c1451132e1139d0a8d0dc3cba0 (diff)
downloadrust-7d777759bf5615411496eb9d1f73c5c43540b150.tar.gz
rust-7d777759bf5615411496eb9d1f73c5c43540b150.zip
Insert newline after extracted struct's attributes
-rw-r--r--crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
index 3738718b3c6..906be27ddbb 100644
--- a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -275,8 +275,14 @@ fn create_struct_def(
     // copy attributes from enum
     ted::insert_all(
         ted::Position::first_child_of(strukt.syntax()),
-        enum_.attrs().map(|it| it.syntax().clone_for_update().into()).collect(),
+        enum_
+            .attrs()
+            .flat_map(|it| {
+                vec![it.syntax().clone_for_update().into(), make::tokens::single_newline().into()]
+            })
+            .collect(),
     );
+
     strukt
 }
 
@@ -458,10 +464,14 @@ enum En<T> { Var(Var<T>) }"#,
     fn test_extract_struct_carries_over_attributes() {
         check_assist(
             extract_struct_from_enum_variant,
-            r#"#[derive(Debug)]
+            r#"
+#[derive(Debug)]
 #[derive(Clone)]
 enum Enum { Variant{ field: u32$0 } }"#,
-            r#"#[derive(Debug)]#[derive(Clone)] struct Variant{ field: u32 }
+            r#"
+#[derive(Debug)]
+#[derive(Clone)]
+struct Variant{ field: u32 }
 
 #[derive(Debug)]
 #[derive(Clone)]