diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-09-03 21:50:18 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-09-03 21:50:18 +0200 |
| commit | ea6056b0b2c0225f62f63bb8a2c1d88ea9593e23 (patch) | |
| tree | ddacda8673a9cdf0cb50f0d287463992d1f30643 | |
| parent | 2f10f4c2ea1b5bd79ac7aa69cf8bfddfb2b41d32 (diff) | |
Add specific handling of `if a, b := my_call_expression()` with breaking
| -rw-r--r-- | src/odin/printer/visit.odin | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index beaf280..9ad25fe 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -450,6 +450,24 @@ is_call_expr_nestable :: proc(list: []^ast.Expr) -> bool { } @(private) +is_value_decl_statement_ending_with_call :: proc(stmt: ^ast.Stmt) -> bool { + + if value_decl, ok := stmt.derived.(^ast.Value_Decl); ok { + if len(value_decl.values) == 0 { + return false + } + + #partial switch v in + value_decl.values[len(value_decl.values) - 1].derived { + case ^ast.Call_Expr, ^ast.Selector_Call_Expr: + return true + } + } + + return false +} + +@(private) is_values_nestable_assign :: proc(list: []^ast.Expr) -> bool { if len(list) > 1 { return true @@ -960,7 +978,11 @@ visit_stmt :: proc( ) } - document = cons(document, group(hang(3, if_document))) + if v.init != nil && is_value_decl_statement_ending_with_call(v.init) { + document = cons(document, group(if_document)) + } else { + document = cons(document, group(hang(3, if_document))) + } set_source_position(p, v.body.pos) |