aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r--crates/ide_assists/src/handlers/extract_type_alias.rs29
1 files changed, 12 insertions, 17 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// ```
22pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 22pub(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#"
83type ${0:Type} = u8; 78type $0Type = u8;
84 79
85struct S { 80struct S {
86 field: ${0:Type}, 81 field: Type,
87} 82}
88 "#, 83 "#,
89 ); 84 );
@@ -103,10 +98,10 @@ fn f() {
103 r#" 98 r#"
104fn generic<T>() {} 99fn generic<T>() {}
105 100
106type ${0:Type} = (); 101type $0Type = ();
107 102
108fn f() { 103fn 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#"
126struct Vec<T> {} 121struct Vec<T> {}
127type ${0:Type} = Vec<u8>; 122type $0Type = Vec<u8>;
128 123
129struct S { 124struct 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#"
146type ${0:Type} = u8; 141type $0Type = u8;
147 142
148struct S { 143struct S {
149 field: (${0:Type},), 144 field: (Type,),
150} 145}
151 "#, 146 "#,
152 ); 147 );