diff --git a/src/runestone.jl b/src/runestone.jl index 7a84d75..68edadb 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -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) 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" diff --git a/test/runtests.jl b/test/runtests.jl index b2fe459..ea3ebd3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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