Skip to content

Commit e3acfbc

Browse files
authored
[clang-format] Stop aligning the to continuation lines (#76378)
Some unwrapped lines are marked as continuations of the previous lines, for example the ports in a Verilog module header. Previously, if the first line following the ports line was changed, and git-clang-format was run, the changed line would be indented by an extra continuation indentation.
1 parent 48e8cd8 commit e3acfbc

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class LevelIndentTracker {
9595
/// level to the same indent.
9696
/// Note that \c nextLine must have been called before this method.
9797
void adjustToUnmodifiedLine(const AnnotatedLine &Line) {
98-
if (Line.InPPDirective)
98+
if (Line.InPPDirective || Line.IsContinuation)
9999
return;
100100
assert(Line.Level < IndentForLevel.size());
101101
if (Line.First->is(tok::comment) && IndentForLevel[Line.Level] != -1)

clang/unittests/Format/FormatTestCSharp.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,18 @@ TEST_F(FormatTestCSharp, CSharpGenericTypeConstraints) {
13041304
"}",
13051305
Style);
13061306

1307+
// When the "where" line is not to be formatted, following lines should not
1308+
// take on its indentation.
1309+
verifyFormat("class ItemFactory<T>\n"
1310+
" where T : new() {\n"
1311+
" int f() {}\n"
1312+
"}",
1313+
"class ItemFactory<T>\n"
1314+
" where T : new() {\n"
1315+
" int f() {}\n"
1316+
"}",
1317+
Style, {tooling::Range(43, 13)});
1318+
13071319
verifyFormat("class Dictionary<TKey, TVal>\n"
13081320
" where TKey : IComparable<TKey>\n"
13091321
" where TVal : IMyInterface {\n"

clang/unittests/Format/FormatTestVerilog.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,17 @@ TEST_F(FormatTestVerilog, Headers) {
613613
" (input var x aaaaaaaaaaaaaaa``x, \\\n"
614614
" b);",
615615
Style);
616+
// When the ports line is not to be formatted, following lines should not take
617+
// on its indentation.
618+
verifyFormat("module x\n"
619+
" (output x);\n"
620+
" assign x = 0;\n"
621+
"endmodule",
622+
"module x\n"
623+
" (output x);\n"
624+
" assign x = 0;\n"
625+
"endmodule",
626+
getDefaultStyle(), {tooling::Range(25, 18)});
616627
}
617628

618629
TEST_F(FormatTestVerilog, Hierarchy) {

0 commit comments

Comments
 (0)