Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make long parenthesized expressions not always break. #1115

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
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)
)
);
}
}
Loading