Process if with colon-delimited body.
(
if_stmt: &'b If<'b>,
body: &'b IfColonDelimitedBody<'b>,
_enclosing_stmt: &'b Statement<'b>,
scope: &mut ScopeState,
ctx: &ForwardWalkCtx<'_>,
)
| 5686 | |
| 5687 | /// Process if with colon-delimited body. |
| 5688 | fn process_if_colon_body<'b>( |
| 5689 | if_stmt: &'b If<'b>, |
| 5690 | body: &'b IfColonDelimitedBody<'b>, |
| 5691 | _enclosing_stmt: &'b Statement<'b>, |
| 5692 | scope: &mut ScopeState, |
| 5693 | ctx: &ForwardWalkCtx<'_>, |
| 5694 | ) { |
| 5695 | // Simplified handling for colon-delimited if. |
| 5696 | // Check if cursor is inside the then-body. |
| 5697 | let then_end = if !body.else_if_clauses.is_empty() { |
| 5698 | body.else_if_clauses |
| 5699 | .first() |
| 5700 | .unwrap() |
| 5701 | .elseif |
| 5702 | .span() |
| 5703 | .start |
| 5704 | .offset |
| 5705 | } else if let Some(ref ec) = body.else_clause { |
| 5706 | ec.r#else.span().start.offset |
| 5707 | } else { |
| 5708 | body.endif.span().start.offset |
| 5709 | }; |
| 5710 | |
| 5711 | let then_start = body.colon.start.offset; |
| 5712 | let cursor_in_then = ctx.cursor_offset >= then_start && ctx.cursor_offset < then_end; |
| 5713 | |
| 5714 | if cursor_in_then { |
| 5715 | apply_condition_narrowing(if_stmt.condition, scope, ctx); |
| 5716 | walk_body_forward(body.statements.iter(), scope, ctx); |
| 5717 | return; |
| 5718 | } |
| 5719 | |
| 5720 | // Check elseif clauses. |
| 5721 | for ei in body.else_if_clauses.iter() { |
| 5722 | let ei_start = ei.colon.start.offset; |
| 5723 | let ei_end = ei |
| 5724 | .statements |
| 5725 | .last() |
| 5726 | .map(|s| s.span().end.offset) |
| 5727 | .unwrap_or(ei_start); |
| 5728 | if ctx.cursor_offset >= ei_start && ctx.cursor_offset <= ei_end { |
| 5729 | apply_condition_narrowing_inverse(if_stmt.condition, scope, ctx); |
| 5730 | apply_condition_narrowing(ei.condition, scope, ctx); |
| 5731 | process_condition_assignment(ei.condition, scope, ctx); |
| 5732 | seed_pass_by_ref_in_condition(ei.condition, scope, ctx); |
| 5733 | walk_body_forward(ei.statements.iter(), scope, ctx); |
| 5734 | return; |
| 5735 | } |
| 5736 | } |
| 5737 | |
| 5738 | // Check else clause. |
| 5739 | if let Some(ref else_clause) = body.else_clause { |
| 5740 | let ec_start = else_clause.colon.start.offset; |
| 5741 | let ec_end = else_clause |
| 5742 | .statements |
| 5743 | .last() |
| 5744 | .map(|s| s.span().end.offset) |
| 5745 | .unwrap_or(ec_start); |
no test coverage detected