Skip to content

Commit

Permalink
Fix line continuation to not continue the first newline leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 13, 2024
1 parent b523eda commit 806c81b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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′
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 806c81b

Please sign in to comment.