aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r--crates/ra_assists/src/handlers/add_from_impl_for_enum.rs25
1 files changed, 11 insertions, 14 deletions
diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
index 275184e24..6a49b7dbd 100644
--- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
+++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
@@ -1,8 +1,5 @@
1use ra_ide_db::RootDatabase; 1use ra_ide_db::RootDatabase;
2use ra_syntax::{ 2use ra_syntax::ast::{self, AstNode, NameOwner};
3 ast::{self, AstNode, NameOwner},
4 TextSize,
5};
6use stdx::format_to; 3use stdx::format_to;
7use test_utils::tested_by; 4use test_utils::tested_by;
8 5
@@ -69,7 +66,6 @@ impl From<{0}> for {1} {{
69 variant_name 66 variant_name
70 ); 67 );
71 edit.insert(start_offset, buf); 68 edit.insert(start_offset, buf);
72 edit.set_cursor(start_offset + TextSize::of("\n\n"));
73 }, 69 },
74 ) 70 )
75} 71}
@@ -97,19 +93,20 @@ fn existing_from_impl(
97 93
98#[cfg(test)] 94#[cfg(test)]
99mod tests { 95mod tests {
100 use super::*; 96 use test_utils::covers;
101 97
102 use crate::tests::{check_assist, check_assist_not_applicable}; 98 use crate::tests::{check_assist, check_assist_not_applicable};
103 use test_utils::covers; 99
100 use super::*;
104 101
105 #[test] 102 #[test]
106 fn test_add_from_impl_for_enum() { 103 fn test_add_from_impl_for_enum() {
107 check_assist( 104 check_assist(
108 add_from_impl_for_enum, 105 add_from_impl_for_enum,
109 "enum A { <|>One(u32) }", 106 "enum A { <|>One(u32) }",
110 r#"enum A { One(u32) } 107 r#"enum A { <|>One(u32) }
111 108
112<|>impl From<u32> for A { 109impl From<u32> for A {
113 fn from(v: u32) -> Self { 110 fn from(v: u32) -> Self {
114 A::One(v) 111 A::One(v)
115 } 112 }
@@ -121,10 +118,10 @@ mod tests {
121 fn test_add_from_impl_for_enum_complicated_path() { 118 fn test_add_from_impl_for_enum_complicated_path() {
122 check_assist( 119 check_assist(
123 add_from_impl_for_enum, 120 add_from_impl_for_enum,
124 "enum A { <|>One(foo::bar::baz::Boo) }", 121 r#"enum A { <|>One(foo::bar::baz::Boo) }"#,
125 r#"enum A { One(foo::bar::baz::Boo) } 122 r#"enum A { <|>One(foo::bar::baz::Boo) }
126 123
127<|>impl From<foo::bar::baz::Boo> for A { 124impl From<foo::bar::baz::Boo> for A {
128 fn from(v: foo::bar::baz::Boo) -> Self { 125 fn from(v: foo::bar::baz::Boo) -> Self {
129 A::One(v) 126 A::One(v)
130 } 127 }
@@ -184,9 +181,9 @@ impl From<String> for A {
184pub trait From<T> { 181pub trait From<T> {
185 fn from(T) -> Self; 182 fn from(T) -> Self;
186}"#, 183}"#,
187 r#"enum A { One(u32), Two(String), } 184 r#"enum A { <|>One(u32), Two(String), }
188 185
189<|>impl From<u32> for A { 186impl From<u32> for A {
190 fn from(v: u32) -> Self { 187 fn from(v: u32) -> Self {
191 A::One(v) 188 A::One(v)
192 } 189 }