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.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/ide_assists/src/handlers/extract_type_alias.rs b/crates/ide_assists/src/handlers/extract_type_alias.rs
index 442a209b9..998e0de7b 100644
--- a/crates/ide_assists/src/handlers/extract_type_alias.rs
+++ b/crates/ide_assists/src/handlers/extract_type_alias.rs
@@ -25,7 +25,12 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Opti
25 } 25 }
26 26
27 let node = ctx.find_node_at_range::<ast::Type>()?; 27 let node = ctx.find_node_at_range::<ast::Type>()?;
28 let insert = ctx.find_node_at_offset::<ast::Item>()?.syntax().text_range().start(); 28 let insert = ctx
29 .find_node_at_offset::<ast::Impl>()
30 .map(|imp| imp.syntax().clone())
31 .or_else(|| ctx.find_node_at_offset::<ast::Item>().map(|item| item.syntax().clone()))?
32 .text_range()
33 .start();
29 let target = node.syntax().text_range(); 34 let target = node.syntax().text_range();
30 35
31 acc.add( 36 acc.add(
@@ -146,4 +151,25 @@ struct S {
146 "#, 151 "#,
147 ); 152 );
148 } 153 }
154
155 #[test]
156 fn extract_from_impl() {
157 // When invoked in an impl, extracted type alias should be placed next to the impl, not
158 // inside.
159 check_assist(
160 extract_type_alias,
161 r#"
162impl S {
163 fn f() -> $0(u8, u8)$0 {}
164}
165 "#,
166 r#"
167type $0Type = (u8, u8);
168
169impl S {
170 fn f() -> Type {}
171}
172 "#,
173 );
174 }
149} 175}