Browse Source

Fix indentation of `let` with comments after variable block

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

14
src/runestone.jl

@ -1317,12 +1317,12 @@ function indent_let(ctx::Context, node::Node) @@ -1317,12 +1317,12 @@ function indent_let(ctx::Context, node::Node)
if span(vars_node) > 0 && length(verified_kids(vars_node)) > 0
@assert kind(last_leaf(vars_node)) !== "NewlineWs"
end
# Third node is the NewlineWs before the block
ln_idx = 3
ln_node = kids[ln_idx]
@assert is_leaf(ln_node) && kind(ln_node) === K"NewlineWs"
# # Third node is the NewlineWs before the block
# ln_idx = 3
# ln_node = kids[ln_idx]
# @assert is_leaf(ln_node) && kind(ln_node) === K"NewlineWs"
# Fourth node is the function body block.
block_idx = 4
block_idx = findnext(x -> kind(x) === K"block", kids, vars_idx + 1)::Int
block_node = kids[block_idx]
@assert !is_leaf(block_node) && kind(block_node) === K"block"
block_node′ = indent_block(ctx, block_node)
@ -1330,8 +1330,8 @@ function indent_let(ctx::Context, node::Node) @@ -1330,8 +1330,8 @@ function indent_let(ctx::Context, node::Node)
kids[block_idx] = block_node′
any_kid_changed = true
end
# Fifth node is the closing end keyword
end_idx = 5
# Next node is the closing end keyword
end_idx = block_idx + 1
@assert is_leaf(kids[end_idx]) && kind(kids[end_idx]) === K"end"
if !has_tag(kids[end_idx], TAG_DEDENT)
kids[end_idx] = add_tag(kids[end_idx], TAG_DEDENT)

8
test/runtests.jl

@ -450,10 +450,10 @@ end @@ -450,10 +450,10 @@ end
@test format_string("macro f()\n$(sp)x\n$(sp)end") ==
"macro f()\n x\nend"
# let-end
@test format_string("let a = 1\n$(sp)x\n$(sp)end") ==
"let a = 1\n x\nend"
@test format_string("let\n$(sp)x\n$(sp)end") ==
"let\n x\nend"
@test format_string("let a = 1\n$(sp)x\n$(sp)end") == "let a = 1\n x\nend"
@test format_string("let\n$(sp)x\n$(sp)end") == "let\n x\nend"
@test format_string("let a = 1 # a\n$(sp)x\n$(sp)end") ==
"let a = 1 # a\n x\nend"
# begin-end
@test format_string("begin\n$(sp)x\n$(sp)end") ==
"begin\n x\nend"

Loading…
Cancel
Save