Skip to content

Commit

Permalink
Fix single line block unnesting with hidden whitespace, closes #79 (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Oct 28, 2024
1 parent 63433c6 commit e10cd92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,12 @@ function indent_block(
if kind(kids′[insert_idx]) === K"Whitespace"
kids′, ws = popatview!(kids′, insert_idx)
wsspn = span(ws)
elseif !is_leaf(kids′[insert_idx]) &&
kind(first_leaf(kids′[insert_idx])) === K"Whitespace"
ws = first_leaf(kids′[insert_idx])
kids′[insert_idx] = replace_first_leaf(kids′[insert_idx], nullnode)
any_kid_changed = true
wsspn = span(ws)
end
# If we end up in this code path we are most likely splitting a single line block
# into multiples lines. This means that we haven't yet updated the indent level for
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,8 @@ end
for mut in ("", "mutable ")
@test format_string("$(mut)struct A$(d)x$(d)end") == "$(mut)struct A\n x\nend"
end
# https://github.com/fredrikekre/Runic.jl/issues/79
@test format_string("while true$(d)x += 1\nend") == "while true\n x += 1\nend"
end # d-loop
# module-end, baremodule-end
for b in ("", "bare")
Expand Down

0 comments on commit e10cd92

Please sign in to comment.