diff options
-rw-r--r-- | crates/ide_assists/src/handlers/extract_type_alias.rs | 29 | ||||
-rw-r--r-- | crates/ide_assists/src/tests/generated.rs | 4 |
2 files changed, 14 insertions, 19 deletions
diff --git a/crates/ide_assists/src/handlers/extract_type_alias.rs b/crates/ide_assists/src/handlers/extract_type_alias.rs index f75d35462..442a209b9 100644 --- a/crates/ide_assists/src/handlers/extract_type_alias.rs +++ b/crates/ide_assists/src/handlers/extract_type_alias.rs | |||
@@ -13,10 +13,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
13 | // ``` | 13 | // ``` |
14 | // -> | 14 | // -> |
15 | // ``` | 15 | // ``` |
16 | // type ${0:Type} = (u8, u8, u8); | 16 | // type $0Type = (u8, u8, u8); |
17 | // | 17 | // |
18 | // struct S { | 18 | // struct S { |
19 | // field: ${0:Type}, | 19 | // field: Type, |
20 | // } | 20 | // } |
21 | // ``` | 21 | // ``` |
22 | pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 22 | pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
@@ -34,17 +34,12 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Opti | |||
34 | target, | 34 | target, |
35 | |builder| { | 35 | |builder| { |
36 | builder.edit_file(ctx.frange.file_id); | 36 | builder.edit_file(ctx.frange.file_id); |
37 | builder.replace(target, "Type"); | ||
37 | match ctx.config.snippet_cap { | 38 | match ctx.config.snippet_cap { |
38 | Some(cap) => { | 39 | Some(cap) => { |
39 | builder.replace_snippet(cap, target, "${0:Type}"); | 40 | builder.insert_snippet(cap, insert, format!("type $0Type = {};\n\n", node)); |
40 | builder.insert_snippet( | ||
41 | cap, | ||
42 | insert, | ||
43 | format!("type ${{0:Type}} = {};\n\n", node), | ||
44 | ); | ||
45 | } | 41 | } |
46 | None => { | 42 | None => { |
47 | builder.replace(target, "Type"); | ||
48 | builder.insert(insert, format!("type Type = {};\n\n", node)); | 43 | builder.insert(insert, format!("type Type = {};\n\n", node)); |
49 | } | 44 | } |
50 | } | 45 | } |
@@ -80,10 +75,10 @@ struct S { | |||
80 | } | 75 | } |
81 | ", | 76 | ", |
82 | r#" | 77 | r#" |
83 | type ${0:Type} = u8; | 78 | type $0Type = u8; |
84 | 79 | ||
85 | struct S { | 80 | struct S { |
86 | field: ${0:Type}, | 81 | field: Type, |
87 | } | 82 | } |
88 | "#, | 83 | "#, |
89 | ); | 84 | ); |
@@ -103,10 +98,10 @@ fn f() { | |||
103 | r#" | 98 | r#" |
104 | fn generic<T>() {} | 99 | fn generic<T>() {} |
105 | 100 | ||
106 | type ${0:Type} = (); | 101 | type $0Type = (); |
107 | 102 | ||
108 | fn f() { | 103 | fn f() { |
109 | generic::<${0:Type}>(); | 104 | generic::<Type>(); |
110 | } | 105 | } |
111 | "#, | 106 | "#, |
112 | ); | 107 | ); |
@@ -124,10 +119,10 @@ struct S { | |||
124 | ", | 119 | ", |
125 | r#" | 120 | r#" |
126 | struct Vec<T> {} | 121 | struct Vec<T> {} |
127 | type ${0:Type} = Vec<u8>; | 122 | type $0Type = Vec<u8>; |
128 | 123 | ||
129 | struct S { | 124 | struct S { |
130 | v: Vec<Vec<${0:Type}>>, | 125 | v: Vec<Vec<Type>>, |
131 | } | 126 | } |
132 | "#, | 127 | "#, |
133 | ); | 128 | ); |
@@ -143,10 +138,10 @@ struct S { | |||
143 | } | 138 | } |
144 | ", | 139 | ", |
145 | r#" | 140 | r#" |
146 | type ${0:Type} = u8; | 141 | type $0Type = u8; |
147 | 142 | ||
148 | struct S { | 143 | struct S { |
149 | field: (${0:Type},), | 144 | field: (Type,), |
150 | } | 145 | } |
151 | "#, | 146 | "#, |
152 | ); | 147 | ); |
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index becd640b1..03b7fb366 100644 --- a/crates/ide_assists/src/tests/generated.rs +++ b/crates/ide_assists/src/tests/generated.rs | |||
@@ -338,10 +338,10 @@ struct S { | |||
338 | } | 338 | } |
339 | "#####, | 339 | "#####, |
340 | r#####" | 340 | r#####" |
341 | type ${0:Type} = (u8, u8, u8); | 341 | type $0Type = (u8, u8, u8); |
342 | 342 | ||
343 | struct S { | 343 | struct S { |
344 | field: ${0:Type}, | 344 | field: Type, |
345 | } | 345 | } |
346 | "#####, | 346 | "#####, |
347 | ) | 347 | ) |