From dd86ab0d52c505141ec3e31124fe710b9b65ff40 Mon Sep 17 00:00:00 2001 From: Yutetsu TAKATSUKASA Date: Sun, 24 Dec 2023 17:12:37 +0900 Subject: [PATCH 1/2] Add a test to reproduce #1538 (local disabling is ignored). --- verilog/formatting/formatter_test.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/verilog/formatting/formatter_test.cc b/verilog/formatting/formatter_test.cc index 9a0f431b9..4ad255009 100644 --- a/verilog/formatting/formatter_test.cc +++ b/verilog/formatting/formatter_test.cc @@ -15465,6 +15465,28 @@ static constexpr FormatterTestCase kFormatterTestCases[] = { "end\n", "always @( /*t*/ * /*t*/) begin\n" "end\n"}, + { + // Don't touch verilog_format:off region #1538 + R"( +module testcode; + // verilog_format: off + assign a = b + & c; + // verilog_format: on + assign e = d; +endmodule +)", + R"( +module testcode; + // verilog_format: off + assign a = b + & c; + // verilog_format: on + assign e = d; +endmodule +)", + + }, // ----------------------------------------------------------------- }; From 221c78dcfdf020d0e89b0f89a1e3ce8620fd4bd7 Mon Sep 17 00:00:00 2001 From: Yutetsu TAKATSUKASA Date: Sun, 24 Dec 2023 17:17:43 +0900 Subject: [PATCH 2/2] formatting: Don't insert additional spacing in frozen region. --- common/formatting/unwrapped_line.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/common/formatting/unwrapped_line.cc b/common/formatting/unwrapped_line.cc index 2ed22b6ef..a6bdbf9b8 100644 --- a/common/formatting/unwrapped_line.cc +++ b/common/formatting/unwrapped_line.cc @@ -129,13 +129,11 @@ std::ostream &FormattedExcerpt::FormattedText( const auto &front = tokens_.front(); if (include_token_p(*front.token)) { VLOG(2) << "action: " << front.before.action; - switch (front.before.action) { - case SpacingDecision::kAlign: - // When aligning tokens, the first token might be further indented. - stream << Spacer(front.before.spaces) << front.token->text(); - break; - default: - stream << front.token->text(); + if (indent && front.before.action == SpacingDecision::kAlign) { + // When aligning tokens, the first token might be further indented. + stream << Spacer(front.before.spaces) << front.token->text(); + } else { + stream << front.token->text(); } } for (const auto &ftoken :