formatter: Make inline comments "transparent"

Adding an inline comment somewhere should not affect formatting below
it. So, for inline comments, don't make the line type a comment, but
instead reuse the current line type so that the comment becomes
"transparent".
This commit is contained in:
Matthijs Velsink 2025-06-12 20:40:08 +02:00
parent e16e723a81
commit edc17dc2df
2 changed files with 4 additions and 2 deletions

View file

@ -183,9 +183,11 @@ def format(data, tab_size=2, insert_space=True):
current_line = f"// {current_line[2:]}"
inline_comment = not last_whitespace_contains_newline
line_type = LineType.COMMENT
newlines = 1
if inline_comment:
current_line = " " + current_line
line_type = prev_line_type
newlines = 0
elif single_line_comment:
if prev_line_type == LineType.BLOCK_CLOSE:
@ -196,7 +198,7 @@ def format(data, tab_size=2, insert_space=True):
current_line = "\n".join(
[line.rstrip() for line in current_line.split("\n")]
)
commit_current_line(LineType.COMMENT, newlines_before=newlines)
commit_current_line(line_type, newlines_before=newlines)
else: # pragma: no cover
raise CompilerBugError()

View file

@ -59,7 +59,7 @@ Adw.MessageDialog {
}
Adw.Breakpoint {
condition ("width < 100")
condition ("width < 100") // Another inline comment
setters {
label2.label: _("Hello, world!");