Skip to content

Commit

Permalink
Fix indent of while-end with K"block" as conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 15, 2024
1 parent eb7f55b commit 2ddbb38
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,8 @@ function indent_loop(ctx::Context, node::Node)
kids[for_idx] = add_tag(kids[for_idx], TAG_INDENT)
any_kid_changed = true
end
block_idx = findnext(x -> kind(x) === K"block", kids, for_idx + 1)::Int
# findlast because the condition can also be a block
block_idx = findlast(x -> kind(x) === K"block", kids)::Int
block_node′ = indent_block(ctx, kids[block_idx])
if block_node′ !== nothing
kids[block_idx] = block_node′
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ end
@test format_string("for i in I, j in J\n$(sp)x\n$(sp)end") == "for i in I, j in J\n x\nend"
# while-end
@test format_string("while x\n$(sp)y\n$(sp)end") == "while x\n y\nend"
@test format_string("while (x = 1; x == 1)\n$(sp)y\n$(sp)end") ==
"while (x = 1; x == 1)\n y\nend"
# try-catch-end
@test format_string("try\n$(sp)x\n$(sp)catch\n$(sp)y\n$(sp)end") ==
"try\n x\ncatch\n y\nend"
Expand Down

0 comments on commit 2ddbb38

Please sign in to comment.