Skip to content

Commit 261afbd

Browse files
committed
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
2 parents 0063e89 + e7a2d13 commit 261afbd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/ide-assists/src/handlers/add_missing_impl_members.rs

+32
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ fn add_missing_impl_members_inner(
109109

110110
if ctx.token_at_offset().all(|t| {
111111
t.parent_ancestors()
112+
.take_while(|node| node != impl_def.syntax())
112113
.any(|s| ast::BlockExpr::can_cast(s.kind()) || ast::ParamList::can_cast(s.kind()))
113114
}) {
114115
return None;
@@ -1486,4 +1487,35 @@ impl Trait for () {
14861487
}"#,
14871488
)
14881489
}
1490+
1491+
#[test]
1492+
fn test_works_inside_function() {
1493+
check_assist(
1494+
add_missing_impl_members,
1495+
r#"
1496+
trait Tr {
1497+
fn method();
1498+
}
1499+
fn main() {
1500+
struct S;
1501+
impl Tr for S {
1502+
$0
1503+
}
1504+
}
1505+
"#,
1506+
r#"
1507+
trait Tr {
1508+
fn method();
1509+
}
1510+
fn main() {
1511+
struct S;
1512+
impl Tr for S {
1513+
fn method() {
1514+
${0:todo!()}
1515+
}
1516+
}
1517+
}
1518+
"#,
1519+
);
1520+
}
14891521
}

0 commit comments

Comments
 (0)