Skip to content

Commit 66a5fd3

Browse files
Place extracted type alias outside of impl
1 parent dbdfeee commit 66a5fd3

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

crates/ide_assists/src/handlers/extract_type_alias.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Opti
2525
}
2626

2727
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();
2934
let target = node.syntax().text_range();
3035

3136
acc.add(
@@ -142,6 +147,27 @@ type $0Type = u8;
142147
143148
struct S {
144149
field: (Type,),
150+
}
151+
"#,
152+
);
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#"
162+
impl S {
163+
fn f() -> $0(u8, u8)$0 {}
164+
}
165+
"#,
166+
r#"
167+
type $0Type = (u8, u8);
168+
169+
impl S {
170+
fn f() -> Type {}
145171
}
146172
"#,
147173
);

0 commit comments

Comments
 (0)