| ... | @@ -733,14 +733,14 @@ fn renderExpression( | ... | @@ -733,14 +733,14 @@ fn renderExpression( |
| 733 | } | 733 | } |
| 734 | | 734 | |
| 735 | // scan to find row size | 735 | // scan to find row size |
| 736 | if (rowSize(tree, exprs, rtoken, false) != null) { | 736 | if (rowSize(tree, exprs, rtoken) != null) { |
| 737 | { | 737 | { |
| 738 | ais.pushIndentNextLine(); | 738 | ais.pushIndentNextLine(); |
| 739 | defer ais.popIndent(); | 739 | defer ais.popIndent(); |
| 740 | try renderToken(tree, ais, lbrace, Space.Newline); | 740 | try renderToken(tree, ais, lbrace, Space.Newline); |
| 741 | | 741 | |
| 742 | var expr_index: usize = 0; | 742 | var expr_index: usize = 0; |
| 743 | while (rowSize(tree, exprs[expr_index..], rtoken, true)) |row_size| { | 743 | while (rowSize(tree, exprs[expr_index..], rtoken)) |row_size| { |
| 744 | const row_exprs = exprs[expr_index..]; | 744 | const row_exprs = exprs[expr_index..]; |
| 745 | // A place to store the width of each expression and its column's maximum | 745 | // A place to store the width of each expression and its column's maximum |
| 746 | var widths = try allocator.alloc(usize, row_exprs.len + row_size); | 746 | var widths = try allocator.alloc(usize, row_exprs.len + row_size); |
| ... | @@ -757,14 +757,14 @@ fn renderExpression( | ... | @@ -757,14 +757,14 @@ fn renderExpression( |
| 757 | // Find next row with trailing comment (if any) to end the current section | 757 | // Find next row with trailing comment (if any) to end the current section |
| 758 | var section_end = sec_end: { | 758 | var section_end = sec_end: { |
| 759 | var this_line_first_expr: usize = 0; | 759 | var this_line_first_expr: usize = 0; |
| 760 | var this_line_size = rowSize(tree, row_exprs, rtoken, true); | 760 | var this_line_size = rowSize(tree, row_exprs, rtoken); |
| 761 | for (row_exprs) |expr, i| { | 761 | for (row_exprs) |expr, i| { |
| 762 | // Ignore comment on first line of this section | 762 | // Ignore comment on first line of this section |
| 763 | if (i == 0 or tree.tokensOnSameLine(row_exprs[0].firstToken(), expr.lastToken())) continue; | 763 | if (i == 0 or tree.tokensOnSameLine(row_exprs[0].firstToken(), expr.lastToken())) continue; |
| 764 | // Track start of line containing comment | 764 | // Track start of line containing comment |
| 765 | if (!tree.tokensOnSameLine(row_exprs[this_line_first_expr].firstToken(), expr.lastToken())) { | 765 | if (!tree.tokensOnSameLine(row_exprs[this_line_first_expr].firstToken(), expr.lastToken())) { |
| 766 | this_line_first_expr = i; | 766 | this_line_first_expr = i; |
| 767 | this_line_size = rowSize(tree, row_exprs[this_line_first_expr..], rtoken, true); | 767 | this_line_size = rowSize(tree, row_exprs[this_line_first_expr..], rtoken); |
| 768 | } | 768 | } |
| 769 | | 769 | |
| 770 | const maybe_comma = expr.lastToken() + 1; | 770 | const maybe_comma = expr.lastToken() + 1; |
| ... | @@ -860,7 +860,7 @@ fn renderExpression( | ... | @@ -860,7 +860,7 @@ fn renderExpression( |
| 860 | continue; | 860 | continue; |
| 861 | } | 861 | } |
| 862 | } | 862 | } |
| 863 | if (single_line) { | 863 | if (single_line and row_size != 1) { |
| 864 | try renderToken(tree, ais, comma, Space.Space); // , | 864 | try renderToken(tree, ais, comma, Space.Space); // , |
| 865 | continue; | 865 | continue; |
| 866 | } | 866 | } |
| ... | @@ -1087,7 +1087,8 @@ fn renderExpression( | ... | @@ -1087,7 +1087,8 @@ fn renderExpression( |
| 1087 | const params = call.params(); | 1087 | const params = call.params(); |
| 1088 | for (params) |param_node, i| { | 1088 | for (params) |param_node, i| { |
| 1089 | const maybe_comment = param_node.firstToken() - 1; | 1089 | const maybe_comment = param_node.firstToken() - 1; |
| 1090 | if (param_node.*.tag == .MultilineStringLiteral or tree.token_ids[maybe_comment] == .LineComment) { | 1090 | const maybe_multiline_string = param_node.firstToken(); |
| | 1091 | if (tree.token_ids[maybe_multiline_string] == .MultilineStringLiteralLine or tree.token_ids[maybe_comment] == .LineComment) { |
| 1091 | ais.pushIndentOneShot(); | 1092 | ais.pushIndentOneShot(); |
| 1092 | } | 1093 | } |
| 1093 | | 1094 | |
| ... | @@ -2629,7 +2630,16 @@ fn copyFixingWhitespace(ais: anytype, slice: []const u8) @TypeOf(ais.*).Error!vo | ... | @@ -2629,7 +2630,16 @@ fn copyFixingWhitespace(ais: anytype, slice: []const u8) @TypeOf(ais.*).Error!vo |
| 2629 | }; | 2630 | }; |
| 2630 | } | 2631 | } |
| 2631 | | 2632 | |
| 2632 | fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex, force: bool) ?usize { | 2633 | fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex) ?usize { |
| | 2634 | const first_token = exprs[0].firstToken(); |
| | 2635 | const first_loc = tree.tokenLocation(tree.token_locs[first_token].start, rtoken); |
| | 2636 | if (first_loc.line == 0) { |
| | 2637 | const maybe_comma = tree.prevToken(rtoken); |
| | 2638 | if (tree.token_ids[maybe_comma] == .Comma) |
| | 2639 | return 1; |
| | 2640 | return null; // no newlines |
| | 2641 | } |
| | 2642 | |
| 2633 | var count: usize = 1; | 2643 | var count: usize = 1; |
| 2634 | for (exprs) |expr, i| { | 2644 | for (exprs) |expr, i| { |
| 2635 | if (i + 1 < exprs.len) { | 2645 | if (i + 1 < exprs.len) { |
| ... | @@ -2638,21 +2648,6 @@ fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex, force: b | ... | @@ -2638,21 +2648,6 @@ fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex, force: b |
| 2638 | if (loc.line != 0) return count; | 2648 | if (loc.line != 0) return count; |
| 2639 | count += 1; | 2649 | count += 1; |
| 2640 | } else { | 2650 | } else { |
| 2641 | if (force) return count; | | |
| 2642 | const expr_last_token = expr.lastToken(); | | |
| 2643 | const loc = tree.tokenLocation(tree.token_locs[expr_last_token].start, rtoken); | | |
| 2644 | if (loc.line == 0) { | | |
| 2645 | // all on one line | | |
| 2646 | const src_has_trailing_comma = trailblk: { | | |
| 2647 | const maybe_comma = tree.prevToken(rtoken); | | |
| 2648 | break :trailblk tree.token_ids[maybe_comma] == .Comma; | | |
| 2649 | }; | | |
| 2650 | if (src_has_trailing_comma) { | | |
| 2651 | return 1; // force row size 1 | | |
| 2652 | } else { | | |
| 2653 | return null; // no newlines | | |
| 2654 | } | | |
| 2655 | } | | |
| 2656 | return count; | 2651 | return count; |
| 2657 | } | 2652 | } |
| 2658 | } | 2653 | } |