diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/ParenthesizedExpressions.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/ParenthesizedExpressions.test index a1248d1b5..72b8e5b10 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/ParenthesizedExpressions.test +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/ParenthesizedExpressions.test @@ -1,16 +1,34 @@ -class ClassName -{ - void MethodName() - { - var x = - query - && ( - currentChar == '=' - || currentChar == '<' - || currentChar == '!' - || currentChar == '>' - || currentChar == '|' - || currentChar == '&' - ); - } -} +var x = + query + && ( + currentChar == '=' + || currentChar == '<' + || currentChar == '!' + || currentChar == '>' + || currentChar == '|' + || currentChar == '&' + ); + +// some comment won't break the next line +(someObject as SomeType).CallMethod(); + +(someObject as Exactly100____________________________________________________________).CallMethod(); +(someObject as SomeLongType___________________________________________________________) + .CallMethod(); +(someObject as SomeLongType________________________________________________________________________) + .CallMethod(); + +( + someObject + as UnlikelyButThisIsWhatItWouldLookLike_________________________________________________ +) + .CallMethod(); + +( + someObject + as UnlikelyButThisIsWhatItWouldLookLike_________________________________________________ +) + .CallMethod______________() + .CallMethod______________() + .CallMethod______________(); + diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs index c2305d59d..75a5d84aa 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs @@ -35,6 +35,7 @@ public static Doc PrintMemberChain(ExpressionSyntax node, FormattingContext cont var forceOneLine = groups.Count <= cutoff + && groups[0].First().Node is not ParenthesizedExpressionSyntax && ( groups .Skip(shouldMergeFirstTwoGroups ? 1 : 0) diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ParenthesizedExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ParenthesizedExpression.cs index 36bdc289e..d3a1b675c 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ParenthesizedExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ParenthesizedExpression.cs @@ -4,11 +4,14 @@ internal static class ParenthesizedExpression { public static Doc Print(ParenthesizedExpressionSyntax node, FormattingContext context) { - return Doc.Group( - Token.Print(node.OpenParenToken, context), - Doc.Indent(Doc.SoftLine, Node.Print(node.Expression, context)), - Doc.SoftLine, - Token.Print(node.CloseParenToken, context) + return Doc.Concat( + Token.PrintLeadingTrivia(node.OpenParenToken, context), + Doc.Group( + Token.PrintWithoutLeadingTrivia(node.OpenParenToken, context), + Doc.Indent(Doc.SoftLine, Node.Print(node.Expression, context)), + Doc.SoftLine, + Token.Print(node.CloseParenToken, context) + ) ); } }