@@ -733,14 +733,14 @@ fn renderExpression(
733733 }
734734
735735 // scan to find row size
736- if (rowSize (tree , exprs , rtoken , false ) != null ) {
736+ if (rowSize (tree , exprs , rtoken ) != null ) {
737737 {
738738 ais .pushIndentNextLine ();
739739 defer ais .popIndent ();
740740 try renderToken (tree , ais , lbrace , Space .Newline );
741741
742742 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 | {
744744 const row_exprs = exprs [expr_index .. ];
745745 // A place to store the width of each expression and its column's maximum
746746 var widths = try allocator .alloc (usize , row_exprs .len + row_size );
@@ -757,14 +757,14 @@ fn renderExpression(
757757 // Find next row with trailing comment (if any) to end the current section
758758 var section_end = sec_end : {
759759 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 );
761761 for (row_exprs ) | expr , i | {
762762 // Ignore comment on first line of this section
763763 if (i == 0 or tree .tokensOnSameLine (row_exprs [0 ].firstToken (), expr .lastToken ())) continue ;
764764 // Track start of line containing comment
765765 if (! tree .tokensOnSameLine (row_exprs [this_line_first_expr ].firstToken (), expr .lastToken ())) {
766766 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 );
768768 }
769769
770770 const maybe_comma = expr .lastToken () + 1 ;
@@ -860,7 +860,7 @@ fn renderExpression(
860860 continue ;
861861 }
862862 }
863- if (single_line ) {
863+ if (single_line and row_size != 1 ) {
864864 try renderToken (tree , ais , comma , Space .Space ); // ,
865865 continue ;
866866 }
@@ -1087,7 +1087,8 @@ fn renderExpression(
10871087 const params = call .params ();
10881088 for (params ) | param_node , i | {
10891089 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 ) {
10911092 ais .pushIndentOneShot ();
10921093 }
10931094
@@ -2629,7 +2630,16 @@ fn copyFixingWhitespace(ais: anytype, slice: []const u8) @TypeOf(ais.*).Error!vo
26292630 };
26302631}
26312632
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+
26332643 var count : usize = 1 ;
26342644 for (exprs ) | expr , i | {
26352645 if (i + 1 < exprs .len ) {
@@ -2638,21 +2648,6 @@ fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex, force: b
26382648 if (loc .line != 0 ) return count ;
26392649 count += 1 ;
26402650 } 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- }
26562651 return count ;
26572652 }
26582653 }
0 commit comments