| ... | @@ -561,7 +561,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -561,7 +561,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 561 | const infix = datas[node]; | 561 | const infix = datas[node]; |
| 562 | try renderExpression(r, infix.lhs, .space); | 562 | try renderExpression(r, infix.lhs, .space); |
| 563 | const op_token = main_tokens[node]; | 563 | const op_token = main_tokens[node]; |
| 564 | try ais.pushIndent(.normal); | 564 | try ais.pushIndent(.binop); |
| 565 | if (tree.tokensOnSameLine(op_token, op_token + 1)) { | 565 | if (tree.tokensOnSameLine(op_token, op_token + 1)) { |
| 566 | try renderToken(r, op_token, .space); | 566 | try renderToken(r, op_token, .space); |
| 567 | } else { | 567 | } else { |
| ... | @@ -590,7 +590,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -590,7 +590,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 590 | else => try renderExpression(r, variable_node, variable_space), | 590 | else => try renderExpression(r, variable_node, variable_space), |
| 591 | } | 591 | } |
| 592 | } | 592 | } |
| 593 | try ais.pushIndent(.normal); | 593 | try ais.pushIndent(.after_equals); |
| 594 | if (tree.tokensOnSameLine(full.ast.equal_token, full.ast.equal_token + 1)) { | 594 | if (tree.tokensOnSameLine(full.ast.equal_token, full.ast.equal_token + 1)) { |
| 595 | try renderToken(r, full.ast.equal_token, .space); | 595 | try renderToken(r, full.ast.equal_token, .space); |
| 596 | } else { | 596 | } else { |
| ... | @@ -1247,7 +1247,7 @@ fn renderVarDeclWithoutFixups( | ... | @@ -1247,7 +1247,7 @@ fn renderVarDeclWithoutFixups( |
| 1247 | | 1247 | |
| 1248 | const eq_token = tree.firstToken(var_decl.ast.init_node) - 1; | 1248 | const eq_token = tree.firstToken(var_decl.ast.init_node) - 1; |
| 1249 | const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline; | 1249 | const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline; |
| 1250 | try ais.pushIndent(.normal); | 1250 | try ais.pushIndent(.after_equals); |
| 1251 | try renderToken(r, eq_token, eq_space); // = | 1251 | try renderToken(r, eq_token, eq_space); // = |
| 1252 | try renderExpression(r, var_decl.ast.init_node, space); // ; | 1252 | try renderExpression(r, var_decl.ast.init_node, space); // ; |
| 1253 | ais.popIndent(); | 1253 | ais.popIndent(); |
| ... | @@ -1549,25 +1549,24 @@ fn renderContainerField( | ... | @@ -1549,25 +1549,24 @@ fn renderContainerField( |
| 1549 | } | 1549 | } |
| 1550 | const eq_token = tree.firstToken(field.ast.value_expr) - 1; | 1550 | const eq_token = tree.firstToken(field.ast.value_expr) - 1; |
| 1551 | const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline; | 1551 | const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline; |
| 1552 | { | 1552 | |
| 1553 | try ais.pushIndent(.normal); | 1553 | try ais.pushIndent(.after_equals); |
| 1554 | try renderToken(r, eq_token, eq_space); // = | 1554 | try renderToken(r, eq_token, eq_space); // = |
| | 1555 | |
| | 1556 | if (eq_space == .space) { |
| 1555 | ais.popIndent(); | 1557 | ais.popIndent(); |
| | 1558 | try renderExpressionComma(r, field.ast.value_expr, space); // value |
| | 1559 | return; |
| 1556 | } | 1560 | } |
| 1557 | | 1561 | |
| 1558 | if (eq_space == .space) | | |
| 1559 | return renderExpressionComma(r, field.ast.value_expr, space); // value | | |
| 1560 | | | |
| 1561 | const token_tags = tree.tokens.items(.tag); | 1562 | const token_tags = tree.tokens.items(.tag); |
| 1562 | const maybe_comma = tree.lastToken(field.ast.value_expr) + 1; | 1563 | const maybe_comma = tree.lastToken(field.ast.value_expr) + 1; |
| 1563 | | 1564 | |
| 1564 | if (token_tags[maybe_comma] == .comma) { | 1565 | if (token_tags[maybe_comma] == .comma) { |
| 1565 | try ais.pushIndent(.normal); | | |
| 1566 | try renderExpression(r, field.ast.value_expr, .none); // value | 1566 | try renderExpression(r, field.ast.value_expr, .none); // value |
| 1567 | ais.popIndent(); | 1567 | ais.popIndent(); |
| 1568 | try renderToken(r, maybe_comma, .newline); | 1568 | try renderToken(r, maybe_comma, .newline); |
| 1569 | } else { | 1569 | } else { |
| 1570 | try ais.pushIndent(.normal); | | |
| 1571 | try renderExpression(r, field.ast.value_expr, space); // value | 1570 | try renderExpression(r, field.ast.value_expr, space); // value |
| 1572 | ais.popIndent(); | 1571 | ais.popIndent(); |
| 1573 | } | 1572 | } |
| ... | @@ -3300,6 +3299,8 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { | ... | @@ -3300,6 +3299,8 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { |
| 3300 | | 3299 | |
| 3301 | pub const IndentType = enum { | 3300 | pub const IndentType = enum { |
| 3302 | normal, | 3301 | normal, |
| | 3302 | after_equals, |
| | 3303 | binop, |
| 3303 | }; | 3304 | }; |
| 3304 | const StackElem = struct { | 3305 | const StackElem = struct { |
| 3305 | indent_type: IndentType, | 3306 | indent_type: IndentType, |
| ... | @@ -3391,6 +3392,15 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { | ... | @@ -3391,6 +3392,15 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { |
| 3391 | if (self.indent_stack.items.len > 0) { | 3392 | if (self.indent_stack.items.len > 0) { |
| 3392 | // Only realize last pushed indent | 3393 | // Only realize last pushed indent |
| 3393 | if (!self.indent_stack.items[self.indent_stack.items.len - 1].realized) { | 3394 | if (!self.indent_stack.items[self.indent_stack.items.len - 1].realized) { |
| | 3395 | if (self.indent_stack.items.len >= 2 and |
| | 3396 | self.indent_stack.items[self.indent_stack.items.len - 2].indent_type == .after_equals and |
| | 3397 | self.indent_stack.items[self.indent_stack.items.len - 2].realized and |
| | 3398 | self.indent_stack.items[self.indent_stack.items.len - 1].indent_type == .binop) |
| | 3399 | { |
| | 3400 | // collapse one level of indentation in binop after equals sign |
| | 3401 | return; |
| | 3402 | } |
| | 3403 | |
| 3394 | self.indent_stack.items[self.indent_stack.items.len - 1].realized = true; | 3404 | self.indent_stack.items[self.indent_stack.items.len - 1].realized = true; |
| 3395 | self.indent_count += 1; | 3405 | self.indent_count += 1; |
| 3396 | } | 3406 | } |