| ... | ... | @@ -1179,6 +1179,12 @@ fn renderExpression( |
| 1179 | 1179 | break :blk tree.tokens.at(maybe_comma).id == .Comma; |
| 1180 | 1180 | }; |
| 1181 | 1181 | |
| 1182 | // Check if the first declaration and the { are on the same line |
| 1183 | const src_has_newline = !tree.tokensOnSameLine( |
| 1184 | container_decl.fields_and_decls.at(0).*.firstToken(), |
| 1185 | container_decl.rbrace_token, |
| 1186 | ); |
| 1187 | |
| 1182 | 1188 | // We can only print all the elements in-line if all the |
| 1183 | 1189 | // declarations inside are fields |
| 1184 | 1190 | const src_has_only_fields = blk: { |
| ... | ... | @@ -1205,6 +1211,19 @@ fn renderExpression( |
| 1205 | 1211 | } |
| 1206 | 1212 | |
| 1207 | 1213 | try stream.writeByteNTimes(' ', indent); |
| 1214 | } else if (src_has_newline) { |
| 1215 | // All the declarations on the same line, but place the items on |
| 1216 | // their own line |
| 1217 | try renderToken(tree, stream, container_decl.lbrace_token, indent, start_col, .Newline); // { |
| 1218 | |
| 1219 | const new_indent = indent + indent_delta; |
| 1220 | try stream.writeByteNTimes(' ', new_indent); |
| 1221 | |
| 1222 | var it = container_decl.fields_and_decls.iterator(0); |
| 1223 | while (it.next()) |decl| { |
| 1224 | const space_after_decl: Space = if (it.peek() == null) .Newline else .Space; |
| 1225 | try renderContainerDecl(allocator, stream, tree, new_indent, start_col, decl.*, space_after_decl); |
| 1226 | } |
| 1208 | 1227 | } else { |
| 1209 | 1228 | // All the declarations on the same line |
| 1210 | 1229 | try renderToken(tree, stream, container_decl.lbrace_token, indent, start_col, .Space); // { |