diff --git a/core/odin/printer/printer.odin b/core/odin/printer/printer.odin index 13c8dbf6b..e1d9f5b7d 100644 --- a/core/odin/printer/printer.odin +++ b/core/odin/printer/printer.odin @@ -24,7 +24,7 @@ Line :: struct { } /* - Represents an singular token in a unwrapped line + Represents a singular token in a unwrapped line */ Format_Token :: struct { kind: tokenizer.Token_Kind, diff --git a/core/odin/printer/visit.odin b/core/odin/printer/visit.odin index 3fdb77615..a6b6759de 100644 --- a/core/odin/printer/visit.odin +++ b/core/odin/printer/visit.odin @@ -476,7 +476,7 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) { } @(private) -visit_exprs :: proc(p: ^Printer, list: []^ast.Expr, add_comma := false, trailing := false) { +visit_exprs :: proc(p: ^Printer, list: []^ast.Expr, add_comma := false, trailing := false, force_newline := false) { if len(list) == 0 { return; @@ -484,9 +484,12 @@ visit_exprs :: proc(p: ^Printer, list: []^ast.Expr, add_comma := false, trailing //we have to newline the expressions to respect the source for expr, i in list { - //Don't move the first expression, it looks bad - if i != 0 { + if i != 0 && force_newline { + newline_position(p, 1); + } + + else if i != 0 { move_line_limit(p, expr.pos, 1); } @@ -496,6 +499,10 @@ visit_exprs :: proc(p: ^Printer, list: []^ast.Expr, add_comma := false, trailing push_generic_token(p, .Comma, 0); } } + + if len(list) > 1 && force_newline { + newline_position(p, 1); + } } @(private) @@ -506,7 +513,6 @@ visit_attributes :: proc(p: ^Printer, attributes: [dynamic]^ast.Attribute) { } for attribute, i in attributes { - move_line_limit(p, attribute.pos, 1); push_generic_token(p, .At, 0); @@ -1029,7 +1035,8 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr) { visit_begin_brace(p, v.pos, .Generic, len(v.fields)); newline_position(p, 1); set_source_position(p, v.fields[0].pos); - visit_exprs(p, v.fields, true, true); + visit_exprs(p, v.fields, true, true, true); + set_source_position(p, v.end); visit_end_brace(p, v.end); }