mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
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:
commit
261afbdd88
1 changed files with 32 additions and 0 deletions
|
@ -109,6 +109,7 @@ fn add_missing_impl_members_inner(
|
||||||
|
|
||||||
if ctx.token_at_offset().all(|t| {
|
if ctx.token_at_offset().all(|t| {
|
||||||
t.parent_ancestors()
|
t.parent_ancestors()
|
||||||
|
.take_while(|node| node != impl_def.syntax())
|
||||||
.any(|s| ast::BlockExpr::can_cast(s.kind()) || ast::ParamList::can_cast(s.kind()))
|
.any(|s| ast::BlockExpr::can_cast(s.kind()) || ast::ParamList::can_cast(s.kind()))
|
||||||
}) {
|
}) {
|
||||||
return None;
|
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!()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue