diff options
| author | flga <flga@users.noreply.github.com> | 2023-07-06 20:39:38 +0100 |
|---|---|---|
| committer | flga <flga@users.noreply.github.com> | 2023-07-06 20:39:38 +0100 |
| commit | 9e886874e728b038ef39710444262b85d4d452db (patch) | |
| tree | 72483cd76fd986c327089511dce738ed1e692d90 /src | |
| parent | ce93ef6b66c9e7cd3562945ad21acd27305aef9d (diff) | |
Add a new config option to allow multiline composite literals
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/printer.odin | 19 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 11 |
2 files changed, 15 insertions, 15 deletions
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index d2af255..ba2b7e3 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -38,15 +38,16 @@ Disabled_Info :: struct { } Config :: struct { - character_width: int, - spaces: int, //Spaces per indentation - newline_limit: int, //The limit of newlines between statements and declarations. - tabs: bool, //Enable or disable tabs - tabs_width: int, - convert_do: bool, //Convert all do statements to brace blocks - brace_style: Brace_Style, - indent_cases: bool, - newline_style: Newline_Style, + character_width: int, + spaces: int, //Spaces per indentation + newline_limit: int, //The limit of newlines between statements and declarations. + tabs: bool, //Enable or disable tabs + tabs_width: int, + convert_do: bool, //Convert all do statements to brace blocks + multiline_composite_literals: bool `json:"exp_multiline_composite_literals"`, + brace_style: Brace_Style, + indent_cases: bool, + newline_style: Newline_Style, } Brace_Style :: enum { diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 01c2400..cc48524 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -2009,9 +2009,11 @@ visit_expr :: proc( } } + can_multiline := + p.config.multiline_composite_literals && + comp_lit_spans_multiple_lines(v^) should_newline := - comp_lit_spans_multiple_lines(v^) || - contains_comments_in_range(p, v.pos, v.end) + can_multiline || contains_comments_in_range(p, v.pos, v.end) should_newline &= (called_from == .Value_Decl || called_from == .Assignment_Stmt || @@ -2019,10 +2021,7 @@ visit_expr :: proc( should_newline &= len(v.elems) != 0 if should_newline { - document = cons( - document, - visit_begin_brace(p, v.pos, .Comp_Lit), - ) + document = cons(document, visit_begin_brace(p, v.pos, .Comp_Lit)) set_source_position(p, v.open) document = cons( |