jbcoe created this revision.
jbcoe added a reviewer: krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
jbcoe added a comment.
Requires https://reviews.llvm.org/D75731 to be merged first.
Do not use continuation indent for '[' in blocks in C# code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75747
Files:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -549,6 +549,15 @@
private Transformer _transformer = new X.Y {
Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
+};)",
+ Style);
+
+ // Dictionary initialisation.
+ verifyFormat(R"(//
+var myDict = new Dictionary<string, string> {
+ ["name"] = _donald,
+ ["age"] = Convert.ToString(DateTime.Today.Year - 1934),
+ ["type"] = _duck,
};)",
Style);
}
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1047,6 +1047,8 @@
if (NextNonComment->is(TT_ArraySubscriptLSquare)) {
if (State.Stack.back().StartOfArraySubscripts != 0)
return State.Stack.back().StartOfArraySubscripts;
+ else if (Style.isCSharp()) // C# allows `["key"] = value` inside object
initializers.
+ return State.Stack.back().Indent;
return ContinuationIndent;
}
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -549,6 +549,15 @@
private Transformer _transformer = new X.Y {
Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
+};)",
+ Style);
+
+ // Dictionary initialisation.
+ verifyFormat(R"(//
+var myDict = new Dictionary<string, string> {
+ ["name"] = _donald,
+ ["age"] = Convert.ToString(DateTime.Today.Year - 1934),
+ ["type"] = _duck,
};)",
Style);
}
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1047,6 +1047,8 @@
if (NextNonComment->is(TT_ArraySubscriptLSquare)) {
if (State.Stack.back().StartOfArraySubscripts != 0)
return State.Stack.back().StartOfArraySubscripts;
+ else if (Style.isCSharp()) // C# allows `["key"] = value` inside object initializers.
+ return State.Stack.back().Indent;
return ContinuationIndent;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits