Auto merge of #14039 - jonas-schievink:add-missing-impl-members-in-blocks, r=jonas-schievink

fix: Fix "add missing impl members" assist for impls inside blocks
This commit is contained in:
bors 2023-01-27 15:52:59 +00:00
commit 261afbdd88

View file

@ -109,6 +109,7 @@ fn add_missing_impl_members_inner(
if ctx.token_at_offset().all(|t| {
t.parent_ancestors()
.take_while(|node| node != impl_def.syntax())
.any(|s| ast::BlockExpr::can_cast(s.kind()) || ast::ParamList::can_cast(s.kind()))
}) {
return None;
@ -1486,4 +1487,35 @@ impl Trait for () {
}"#,
)
}
#[test]
fn test_works_inside_function() {
check_assist(
add_missing_impl_members,
r#"
trait Tr {
fn method();
}
fn main() {
struct S;
impl Tr for S {
$0
}
}
"#,
r#"
trait Tr {
fn method();
}
fn main() {
struct S;
impl Tr for S {
fn method() {
${0:todo!()}
}
}
}
"#,
);
}
}