Browse Source

Ignore paren-blocks in trailing semicolon trimming

pull/53/head
Fredrik Ekre 1 year ago
parent
commit
3931a4ffe3
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 9
      src/runestone.jl
  2. 3
      test/runtests.jl

9
src/runestone.jl

@ -3302,10 +3302,13 @@ function remove_trailing_semicolon(ctx::Context, node::Node) @@ -3302,10 +3302,13 @@ function remove_trailing_semicolon(ctx::Context, node::Node)
pos = position(ctx.fmt_io)
kids = verified_kids(node)
kids′ = kids
block_idx = findfirst(x -> kind(x) === K"block", kids′)
block_predicate = function(x)
return kind(x) === K"block" && !JuliaSyntax.has_flags(x, JuliaSyntax.PARENS_FLAG)
end
block_idx = findfirst(block_predicate, kids′)
if kind(node) === K"let"
# The first block of let is the variables
block_idx = findnext(x -> kind(x) === K"block", kids′, block_idx + 1)
block_idx = findnext(block_predicate, kids′, block_idx + 1)
end
any_changed = false
while block_idx !== nothing
@ -3323,7 +3326,7 @@ function remove_trailing_semicolon(ctx::Context, node::Node) @@ -3323,7 +3326,7 @@ function remove_trailing_semicolon(ctx::Context, node::Node)
end
seek(ctx.fmt_io, p)
end
block_idx = findnext(x -> kind(x) === K"block", kids′, block_idx + 1)
block_idx = findnext(block_predicate, kids′, block_idx + 1)
end
# Reset the stream and return
seek(ctx.fmt_io, pos)

3
test/runtests.jl

@ -1188,6 +1188,9 @@ end @@ -1188,6 +1188,9 @@ end
@test format_string("$(mut)struct A\na::Int;\nend") ==
"$(mut)struct A\n a::Int\nend"
end
# Paren-blocks should be skipped
@test format_string("if (a;\nb)\nend") == "if (\n a;\n b\n )\nend"
@test format_string("if begin a;\nb; end\nend") == "if begin\n a\n b\n end\nend"
# Top-level semicolons are kept (useful if you want to supress output in various
# contexts)
let str = """

Loading…
Cancel
Save