Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e1396bd

Browse files
committed
Don't trigger postfix completion if block which has an else block
Discard postfix completion if the next_non_trivia_sibling of dot_token is an ELSE_KW.
1 parent 8011029 commit e1396bd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

crates/ide-completion/src/completions/postfix.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,4 +747,16 @@ fn main() {
747747
"#,
748748
);
749749
}
750+
751+
#[test]
752+
fn no_postfix_completions_in_if_block_that_has_an_else() {
753+
check(
754+
r#"
755+
fn test() {
756+
if true {}.$0 else {}
757+
}
758+
"#,
759+
expect![[r#""#]],
760+
);
761+
}
750762
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,26 @@ fn classify_name_ref(
605605
},
606606
_ => false,
607607
};
608+
609+
let reciever_is_part_of_indivisible_expression = match &receiver {
610+
Some(ast::Expr::IfExpr(_)) => {
611+
let next_sibling = field.dot_token().and_then(|token| {
612+
let dot_token = original_file.covering_element(token.text_range());
613+
let next_sibling = dot_token.as_token().and_then(|t| t.next_token()).and_then(|t| next_non_trivia_sibling(t.into()));
614+
next_sibling
615+
});
616+
match next_sibling {
617+
Some(syntax::NodeOrToken::Node(n)) => n.first_child_or_token().map(|t| t.kind()) == Some(SyntaxKind::ELSE_KW),
618+
Some(syntax::NodeOrToken::Token(t)) => t.kind() == SyntaxKind::ELSE_KW,
619+
None => false
620+
}
621+
},
622+
_ => false
623+
};
624+
if reciever_is_part_of_indivisible_expression {
625+
return None;
626+
}
627+
608628
let kind = NameRefKind::DotAccess(DotAccess {
609629
receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
610630
kind: DotAccessKind::Field { receiver_is_ambiguous_float_literal },

0 commit comments

Comments
 (0)