Skip to content

fix(formatter): Preserve new line if the previous line has an inline comment - #321

Merged
NathanLovato merged 3 commits into
GDQuest:mainfrom
Buitragox:preserve-new-line
Aug 9, 2026
Merged

fix(formatter): Preserve new line if the previous line has an inline comment#321
NathanLovato merged 3 commits into
GDQuest:mainfrom
Buitragox:preserve-new-line

Conversation

@Buitragox

Copy link
Copy Markdown
Contributor

Please check if the PR fulfills these requirements:

  • The commit message follows our guidelines.
    • I don't see a commit message guideline in the readme but I think the commit is ok?
  • For bug fixes and features:
    • You tested the changes.

Related issue: #320

What kind of change does this PR introduce?

Fixes an issue where the formatter does not preserve the new line between two statements when the previous statement has an inline comment.

Does this PR introduce a breaking change?

No

New feature or change

What is the current behavior?
The new line between some_call and another_call gets deleted

func test_inline_comment_preserves_blank_line():
	some_call() # The new line below gets deleted
	another_call()

What is the new behavior?

The new line between the two methods is preserved

func test_inline_comment_preserves_blank_line():
	some_call() # The new line below is preserved yay

	another_call()

Other information
Added tests in comment_edge_cases.gd because it feels like an edge case? But let me know if somewhere else is more appropriate :)

All tests pass.

Another (safer?) approach would be to add another branch

    } else if statement_has_inline_comment {
        let newline_count =
            count_newlines(source, previous_end, child.start_byte());
        push_separator_for_newline_count(newline_count, render_elements);

instead of removing && current_is_declaration, but I don't see any downsides for simplifying the branching logic here.

The benchmark also shows no measurable performance impact.

@Buitragox Buitragox changed the title fix(formatter): Preserve new line if the previous node is an inline comment fix(formatter): Preserve new line if the previous line has an inline comment Aug 9, 2026
@NathanLovato
NathanLovato merged commit f940073 into GDQuest:main Aug 9, 2026
1 check passed
@NathanLovato

Copy link
Copy Markdown
Contributor

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants