Fix not complete let before expr in condition

Example
---
```rust
fn f() {
    if $0foo.bar() {}
}
```

**Before this PR**

"let" not in completion list

**After this PR**

```rust
fn f() {
    if let $1 = $0foo.bar() {}
}
```
This commit is contained in:
A4-Tacks
2025-10-25 15:24:37 +08:00
parent 1796ced6a9
commit 5fda166acf
2 changed files with 8 additions and 0 deletions

View File

@@ -460,6 +460,8 @@ pub(crate) fn is_in_condition(it: &ast::Expr) -> bool {
ast::MatchGuard(guard) => guard.condition()? == *it,
ast::BinExpr(bin_expr) => (bin_expr.op_token()?.kind() == T![&&])
.then(|| is_in_condition(&bin_expr.into()))?,
ast::Expr(expr) => (expr.syntax().text_range().start() == it.syntax().text_range().start())
.then(|| is_in_condition(&expr))?,
_ => return None,
} })
})

View File

@@ -3268,6 +3268,12 @@ fn foo() -> (i32, i32) {
#[test]
fn let_in_condition() {
check_edit("let", r#"fn f() { if $0 {} }"#, r#"fn f() { if let $1 = $0 {} }"#);
check_edit("let", r#"fn f() { if $0x {} }"#, r#"fn f() { if let $1 = $0x {} }"#);
check_edit(
"let",
r#"fn f() { if $0foo.bar() {} }"#,
r#"fn f() { if let $1 = $0foo.bar() {} }"#,
);
}
#[test]