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

Allow empty lines in query syntax #814

Merged
merged 4 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions Src/CSharpier.Tests/FormattingTests/TestFiles/QueryExpressions.cst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ class ClassName
CustCount____________________________ = g.Count()
};

var complexQuerySupportsNewLines =
from c in customers

let d = c

where d != null

join c1 in customers1 on c1 equals c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have some lines without spaces to test the negative case


group c by c.Country into g

orderby g.Count() ascending

select new { Country = g.Key, CustCount = g.Count() };

var asyncQuery = await
from c in customers
from u in users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal static class GroupClause
public static Doc Print(GroupClauseSyntax node, FormattingContext context)
{
return Doc.Concat(
ExtraNewLines.Print(node),
Token.PrintWithSuffix(node.GroupKeyword, " ", context),
Node.Print(node.GroupExpression, context),
" ",
Expand Down
43 changes: 23 additions & 20 deletions Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/JoinClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ internal static class JoinClause
{
public static Doc Print(JoinClauseSyntax node, FormattingContext context)
{
return Doc.Group(
Token.PrintWithSuffix(node.JoinKeyword, " ", context),
node.Type != null ? Doc.Concat(Node.Print(node.Type, context), " ") : Doc.Null,
Token.PrintWithSuffix(node.Identifier, " ", context),
Token.PrintWithSuffix(node.InKeyword, " ", context),
Node.Print(node.InExpression, context),
Doc.Indent(
Doc.Line,
Token.PrintWithSuffix(node.OnKeyword, " ", context),
Node.Print(node.LeftExpression, context),
" ",
Token.PrintWithSuffix(node.EqualsKeyword, " ", context),
Node.Print(node.RightExpression, context),
node.Into != null
? Doc.Concat(
Doc.Line,
Token.PrintWithSuffix(node.Into.IntoKeyword, " ", context),
Token.Print(node.Into.Identifier, context)
)
: Doc.Null
return Doc.Concat(
ExtraNewLines.Print(node),
Doc.Group(
Token.PrintWithSuffix(node.JoinKeyword, " ", context),
node.Type != null ? Doc.Concat(Node.Print(node.Type, context), " ") : Doc.Null,
Token.PrintWithSuffix(node.Identifier, " ", context),
Token.PrintWithSuffix(node.InKeyword, " ", context),
Node.Print(node.InExpression, context),
Doc.Indent(
Doc.Line,
Token.PrintWithSuffix(node.OnKeyword, " ", context),
Node.Print(node.LeftExpression, context),
" ",
Token.PrintWithSuffix(node.EqualsKeyword, " ", context),
Node.Print(node.RightExpression, context),
node.Into != null
? Doc.Concat(
Doc.Line,
Token.PrintWithSuffix(node.Into.IntoKeyword, " ", context),
Token.Print(node.Into.Identifier, context)
)
: Doc.Null
)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal static class LetClause
public static Doc Print(LetClauseSyntax node, FormattingContext context)
{
return Doc.Concat(
ExtraNewLines.Print(node),
Token.PrintWithSuffix(node.LetKeyword, " ", context),
Token.PrintWithSuffix(node.Identifier, " ", context),
Token.PrintWithSuffix(node.EqualsToken, " ", context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal static class OrderByClause
public static Doc Print(OrderByClauseSyntax node, FormattingContext context)
{
return Doc.Concat(
ExtraNewLines.Print(node),
Token.Print(node.OrderByKeyword, context),
SeparatedSyntaxList.Print(
node.Orderings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal static class SelectClause
public static Doc Print(SelectClauseSyntax node, FormattingContext context)
{
return Doc.Concat(
ExtraNewLines.Print(node),
Token.PrintWithSuffix(node.SelectKeyword, " ", context),
Node.Print(node.Expression, context)
);
Expand Down
9 changes: 6 additions & 3 deletions Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/WhereClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ internal static class WhereClause
{
public static Doc Print(WhereClauseSyntax node, FormattingContext context)
{
return Doc.Group(
Token.Print(node.WhereKeyword, context),
Doc.Indent(Doc.Line, Node.Print(node.Condition, context))
return Doc.Concat(
ExtraNewLines.Print(node),
Doc.Group(
Token.Print(node.WhereKeyword, context),
Doc.Indent(Doc.Line, Node.Print(node.Condition, context))
)
);
}
}