From e7a2d13ff63c6b16f70f7854a9225de7301e044c Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 27 Jan 2023 16:51:55 +0100 Subject: [PATCH] Fix "add missing impl members" assist for impls inside blocks --- .../src/handlers/add_missing_impl_members.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/crates/ide-assists/src/handlers/add_missing_impl_members.rs index 627a9852fc..4e11b31deb 100644 --- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs @@ -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!()} + } + } +} +"#, + ); + } }