@@ -15,16 +15,16 @@ use ide_db::{
15
15
use syntax:: {
16
16
algo:: { find_node_at_offset, non_trivia_sibling} ,
17
17
ast:: { self , AttrKind , HasArgList , HasName , NameOrNameRef } ,
18
- match_ast, AstNode , AstToken , NodeOrToken ,
18
+ match_ast, AstNode , AstToken , Direction , NodeOrToken ,
19
19
SyntaxKind :: { self , * } ,
20
20
SyntaxNode , SyntaxToken , TextRange , TextSize , T ,
21
21
} ;
22
22
use text_edit:: Indel ;
23
23
24
24
use crate :: {
25
25
patterns:: {
26
- determine_location, determine_prev_sibling , is_in_loop_body, is_in_token_of_for_loop,
27
- previous_token , ImmediateLocation , ImmediatePrevSibling ,
26
+ determine_location, is_in_loop_body, is_in_token_of_for_loop, previous_token ,
27
+ ImmediateLocation ,
28
28
} ,
29
29
CompletionConfig ,
30
30
} ;
@@ -48,6 +48,7 @@ pub(super) enum PathKind {
48
48
Expr {
49
49
in_block_expr : bool ,
50
50
in_loop_body : bool ,
51
+ after_if_expr : bool ,
51
52
} ,
52
53
Type {
53
54
in_tuple_struct : bool ,
@@ -264,7 +265,6 @@ pub(crate) struct CompletionContext<'a> {
264
265
pub ( super ) incomplete_let : bool ,
265
266
266
267
pub ( super ) completion_location : Option < ImmediateLocation > ,
267
- pub ( super ) prev_sibling : Option < ImmediatePrevSibling > ,
268
268
pub ( super ) previous_token : Option < SyntaxToken > ,
269
269
270
270
pub ( super ) ident_ctx : IdentContext ,
@@ -345,10 +345,6 @@ impl<'a> CompletionContext<'a> {
345
345
matches ! ( self . completion_location, Some ( ImmediateLocation :: RefExpr ) )
346
346
}
347
347
348
- pub ( crate ) fn after_if ( & self ) -> bool {
349
- matches ! ( self . prev_sibling, Some ( ImmediatePrevSibling :: IfExpr ) )
350
- }
351
-
352
348
// FIXME: This shouldn't exist
353
349
pub ( crate ) fn is_path_disallowed ( & self ) -> bool {
354
350
!self . qualifier_ctx . none ( )
@@ -527,7 +523,6 @@ impl<'a> CompletionContext<'a> {
527
523
impl_def : None ,
528
524
incomplete_let : false ,
529
525
completion_location : None ,
530
- prev_sibling : None ,
531
526
previous_token : None ,
532
527
// dummy value, will be overwritten
533
528
ident_ctx : IdentContext :: UnexpandedAttrTT { fake_attribute_under_caret : None } ,
@@ -922,7 +917,6 @@ impl<'a> CompletionContext<'a> {
922
917
} ;
923
918
self . completion_location =
924
919
determine_location ( & self . sema , original_file, offset, & name_like) ;
925
- self . prev_sibling = determine_prev_sibling ( & name_like) ;
926
920
self . impl_def = self
927
921
. sema
928
922
. token_ancestors_with_macros ( self . token . clone ( ) )
@@ -1169,6 +1163,13 @@ impl<'a> CompletionContext<'a> {
1169
1163
find_node_in_file_compensated ( original_file, & record_expr) . zip ( Some ( true ) ) ;
1170
1164
}
1171
1165
} ;
1166
+ let after_if_expr = |node : SyntaxNode | {
1167
+ let prev_expr = ( || {
1168
+ let prev_sibling = non_trivia_sibling ( node. into ( ) , Direction :: Prev ) ?. into_node ( ) ?;
1169
+ ast:: ExprStmt :: cast ( prev_sibling) ?. expr ( )
1170
+ } ) ( ) ;
1171
+ matches ! ( prev_expr, Some ( ast:: Expr :: IfExpr ( _) ) )
1172
+ } ;
1172
1173
1173
1174
// We do not want to generate path completions when we are sandwiched between an item decl signature and its body.
1174
1175
// ex. trait Foo $0 {}
@@ -1226,7 +1227,9 @@ impl<'a> CompletionContext<'a> {
1226
1227
path_ctx. has_call_parens = it. syntax( ) . parent( ) . map_or( false , |it| ast:: CallExpr :: can_cast( it. kind( ) ) ) ;
1227
1228
let in_block_expr = is_in_block( it. syntax( ) ) ;
1228
1229
let in_loop_body = is_in_loop_body( it. syntax( ) ) ;
1229
- Some ( PathKind :: Expr { in_block_expr, in_loop_body } )
1230
+ let after_if_expr = after_if_expr( it. syntax( ) . clone( ) ) ;
1231
+
1232
+ Some ( PathKind :: Expr { in_block_expr, in_loop_body, after_if_expr } )
1230
1233
} ,
1231
1234
ast:: TupleStructPat ( it) => {
1232
1235
path_ctx. has_call_parens = true ;
@@ -1274,8 +1277,9 @@ impl<'a> CompletionContext<'a> {
1274
1277
return Some ( parent. and_then( ast:: MacroExpr :: cast) . map( |it| {
1275
1278
let in_loop_body = is_in_loop_body( it. syntax( ) ) ;
1276
1279
let in_block_expr = is_in_block( it. syntax( ) ) ;
1280
+ let after_if_expr = after_if_expr( it. syntax( ) . clone( ) ) ;
1277
1281
fill_record_expr( it. syntax( ) ) ;
1278
- PathKind :: Expr { in_block_expr, in_loop_body }
1282
+ PathKind :: Expr { in_block_expr, in_loop_body, after_if_expr }
1279
1283
} ) ) ;
1280
1284
} ,
1281
1285
}
0 commit comments