Author: Jonathan Coe
Date: 2020-02-27T11:49:30Z
New Revision: 548e540d2ced9f5a596e0433f544c560a842a6a7

URL: 
https://github.com/llvm/llvm-project/commit/548e540d2ced9f5a596e0433f544c560a842a6a7
DIFF: 
https://github.com/llvm/llvm-project/commit/548e540d2ced9f5a596e0433f544c560a842a6a7.diff

LOG: [clang-format] Handle commas in [] in C#

Summary:
Respect setting `SpacesInSquareBrackets` for commas in square brackets in C# 
code.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75182

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTestCSharp.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 04b20599638d..ff5827c8c4d4 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2893,6 +2893,10 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
     if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName))
       return true;
 
+    // space after comma in '[,]'.
+    if (Left.is(tok::comma) && Right.is(tok::r_square))
+      return Style.SpacesInSquareBrackets;
+
     // space between keywords and paren e.g. "using ("
     if (Right.is(tok::l_paren))
       if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when))

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 3bdaf3d5a9f3..0428de34728a 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -595,6 +595,10 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
   verifyFormat(R"(bool[] xs = { true, true };)", Style);
   verifyFormat(R"(taskContext.Factory.Run(async () => doThing(args);)", Style);
   verifyFormat(R"(catch (TestException) when (innerFinallyExecuted))", Style);
+  verifyFormat(R"(private float[,] Values;)", Style);
+
+  Style.SpacesInSquareBrackets = true;
+  verifyFormat(R"(private float[, ] Values;)", Style);
 }
 
 } // namespace format


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to