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:
@@ -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,
|
||||
} })
|
||||
})
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user