From edc17dc2df649f767f21e105ae2842c702c89934 Mon Sep 17 00:00:00 2001 From: Matthijs Velsink Date: Thu, 12 Jun 2025 20:40:08 +0200 Subject: [PATCH] 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". --- blueprintcompiler/formatter.py | 4 +++- tests/formatting/correct1.blp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/blueprintcompiler/formatter.py b/blueprintcompiler/formatter.py index bfff8f4..aebcace 100644 --- a/blueprintcompiler/formatter.py +++ b/blueprintcompiler/formatter.py @@ -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() diff --git a/tests/formatting/correct1.blp b/tests/formatting/correct1.blp index 0101507..56286b4 100644 --- a/tests/formatting/correct1.blp +++ b/tests/formatting/correct1.blp @@ -59,7 +59,7 @@ Adw.MessageDialog { } Adw.Breakpoint { - condition ("width < 100") + condition ("width < 100") // Another inline comment setters { label2.label: _("Hello, world!");