[PATCH] D112887: [clang-format] [PR52228] clang-format csharp inconsistant nested namespace indentation

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 31 07:18:05 PDT 2021


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: HazardyKnusperkeks, curdeius.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

https://bugs.llvm.org/show_bug.cgi?id=52228

For multilevel namespaces in C# get their content indented when NamespaceIndentation: None is set, where as single level namespaces are formatted correctly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112887

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1314,5 +1314,26 @@
                Style);
 }
 
+TEST_F(FormatTestCSharp, NamespaceIndentation) {
+  FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
+  Style.NamespaceIndentation = FormatStyle::NI_None;
+
+    verifyFormat("namespace A\n"
+              "{\n"
+               "public interface Name1\n"
+               "{\n"
+               "}\n"
+               "}\n",
+               Style);
+    
+    verifyFormat("namespace A.B\n"
+              "{\n"
+               "public interface Name1\n"
+               "{\n"
+               "}\n"
+               "}\n",
+               Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -14,6 +14,7 @@
 
 #include "UnwrappedLineParser.h"
 #include "FormatToken.h"
+#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -2216,7 +2217,7 @@
     parseParens();
   } else {
     while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::kw_inline,
-                              tok::l_square)) {
+                              tok::l_square, tok::period)) {
       if (FormatTok->is(tok::l_square))
         parseSquare();
       else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112887.383650.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211031/90d9537b/attachment.bin>


More information about the cfe-commits mailing list