Skip to content

Commit

Permalink
Make long parenthesized expressions not always break.
Browse files Browse the repository at this point in the history
closes #921
  • Loading branch information
belav committed Jan 7, 2024
1 parent 1b481e2 commit 75a8e1f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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______________();

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);
}
}

0 comments on commit 75a8e1f

Please sign in to comment.