Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single line block unnesting with hidden whitespace, closes #79 #85

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading