Merge pull request #20513 from A4-Tacks/let-in-let-chain

Add let in let-chain completion support
This commit is contained in:
Chayim Refael Friedman 2025-08-23 22:17:27 +00:00 committed by GitHub
commit 544ef84898
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View file

@ -1176,19 +1176,23 @@ fn classify_name_ref<'db>(
Some(res)
};
let is_in_condition = |it: &ast::Expr| {
fn is_in_condition(it: &ast::Expr) -> bool {
(|| {
let parent = it.syntax().parent()?;
if let Some(expr) = ast::WhileExpr::cast(parent.clone()) {
Some(expr.condition()? == *it)
} else if let Some(expr) = ast::IfExpr::cast(parent) {
} else if let Some(expr) = ast::IfExpr::cast(parent.clone()) {
Some(expr.condition()? == *it)
} else if let Some(expr) = ast::BinExpr::cast(parent)
&& expr.op_token()?.kind() == T![&&]
{
Some(is_in_condition(&expr.into()))
} else {
None
}
})()
.unwrap_or(false)
};
}
let make_path_kind_expr = |expr: ast::Expr| {
let it = expr.syntax();

View file

@ -2622,3 +2622,13 @@ fn foo() {
"#]],
);
}
#[test]
fn let_in_condition() {
check_edit("let", r#"fn f() { if $0 {} }"#, r#"fn f() { if let $1 = $0 {} }"#);
}
#[test]
fn let_in_let_chain() {
check_edit("let", r#"fn f() { if true && $0 {} }"#, r#"fn f() { if true && let $1 = $0 {} }"#);
}