diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-29 14:04:55 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-29 14:04:55 -0400 |
| commit | 2d3021728bf5c74f8bf6854c1ae4951a6ebbf9c7 (patch) | |
| tree | 3da6684c56138432b4313856bdce17706e3ec216 /src/formatter/formatter.c | |
| parent | 0e67c79f6fc05e79749c2a007df459f926d3dba4 (diff) | |
Formatting tweaks/fixes
Diffstat (limited to 'src/formatter/formatter.c')
| -rw-r--r-- | src/formatter/formatter.c | 11 |
1 files changed, 7 insertions, 4 deletions
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;) { |
