Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format] Stop aligning the to continuation lines #76378

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

sstwcw
Copy link
Contributor

@sstwcw sstwcw commented Dec 26, 2023

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 lines was changed, and git-clang-format was run, the changed line would be indented by an extra continuation indentation.

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 lines was changed, and git-clang-format
was run, the changed line would be indented by an extra continuation
indentation.
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 26, 2023

@llvm/pr-subscribers-clang-format

Author: None (sstwcw)

Changes

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 lines was changed, and git-clang-format was run, the changed line would be indented by an extra continuation indentation.


Full diff: https://github.com/llvm/llvm-project/pull/76378.diff

3 Files Affected:

  • (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+1-1)
  • (modified) clang/unittests/Format/FormatTestCSharp.cpp (+12)
  • (modified) clang/unittests/Format/FormatTestVerilog.cpp (+11)
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 56077499c39d53..2fc15d8828e4be 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -95,7 +95,7 @@ class LevelIndentTracker {
   /// level to the same indent.
   /// Note that \c nextLine must have been called before this method.
   void adjustToUnmodifiedLine(const AnnotatedLine &Line) {
-    if (Line.InPPDirective)
+    if (Line.InPPDirective || Line.IsContinuation)
       return;
     assert(Line.Level < IndentForLevel.size());
     if (Line.First->is(tok::comment) && IndentForLevel[Line.Level] != -1)
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index 4a0840d32341e8..c27e2b576adf73 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -1304,6 +1304,18 @@ TEST_F(FormatTestCSharp, CSharpGenericTypeConstraints) {
                "}",
                Style);
 
+  // When the where line is not to be formatted, following lines should not take
+  // on its indentation.
+  verifyFormat("class ItemFactory<T>\n"
+               "    where T : new() {\n"
+               "  int f() {}\n"
+               "}",
+               "class ItemFactory<T>\n"
+               "    where T : new() {\n"
+               "  int f() {}\n"
+               "}",
+               Style, {tooling::Range(43, 13)});
+
   verifyFormat("class Dictionary<TKey, TVal>\n"
                "    where TKey : IComparable<TKey>\n"
                "    where TVal : IMyInterface {\n"
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp
index fcda05df182687..abebf9f7d4c785 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -613,6 +613,17 @@ TEST_F(FormatTestVerilog, Headers) {
                "      (input var x aaaaaaaaaaaaaaa``x, \\\n"
                "                   b);",
                Style);
+  // When the ports line is not to be formatted, following lines should not take
+  // on its indentation.
+  verifyFormat("module x\n"
+               "    (output x);\n"
+               "  assign x = 0;\n"
+               "endmodule",
+               "module x\n"
+               "    (output x);\n"
+               "    assign x = 0;\n"
+               "endmodule",
+               getDefaultStyle(), {tooling::Range(25, 18)});
 }
 
 TEST_F(FormatTestVerilog, Hierarchy) {

@sstwcw
Copy link
Contributor Author

sstwcw commented Jan 12, 2024

Can someone review this please? Did you see it when I opened the pull request 2 weeks ago or only when I added the reviewers just now? I thought reviewers would be added automatically.

@HazardyKnusperkeks
Copy link
Contributor

Can someone review this please? Did you see it when I opened the pull request 2 weeks ago or only when I added the reviewers just now? I thought reviewers would be added automatically.

Every member of @pr-subscribers-clang-format will be informed, and I look into most of the stuff at least once. But sometimes (for various reasons) I skip a change at first. When not directly added the change might slip, if no one else starts to comment.

@sstwcw sstwcw merged commit e3acfbc into llvm:main Jan 15, 2024
3 of 4 checks passed
@sstwcw sstwcw deleted the format-partial branch January 15, 2024 03:04
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants