Browse Source

Fix a bug with single line comments inside a list

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

7
src/runestone.jl

@ -435,6 +435,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
state = state_after_item(i) state = state_after_item(i)
end end
elseif state === :expect_comma elseif state === :expect_comma
trailing = i > last_item_idx
if kind(kid′) === K"," || (kind(kid′) === K";" && kind(node) === K"bracescat") if kind(kid′) === K"," || (kind(kid′) === K";" && kind(node) === K"bracescat")
before_last_item = i < last_item_idx before_last_item = i < last_item_idx
if before_last_item || expect_trailing_comma if before_last_item || expect_trailing_comma
@ -465,8 +466,8 @@ function spaces_in_listlike(ctx::Context, node::Node)
!JuliaSyntax.is_whitespace, @view(kids[1:closing_leaf_idx - 1]), i + 1, !JuliaSyntax.is_whitespace, @view(kids[1:closing_leaf_idx - 1]), i + 1,
) )
next_kind = next_non_ws_idx === nothing ? nothing : kind(kids[next_non_ws_idx]) next_kind = next_non_ws_idx === nothing ? nothing : kind(kids[next_non_ws_idx])
# Insert a comma # Insert a comma if there isn't one coming
if next_kind !== K"," if trailing && next_kind !== K","
@assert expect_trailing_comma @assert expect_trailing_comma
this_kid_changed = true this_kid_changed = true
if kids′ === kids if kids′ === kids
@ -476,8 +477,6 @@ function spaces_in_listlike(ctx::Context, node::Node)
push!(kids′, comma) push!(kids′, comma)
accept_node!(ctx, comma) accept_node!(ctx, comma)
state = :expect_closing state = :expect_closing
else
@assert false # Unreachable?
end end
any_kid_changed |= this_kid_changed any_kid_changed |= this_kid_changed
# Accept the newline # Accept the newline

5
test/runtests.jl

@ -207,6 +207,11 @@ end
@test format_string("$(f)($(sp)$(a)$(sp),$(sp)$(b)$(sp))") == @test format_string("$(f)($(sp)$(a)$(sp),$(sp)$(b)$(sp))") ==
format_string("$(f)($(sp)$(a)$(sp),$(sp)$(b)$(sp),$(sp))") == format_string("$(f)($(sp)$(a)$(sp),$(sp)$(b)$(sp),$(sp))") ==
"$(f)($(a), $(b))" "$(f)($(a), $(b))"
# comments on the same line
@test format_string("$(f)($(sp)$(a)$(sp), #==#$(sp)$(b)$(sp))") ==
"$(f)($(a), #==# $(b))"
@test format_string("$(f)($(sp)$(a) #==#,$(sp)$(b)$(sp))") ==
"$(f)($(a) #==#, $(b))"
# line break in between items # line break in between items
@test format_string("$(f)($(sp)$(a)$(sp),\n$(sp)$(b)$(sp))") == @test format_string("$(f)($(sp)$(a)$(sp),\n$(sp)$(b)$(sp))") ==
format_string("$(f)($(sp)$(a)$(sp),\n$(sp)$(b)$(sp),$(sp))") == format_string("$(f)($(sp)$(a)$(sp),\n$(sp)$(b)$(sp),$(sp))") ==

Loading…
Cancel
Save