Skip to content

Commit

Permalink
Merge pull request #471 from asibahi/one_line_case_clause
Browse files Browse the repository at this point in the history
short assignments dont get a new line in `case:`
  • Loading branch information
DanielGavin authored Aug 28, 2024
2 parents e2f4f96 + 05dde34 commit 1c62e7c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/odin/printer/visit.odin
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,14 @@ visit_stmt :: proc(

document = cons(document, text(v.terminator.text))

if len(v.body) != 0 {
if count := len(v.body); count > 0 {
set_source_position(p, v.body[0].pos)
document = cons(document, nest(cons(newline(1), visit_block_stmts(p, v.body))))
fst_stmt, is_assign := v.body[0].derived_stmt.(^Assign_Stmt)
if is_assign && count == 1 {
document = cons_with_opl(document, nest(visit_stmt(p, fst_stmt)))
} else {
document = cons(document, nest(cons(newline(1), visit_block_stmts(p, v.body))))
}
}
case ^Type_Switch_Stmt:
if v.partial {
Expand Down

0 comments on commit 1c62e7c

Please sign in to comment.