From 806c81be368444ef89ac25437199f6a6461d2b54 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sat, 13 Jul 2024 13:53:41 +0200 Subject: [PATCH] Fix line continuation to not continue the first newline leaf --- src/runestone.jl | 7 ++++++- test/runtests.jl | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/runestone.jl b/src/runestone.jl index 0786ec4..5f2bce2 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -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( 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′ diff --git a/test/runtests.jl b/test/runtests.jl index d66ebb6..6364170 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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"