Skip to content

Commit 544ef84

Browse files
Merge pull request #20513 from A4-Tacks/let-in-let-chain
Add let in let-chain completion support
2 parents 71662e4 + 6a7a0fa commit 544ef84

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

crates/ide-completion/src/context/analysis.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,19 +1176,23 @@ fn classify_name_ref<'db>(
11761176
Some(res)
11771177
};
11781178

1179-
let is_in_condition = |it: &ast::Expr| {
1179+
fn is_in_condition(it: &ast::Expr) -> bool {
11801180
(|| {
11811181
let parent = it.syntax().parent()?;
11821182
if let Some(expr) = ast::WhileExpr::cast(parent.clone()) {
11831183
Some(expr.condition()? == *it)
1184-
} else if let Some(expr) = ast::IfExpr::cast(parent) {
1184+
} else if let Some(expr) = ast::IfExpr::cast(parent.clone()) {
11851185
Some(expr.condition()? == *it)
1186+
} else if let Some(expr) = ast::BinExpr::cast(parent)
1187+
&& expr.op_token()?.kind() == T![&&]
1188+
{
1189+
Some(is_in_condition(&expr.into()))
11861190
} else {
11871191
None
11881192
}
11891193
})()
11901194
.unwrap_or(false)
1191-
};
1195+
}
11921196

11931197
let make_path_kind_expr = |expr: ast::Expr| {
11941198
let it = expr.syntax();

crates/ide-completion/src/tests/expression.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,3 +2622,13 @@ fn foo() {
26222622
"#]],
26232623
);
26242624
}
2625+
2626+
#[test]
2627+
fn let_in_condition() {
2628+
check_edit("let", r#"fn f() { if $0 {} }"#, r#"fn f() { if let $1 = $0 {} }"#);
2629+
}
2630+
2631+
#[test]
2632+
fn let_in_let_chain() {
2633+
check_edit("let", r#"fn f() { if true && $0 {} }"#, r#"fn f() { if true && let $1 = $0 {} }"#);
2634+
}

0 commit comments

Comments
 (0)