From ea6056b0b2c0225f62f63bb8a2c1d88ea9593e23 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Sat, 3 Sep 2022 21:50:18 +0200 Subject: Add specific handling of `if a, b := my_call_expression()` with breaking --- src/odin/printer/visit.odin | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') 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 @@ -449,6 +449,24 @@ is_call_expr_nestable :: proc(list: []^ast.Expr) -> bool { return true } +@(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 { @@ -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) -- cgit v1.2.3