Skip to content

Commit

Permalink
Properly indent dotcalls
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jun 14, 2024
1 parent bf1e035 commit b119641
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ function indent_if(ctx::Context, node::Node)
end

function indent_call(ctx::Context, node::Node)
@assert kind(node) === K"call"
@assert kind(node) in KSet"call dotcall"
return indent_paren(ctx, node)
end

Expand Down Expand Up @@ -895,7 +895,7 @@ end

# Mark opening and closing parentheses, in a call or a tuple, with indent and dedent tags.
function indent_paren(ctx::Context, node::Node)
@assert kind(node) in KSet"call tuple parens"
@assert kind(node) in KSet"call dotcall tuple parens"
kids = verified_kids(node)
opening_paren_idx = findfirst(x -> kind(x) === K"(", kids)::Int
closing_paren_idx = findnext(x -> kind(x) === K")", kids, opening_paren_idx + 1)::Int
Expand Down Expand Up @@ -1147,7 +1147,7 @@ function insert_delete_mark_newlines(ctx::Context, node::Node)
return indent_let(ctx, node)
elseif is_begin_block(node)
return indent_begin(ctx, node)
elseif kind(node) === K"call" && flags(node) == 0
elseif kind(node) in KSet"call dotcall" && flags(node) == 0 # TODO: Why the flag check?
return indent_call(ctx, node)
elseif is_infix_op_call(node)
return indent_op_call(ctx, node)
Expand Down
26 changes: 15 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,22 @@ end
@test format_string("(a,\n$(sp)b\n$(sp))") == "(a,\n b\n)"
@test format_string("(a,\n$(sp)b,\n$(sp))") == "(a,\n b,\n)"
@test format_string("(\n$(sp)a,\n$(sp)b,\n$(sp))") == "(\n a,\n b,\n)"
# call
for sep in (",", ";")
@test format_string("f(a$(sep)\n$(sp)b)") == "f(a$(sep)\n b)"
@test format_string("f(a$(sep)\n$(sp)b\n$(sp))") == "f(a$(sep)\n b\n)"
@test format_string("f(a$(sep)\n$(sp)b,\n$(sp))") == "f(a$(sep)\n b,\n)"
@test format_string("f(\n$(sp)a$(sep)\n$(sp)b,\n$(sp))") == "f(\n a$(sep)\n b,\n)"
# call, dotcall
for sep in (",", ";"), d in ("", ".")
@test format_string("f$(d)(a$(sep)\n$(sp)b)") == "f$(d)(a$(sep)\n b)"
@test format_string("f$(d)(a$(sep)\n$(sp)b\n$(sp))") == "f$(d)(a$(sep)\n b\n)"
@test format_string("f$(d)(a$(sep)\n$(sp)b,\n$(sp))") == "f$(d)(a$(sep)\n b,\n)"
@test format_string("f$(d)(\n$(sp)a$(sep)\n$(sp)b,\n$(sp))") == "f$(d)(\n a$(sep)\n b,\n)"
end
# op-call, dot-op-call
for d in ("", ".")
@test format_string("a $(d)+\n$(sp)b") == "a $(d)+\n b"
@test format_string("a $(d)+ b $(d)*\n$(sp)c") == "a $(d)+ b $(d)*\n c"
@test format_string("a $(d)+\n$(sp)b $(d)*\n$(sp)c") == "a $(d)+\n b $(d)*\n c"
if !(VERSION < v"1.7" && d == ".")
@test format_string("a $(d)||\n$(sp)b") == "a $(d)||\n b"
end
end
# op-call
@test format_string("a +\n$(sp)b") == "a +\n b"
@test format_string("a + b *\n$(sp)c") == "a + b *\n c"
@test format_string("a +\n$(sp)b *\n$(sp)c") == "a +\n b *\n c"
@test format_string("a ||\n$(sp)b") == "a ||\n b"
# assignment
for op in ("=", "+=")
@test format_string("a $(op)\n$(sp)b") == "a $(op)\n b"
Expand Down

0 comments on commit b119641

Please sign in to comment.