Skip to content

Commit cc725f8

Browse files
committed
Fix not complete 'else' before tuple
Example --- ```rust fn foo() -> (i32, i32) { if foo {} el$0 (2, 3) } ``` **Before this PR** ```rust ... kw crate:: kw false kw for ... ``` **After this PR** ```rust ... kw crate:: kw else kw else if kw false kw for ... ```
1 parent adbff8b commit cc725f8

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,9 +2030,10 @@ fn is_after_if_expr(node: SyntaxNode) -> bool {
20302030
Some(stmt) => stmt.syntax().clone(),
20312031
None => node,
20322032
};
2033-
let prev_sibling =
2034-
non_trivia_sibling(node.into(), Direction::Prev).and_then(NodeOrToken::into_node);
2035-
iter::successors(prev_sibling, |it| it.last_child_or_token()?.into_node())
2033+
let Some(prev_token) = previous_non_trivia_token(node) else { return false };
2034+
prev_token
2035+
.parent_ancestors()
2036+
.take_while(|it| it.text_range().end() == prev_token.text_range().end())
20362037
.find_map(ast::IfExpr::cast)
20372038
.is_some()
20382039
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,32 @@ fn foo() { match () { () => if foo {} $0, _ => (), } }
21822182
kw ref
21832183
"#]],
21842184
);
2185+
check(
2186+
r#"
2187+
fn foo() -> (i32, i32) { if foo {} el$0 (2, 3) }
2188+
"#,
2189+
expect![[r#"
2190+
fn foo fn() -> (i32, i32)
2191+
bt u32 u32
2192+
kw const
2193+
kw crate::
2194+
kw else
2195+
kw else if
2196+
kw false
2197+
kw for
2198+
kw if
2199+
kw if let
2200+
kw loop
2201+
kw match
2202+
kw return
2203+
kw self::
2204+
kw true
2205+
kw unsafe
2206+
kw while
2207+
kw while let
2208+
ex foo()
2209+
"#]],
2210+
);
21852211
// FIXME: support else completion after ast::RecordExprField
21862212
}
21872213

0 commit comments

Comments
 (0)