From 2d3021728bf5c74f8bf6854c1ae4951a6ebbf9c7 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 29 Aug 2025 14:04:55 -0400 Subject: Formatting tweaks/fixes --- src/formatter/formatter.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/formatter/formatter.c') diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c index 89535071..161c70d4 100644 --- a/src/formatter/formatter.c +++ b/src/formatter/formatter.c @@ -386,7 +386,8 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) { bool gap_before_comment = false; const char *comment_pos = ast->start; for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { - if (should_have_blank_line(stmt->ast)) add_line(&code, Text(""), indent); + for (int blanks = suggested_blank_lines(stmt->ast); blanks > 0; blanks--) + add_line(&code, Text(""), indent); for (OptionalText_t comment; (comment = next_comment(comments, &comment_pos, stmt->ast->start)).length > 0;) { @@ -400,9 +401,11 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) { add_line(&code, fmt(stmt->ast, comments, indent), indent); comment_pos = stmt->ast->end; - if (should_have_blank_line(stmt->ast) && stmt->next && !should_have_blank_line(stmt->next->ast)) - add_line(&code, Text(""), indent); - else gap_before_comment = true; + if (stmt->next) { + for (int blanks = suggested_blank_lines(stmt->ast) - suggested_blank_lines(stmt->next->ast); blanks > 0; + blanks--) + add_line(&code, Text(""), indent); + } else gap_before_comment = true; } for (OptionalText_t comment; (comment = next_comment(comments, &comment_pos, ast->end)).length > 0;) { -- cgit v1.2.3