Skip to content

Commit

Permalink
Add line-continuation in curly braces, closes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jun 14, 2024
1 parent 0080cdf commit a408508
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a408508

Please sign in to comment.