Browse Source

Add line-continuation in curly braces, closes #6.

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

10
src/runestone.jl

@ -910,6 +910,14 @@ function indent_paren(ctx::Context, node::Node) @@ -910,6 +910,14 @@ function indent_paren(ctx::Context, node::Node)
return indent_newlines_between_indices(ctx, node, opening_paren_idx, closing_paren_idx)
end
function indent_braces(ctx::Context, node::Node)
@assert kind(node) === K"braces"
kids = verified_kids(node)
opening_brace_idx = findfirst(x -> kind(x) === K"{", kids)::Int
closing_brace_idx = findnext(x -> kind(x) === K"}", kids, opening_brace_idx + 1)::Int
return indent_newlines_between_indices(ctx, node, opening_brace_idx, closing_brace_idx)
end
# Insert line-continuation nodes instead of bumping the indent level.
function indent_op_call(ctx::Context, node::Node)
kids = verified_kids(node)
@ -1167,6 +1175,8 @@ function insert_delete_mark_newlines(ctx::Context, node::Node) @@ -1167,6 +1175,8 @@ function insert_delete_mark_newlines(ctx::Context, node::Node)
return indent_struct(ctx, node)
elseif kind(node) === K"parens"
return indent_parens(ctx, node)
elseif kind(node) === K"braces"
return indent_braces(ctx, node)
elseif kind(node) in KSet"|| &&"
return indent_short_circuit(ctx, node)
elseif kind(node) in KSet"using import export"

5
test/runtests.jl

@ -449,5 +449,10 @@ end @@ -449,5 +449,10 @@ end
# comparison
@test format_string("a == b ==\n$(sp)c") == "a == b ==\n c"
@test format_string("a <= b >=\n$(sp)c") == "a <= b >=\n c"
# curly braces
@test format_string("{a,\n$(sp)b}") == "{a,\n b}"
@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}"
end
end

Loading…
Cancel
Save