Browse Source

Properly indent dotcalls

pull/19/head
Fredrik Ekre 2 years ago
parent
commit
b119641f36
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 6
      src/runestone.jl
  2. 28
      test/runtests.jl

6
src/runestone.jl

@ -849,7 +849,7 @@ function indent_if(ctx::Context, node::Node)
end end
function indent_call(ctx::Context, node::Node) function indent_call(ctx::Context, node::Node)
@assert kind(node) === K"call" @assert kind(node) in KSet"call dotcall"
return indent_paren(ctx, node) return indent_paren(ctx, node)
end end
@ -895,7 +895,7 @@ end
# Mark opening and closing parentheses, in a call or a tuple, with indent and dedent tags. # Mark opening and closing parentheses, in a call or a tuple, with indent and dedent tags.
function indent_paren(ctx::Context, node::Node) 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) kids = verified_kids(node)
opening_paren_idx = findfirst(x -> kind(x) === K"(", kids)::Int opening_paren_idx = findfirst(x -> kind(x) === K"(", kids)::Int
closing_paren_idx = findnext(x -> kind(x) === K")", kids, opening_paren_idx + 1)::Int closing_paren_idx = findnext(x -> kind(x) === K")", kids, opening_paren_idx + 1)::Int
@ -1147,7 +1147,7 @@ function insert_delete_mark_newlines(ctx::Context, node::Node)
return indent_let(ctx, node) return indent_let(ctx, node)
elseif is_begin_block(node) elseif is_begin_block(node)
return indent_begin(ctx, 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) return indent_call(ctx, node)
elseif is_infix_op_call(node) elseif is_infix_op_call(node)
return indent_op_call(ctx, node) return indent_op_call(ctx, node)

28
test/runtests.jl

@ -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("(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)" @test format_string("(\n$(sp)a,\n$(sp)b,\n$(sp))") == "(\n a,\n b,\n)"
# call # call, dotcall
for sep in (",", ";") for sep in (",", ";"), d in ("", ".")
@test format_string("f(a$(sep)\n$(sp)b)") == "f(a$(sep)\n b)" @test format_string("f$(d)(a$(sep)\n$(sp)b)") == "f$(d)(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$(d)(a$(sep)\n$(sp)b\n$(sp))") == "f$(d)(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$(d)(a$(sep)\n$(sp)b,\n$(sp))") == "f$(d)(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)" @test format_string("f$(d)(\n$(sp)a$(sep)\n$(sp)b,\n$(sp))") == "f$(d)(\n a$(sep)\n b,\n)"
end end
# op-call # op-call, dot-op-call
@test format_string("a +\n$(sp)b") == "a +\n b" for d in ("", ".")
@test format_string("a + b *\n$(sp)c") == "a + b *\n c" @test format_string("a $(d)+\n$(sp)b") == "a $(d)+\n b"
@test format_string("a +\n$(sp)b *\n$(sp)c") == "a +\n b *\n c" @test format_string("a $(d)+ b $(d)*\n$(sp)c") == "a $(d)+ b $(d)*\n c"
@test format_string("a ||\n$(sp)b") == "a ||\n b" @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
# assignment # assignment
for op in ("=", "+=") for op in ("=", "+=")
@test format_string("a $(op)\n$(sp)b") == "a $(op)\n b" @test format_string("a $(op)\n$(sp)b") == "a $(op)\n b"

Loading…
Cancel
Save