mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Merge #9111
9111: fix: make "extract type alias" place extracted type alias outside of impl r=jonas-schievink a=jonas-schievink bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
2022cfce44
1 changed files with 27 additions and 1 deletions
|
@ -25,7 +25,12 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Opti
|
|||
}
|
||||
|
||||
let node = ctx.find_node_at_range::<ast::Type>()?;
|
||||
let insert = ctx.find_node_at_offset::<ast::Item>()?.syntax().text_range().start();
|
||||
let insert = ctx
|
||||
.find_node_at_offset::<ast::Impl>()
|
||||
.map(|imp| imp.syntax().clone())
|
||||
.or_else(|| ctx.find_node_at_offset::<ast::Item>().map(|item| item.syntax().clone()))?
|
||||
.text_range()
|
||||
.start();
|
||||
let target = node.syntax().text_range();
|
||||
|
||||
acc.add(
|
||||
|
@ -142,6 +147,27 @@ type $0Type = u8;
|
|||
|
||||
struct S {
|
||||
field: (Type,),
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_from_impl() {
|
||||
// When invoked in an impl, extracted type alias should be placed next to the impl, not
|
||||
// inside.
|
||||
check_assist(
|
||||
extract_type_alias,
|
||||
r#"
|
||||
impl S {
|
||||
fn f() -> $0(u8, u8)$0 {}
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
type $0Type = (u8, u8);
|
||||
|
||||
impl S {
|
||||
fn f() -> Type {}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue