fix: Don't add braces to 'if' completion in match guard position

When the cursor is in a match arm, but before the fat arrow (=>) token, don't
add braces when autocompleting "if".

fixes #12823
This commit is contained in:
Dorian Scheidt 2022-07-22 19:06:14 -05:00
parent 0b131bc78e
commit 13c83f90ac
4 changed files with 88 additions and 1 deletions

View file

@ -763,6 +763,13 @@ impl<'a> CompletionContext<'a> {
.map_or(false, |it| it.semicolon_token().is_none());
let impl_ = fetch_immediate_impl(sema, original_file, expr.syntax());
let in_match_guard = match it.parent().and_then(ast::MatchArm::cast) {
Some(arm) => arm
.fat_arrow_token()
.map_or(true, |arrow| it.text_range().start() < arrow.text_range().start()),
None => false,
};
PathKind::Expr {
expr_ctx: ExprCtx {
in_block_expr,
@ -775,6 +782,7 @@ impl<'a> CompletionContext<'a> {
self_param,
incomplete_let,
impl_,
in_match_guard,
},
}
};