diff --git a/CHANGELOG.md b/CHANGELOG.md index a92e98b..5df9be7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This file documents the changes made to the formatter with each release. - Fixed an extra comma being inserted after a trailing comment in a lambda function argument (#304) - fixed certain export annotations being moved out of their respective groups (#308) - Preserve up to one blank line used to group elements in "containers" like enums +- Fixed losing blank line between statements in a body if the previous statement has an inline comment (#320, thanks @Buitragox for the fix) ## Release 0.24.0 (2026-07-25) diff --git a/src/formatter.rs b/src/formatter.rs index 77cee6f..47acce0 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -744,7 +744,7 @@ fn process_body( false, ); } - } else if statement_has_inline_comment && current_is_declaration { + } else if statement_has_inline_comment { let needs_two_blank_lines = needs_two_blank_lines(current_child_kind); add_spacing_between_body_children( previous_end, diff --git a/tests/expected/comment_edge_cases.gd b/tests/expected/comment_edge_cases.gd index e2fcc69..e5d5a6e 100644 --- a/tests/expected/comment_edge_cases.gd +++ b/tests/expected/comment_edge_cases.gd @@ -26,3 +26,20 @@ func test3(): else: pass + + +func test_inline_comment_preserves_blank_line(): + some_call() # inline comment + + another_call() + + +func test_inline_comment_no_blank_line(): + some_call() # inline comment + another_call() + + +func test_inline_comment_multiple_blank_lines_collapse(): + some_call() # inline comment + + another_call() diff --git a/tests/input/comment_edge_cases.gd b/tests/input/comment_edge_cases.gd index 4e19379..4d17714 100644 --- a/tests/input/comment_edge_cases.gd +++ b/tests/input/comment_edge_cases.gd @@ -26,3 +26,20 @@ func test3(): else: pass + +func test_inline_comment_preserves_blank_line(): + some_call() # inline comment + + another_call() + + +func test_inline_comment_no_blank_line(): + some_call() # inline comment + another_call() + + +func test_inline_comment_multiple_blank_lines_collapse(): + some_call() # inline comment + + + another_call()