Browse Source

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

pull/86/head
Fredrik Ekre 1 year ago committed by GitHub
parent
commit
e10cd9295a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      src/runestone.jl
  2. 2
      test/runtests.jl

6
src/runestone.jl

@ -2026,6 +2026,12 @@ function indent_block(
if kind(kids′[insert_idx]) === K"Whitespace" if kind(kids′[insert_idx]) === K"Whitespace"
kids′, ws = popatview!(kids′, insert_idx) kids′, ws = popatview!(kids′, insert_idx)
wsspn = span(ws) 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 end
# If we end up in this code path we are most likely splitting a single line block # 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 # into multiples lines. This means that we haven't yet updated the indent level for

2
test/runtests.jl

@ -1135,6 +1135,8 @@ end
for mut in ("", "mutable ") for mut in ("", "mutable ")
@test format_string("$(mut)struct A$(d)x$(d)end") == "$(mut)struct A\n x\nend" @test format_string("$(mut)struct A$(d)x$(d)end") == "$(mut)struct A\n x\nend"
end 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 end # d-loop
# module-end, baremodule-end # module-end, baremodule-end
for b in ("", "bare") for b in ("", "bare")

Loading…
Cancel
Save