File tree 2 files changed +40
-0
lines changed
crates/ide-completion/src
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -747,4 +747,16 @@ fn main() {
747
747
"# ,
748
748
) ;
749
749
}
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
+ }
750
762
}
Original file line number Diff line number Diff line change @@ -605,6 +605,18 @@ fn classify_name_ref(
605
605
} ,
606
606
_ => false ,
607
607
} ;
608
+
609
+ let reciever_is_part_of_indivisible_expression = match & receiver {
610
+ Some ( ast:: Expr :: IfExpr ( _) ) => {
611
+ let next_token_kind = next_non_trivia_token( name_ref. syntax( ) . clone( ) ) . map( |t| t. kind( ) ) ;
612
+ next_token_kind == Some ( SyntaxKind :: ELSE_KW )
613
+ } ,
614
+ _ => false
615
+ } ;
616
+ if reciever_is_part_of_indivisible_expression {
617
+ return None ;
618
+ }
619
+
608
620
let kind = NameRefKind :: DotAccess ( DotAccess {
609
621
receiver_ty: receiver. as_ref( ) . and_then( |it| sema. type_of_expr( it) ) ,
610
622
kind: DotAccessKind :: Field { receiver_is_ambiguous_float_literal } ,
@@ -1317,6 +1329,22 @@ fn previous_non_trivia_token(e: impl Into<SyntaxElement>) -> Option<SyntaxToken>
1317
1329
None
1318
1330
}
1319
1331
1332
+ fn next_non_trivia_token ( e : impl Into < SyntaxElement > ) -> Option < SyntaxToken > {
1333
+ let mut token = match e. into ( ) {
1334
+ SyntaxElement :: Node ( n) => n. last_token ( ) ?,
1335
+ SyntaxElement :: Token ( t) => t,
1336
+ }
1337
+ . next_token ( ) ;
1338
+ while let Some ( inner) = token {
1339
+ if !inner. kind ( ) . is_trivia ( ) {
1340
+ return Some ( inner) ;
1341
+ } else {
1342
+ token = inner. next_token ( ) ;
1343
+ }
1344
+ }
1345
+ None
1346
+ }
1347
+
1320
1348
fn next_non_trivia_sibling ( ele : SyntaxElement ) -> Option < SyntaxElement > {
1321
1349
let mut e = ele. next_sibling_or_token ( ) ;
1322
1350
while let Some ( inner) = e {
You can’t perform that action at this time.
0 commit comments