Fix "add missing impl members" assist for impls inside blocks

This commit is contained in:
Jonas Schievink 2023-01-27 16:51:55 +01:00
parent 0063e89469
commit e7a2d13ff6

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 @@ fn foo(&self) {}
}"#,
)
}
#[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!()}
}
}
}
"#,
);
}
}