Add let in let-chain completion support
Example
---
```rust
fn f() {
if true && $0 {}
}
```
->
```rust
fn f() {
if true && let $1 = $0 {}
}
```
This commit is contained in:
parent
8e7cca8334
commit
c9fbcdcfcd
2 changed files with 17 additions and 3 deletions
|
|
@ -1171,19 +1171,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();
|
||||
|
|
|
|||
|
|
@ -2275,3 +2275,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 {} }"#);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue