Browse Source

Fix line continuation to not continue the first newline leaf

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
806c81be36
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 7
      src/runestone.jl
  2. 4
      test/runtests.jl

7
src/runestone.jl

@ -2061,10 +2061,14 @@ end @@ -2061,10 +2061,14 @@ end
# with a max_depth parameter.
function continue_all_newlines(
ctx::Context, node::Node; skip_last::Bool = true, is_last::Bool = is_leaf(node),
skip_first::Bool = true, is_first::Bool = true,
)
# Not sure these need to arguments since they should always(?) be `true`.
@assert skip_last
@assert skip_first
if is_leaf(node)
if kind(node) === K"NewlineWs" && !has_tag(node, TAG_LINE_CONT) &&
!(skip_last && is_last)
!((skip_last && is_last) || (skip_first && is_first))
return add_tag(node, TAG_LINE_CONT)
else
return nothing
@ -2075,6 +2079,7 @@ function continue_all_newlines( @@ -2075,6 +2079,7 @@ function continue_all_newlines(
for (i, kid) in pairs(kids)
kid′ = continue_all_newlines(
ctx, kid; skip_last = skip_last, is_last = i == lastindex(kids),
skip_first = skip_first, is_first = is_first && i == firstindex(kids),
)
if kid′ !== nothing
kids[i] = kid′

4
test/runtests.jl

@ -688,6 +688,10 @@ end @@ -688,6 +688,10 @@ end
@test format_string("a ?\n$(sp)b :\n$(sp)c") == "a ?\n b :\n c"
@test format_string("a ?\n$(sp)b :\n$(sp)c ?\n$(sp)d : e") ==
"a ?\n b :\n c ?\n d : e"
@test format_string("(\n$(sp)a ? b : c,\n)") ==
"(\n a ? b : c,\n)"
@test format_string("f(\n$(sp)a ? b : c,\n)") ==
"f(\n a ? b : c,\n)"
# comparison
@test format_string("a == b ==\n$(sp)c") == "a == b ==\n c"
@test format_string("a <= b >=\n$(sp)c") == "a <= b >=\n c"

Loading…
Cancel
Save