From 91bbafbef6f90c43551dd71590c0dfe7eeb3296d Mon Sep 17 00:00:00 2001 From: Bela VanderVoort Date: Thu, 7 Nov 2024 12:01:23 -0600 Subject: [PATCH] Fixing extra line + indent with collection expression on fields (#1371) closes #1351 Co-authored-by: Lasath Fernando --- .../TestFiles/cs/CollectionExpressions.test | 12 ++++++++++++ Src/CSharpier/SyntaxPrinter/RightHandSide.cs | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test index a4a417987..790a1585a 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test @@ -149,6 +149,18 @@ class ClassName { } class CastExpressions { + public SomeType[] ShortName = + [ + someLongValue___________________________________________________, + someLongValue___________________________________________________, + ]; + + public SomeType[] LongName____________________________________________________________________________ = + [ + someLongValue___________________________________________________, + someLongValue___________________________________________________, + ]; + void MethodName() { var x = (string[])[someValue, someValue]; diff --git a/Src/CSharpier/SyntaxPrinter/RightHandSide.cs b/Src/CSharpier/SyntaxPrinter/RightHandSide.cs index 5fa39669f..0ebe99cb5 100644 --- a/Src/CSharpier/SyntaxPrinter/RightHandSide.cs +++ b/Src/CSharpier/SyntaxPrinter/RightHandSide.cs @@ -12,7 +12,7 @@ FormattingContext context { var layout = DetermineLayout(leftNode, rightNode); - var groupId = Guid.NewGuid().ToString(); + var groupId = layout.ToString() + Guid.NewGuid(); return layout switch { @@ -98,7 +98,8 @@ is ObjectCreationExpressionSyntax return rightNode switch { - LiteralExpressionSyntax + CollectionExpressionSyntax + or LiteralExpressionSyntax { Token.RawKind: (int)SyntaxKind.MultiLineRawStringLiteralToken }