diff options
-rw-r--r-- | crates/ide_assists/src/handlers/extract_type_alias.rs | 37 | ||||
-rw-r--r-- | crates/ide_assists/src/tests/generated.rs | 4 |
2 files changed, 26 insertions, 15 deletions
diff --git a/crates/ide_assists/src/handlers/extract_type_alias.rs b/crates/ide_assists/src/handlers/extract_type_alias.rs index 771868234..171b87918 100644 --- a/crates/ide_assists/src/handlers/extract_type_alias.rs +++ b/crates/ide_assists/src/handlers/extract_type_alias.rs | |||
@@ -16,10 +16,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
16 | // ``` | 16 | // ``` |
17 | // -> | 17 | // -> |
18 | // ``` | 18 | // ``` |
19 | // type Type = (u8, u8, u8); | 19 | // type ${0:Type} = (u8, u8, u8); |
20 | // | 20 | // |
21 | // struct S { | 21 | // struct S { |
22 | // field: Type, | 22 | // field: ${0:Type}, |
23 | // } | 23 | // } |
24 | // ``` | 24 | // ``` |
25 | pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 25 | pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
@@ -56,9 +56,20 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Opti | |||
56 | target, | 56 | target, |
57 | |builder| { | 57 | |builder| { |
58 | builder.edit_file(ctx.frange.file_id); | 58 | builder.edit_file(ctx.frange.file_id); |
59 | // FIXME: add snippet support | 59 | match ctx.config.snippet_cap { |
60 | builder.replace(target, "Type"); | 60 | Some(cap) => { |
61 | builder.insert(insert, format!("type Type = {};\n\n", node)); | 61 | builder.replace_snippet(cap, target, "${0:Type}"); |
62 | builder.insert_snippet( | ||
63 | cap, | ||
64 | insert, | ||
65 | format!("type ${{0:Type}} = {};\n\n", node), | ||
66 | ); | ||
67 | } | ||
68 | None => { | ||
69 | builder.replace(target, "Type"); | ||
70 | builder.insert(insert, format!("type Type = {};\n\n", node)); | ||
71 | } | ||
72 | } | ||
62 | }, | 73 | }, |
63 | ) | 74 | ) |
64 | } | 75 | } |
@@ -91,10 +102,10 @@ struct S { | |||
91 | } | 102 | } |
92 | ", | 103 | ", |
93 | r#" | 104 | r#" |
94 | type Type = u8; | 105 | type ${0:Type} = u8; |
95 | 106 | ||
96 | struct S { | 107 | struct S { |
97 | field: Type, | 108 | field: ${0:Type}, |
98 | } | 109 | } |
99 | "#, | 110 | "#, |
100 | ); | 111 | ); |
@@ -114,10 +125,10 @@ fn f() { | |||
114 | r#" | 125 | r#" |
115 | fn generic<T>() {} | 126 | fn generic<T>() {} |
116 | 127 | ||
117 | type Type = (); | 128 | type ${0:Type} = (); |
118 | 129 | ||
119 | fn f() { | 130 | fn f() { |
120 | generic::<Type>(); | 131 | generic::<${0:Type}>(); |
121 | } | 132 | } |
122 | "#, | 133 | "#, |
123 | ); | 134 | ); |
@@ -135,10 +146,10 @@ struct S { | |||
135 | ", | 146 | ", |
136 | r#" | 147 | r#" |
137 | struct Vec<T> {} | 148 | struct Vec<T> {} |
138 | type Type = Vec<u8>; | 149 | type ${0:Type} = Vec<u8>; |
139 | 150 | ||
140 | struct S { | 151 | struct S { |
141 | v: Vec<Vec<Type>>, | 152 | v: Vec<Vec<${0:Type}>>, |
142 | } | 153 | } |
143 | "#, | 154 | "#, |
144 | ); | 155 | ); |
@@ -154,10 +165,10 @@ struct S { | |||
154 | } | 165 | } |
155 | ", | 166 | ", |
156 | r#" | 167 | r#" |
157 | type Type = u8; | 168 | type ${0:Type} = u8; |
158 | 169 | ||
159 | struct S { | 170 | struct S { |
160 | field: (Type,), | 171 | field: (${0:Type},), |
161 | } | 172 | } |
162 | "#, | 173 | "#, |
163 | ); | 174 | ); |
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index 6bb65e6bc..becd640b1 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 Type = (u8, u8, u8); | 341 | type ${0:Type} = (u8, u8, u8); |
342 | 342 | ||
343 | struct S { | 343 | struct S { |
344 | field: Type, | 344 | field: ${0:Type}, |
345 | } | 345 | } |
346 | "#####, | 346 | "#####, |
347 | ) | 347 | ) |