diff options
| author | flga <flga@users.noreply.github.com> | 2023-07-04 02:19:09 +0100 |
|---|---|---|
| committer | flga <flga@users.noreply.github.com> | 2023-07-04 02:19:09 +0100 |
| commit | ac78202eea46ef9b1f10cceed3dd693c0d1a5ff1 (patch) | |
| tree | 47197032e4f2a35bd2f983ea47b5d1a0795921b6 /src | |
| parent | 7bf6b1dce94ac3184cb56f31b216e3f47f4a072e (diff) | |
Force composite literals with comments to be multi line again
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/document.odin | 13 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 8 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/odin/printer/document.odin b/src/odin/printer/document.odin index 3dd9eda..89edd4b 100644 --- a/src/odin/printer/document.odin +++ b/src/odin/printer/document.odin @@ -290,11 +290,11 @@ cons_with_opl :: proc( rhs: ^Document, allocator := context.allocator, ) -> ^Document { - if _, ok := lhs.(Document_Nil); ok { + if is_empty(lhs) { return rhs } - if _, ok := rhs.(Document_Nil); ok { + if is_empty(rhs) { return lhs } @@ -309,11 +309,11 @@ cons_with_nopl :: proc( rhs: ^Document, allocator := context.allocator, ) -> ^Document { - if _, ok := lhs.(Document_Nil); ok { + if is_empty(lhs) { return rhs } - if _, ok := rhs.(Document_Nil); ok { + if is_empty(rhs) { return lhs } @@ -323,6 +323,11 @@ cons_with_nopl :: proc( ) } +is_empty :: proc(doc: ^Document) -> bool { + _, ok := doc.(Document_Nil) + return ok +} + Tuple :: struct { indentation: int, alignment: int, diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 61bbad3..9a73e3d 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -818,7 +818,7 @@ visit_comp_lit_exprs :: proc( document = cons( document, newline(1), - group(visit_expr(p, expr, .Generic, options)), + visit_expr(p, expr, .Generic, options), ) } else { document = group( @@ -2022,9 +2022,10 @@ visit_expr :: proc( } } + contains_comments := contains_comments_in_range(p, v.pos, v.end) should_newline := + contains_comments || comp_lit_spans_multiple_lines(v) || - contains_comments_in_range(p, v.pos, v.end) || (called_from == .Call_Expr && comp_lit_contains_blocks(p, v^)) should_newline &= len(v.elems) != 0 @@ -2032,12 +2033,11 @@ visit_expr :: proc( document = cons(document, visit_begin_brace(p, v.pos, .Comp_Lit)) options: List_Options = {.Add_Comma, .Trailing} - if comp_lit_contains_fields(p, v^) { + if contains_comments || comp_lit_contains_fields(p, v^) { options |= {.Enforce_Newline} } else { options |= {.Group} } - set_source_position(p, v.open) document = cons( document, |