Skip to content

Commit

Permalink
Allow empty lines in query syntax (#814)
Browse files Browse the repository at this point in the history
* Allow empty lines in query syntax

closes #754

* Adding some tests for removing lines
  • Loading branch information
belav authored Feb 4, 2023
1 parent 5f55413 commit c32bbfd
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 32 deletions.
18 changes: 9 additions & 9 deletions Src/CSharpier.Tests/CSharpier.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DiffEngine"/>
<PackageReference Include="FluentAssertions"/>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit3TestAdapter"/>
<PackageReference Include="DiffEngine" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CSharpier.Cli\CSharpier.Cli.csproj"/>
<ProjectReference Include="..\CSharpier.Tests.Generators\CSharpier.Tests.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\CSharpier\CSharpier.csproj"/>
<ProjectReference Include="..\CSharpier.Cli\CSharpier.Cli.csproj" />
<ProjectReference Include="..\CSharpier.Tests.Generators\CSharpier.Tests.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\CSharpier\CSharpier.csproj" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="FormattingTests\TestFiles\*.cst"/>
<AdditionalFiles Include="FormattingTests\TestFiles\*.cst" />
</ItemGroup>
<ItemGroup>
<Content Include="FormattingTests\TestFiles\*.actual.cst">
Expand Down
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

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
@@ -0,0 +1,20 @@
var complexQuerySupportsNewLines =
from c in customers


let d = c


where d != null


join c1 in customers1 on c1 equals c


group c by c.Country into g


orderby g.Count() ascending


select new { Country = g.Key, CustCount = g.Count() };
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var complexQuerySupportsNewLines =
from c in customers

let d = c

where d != null

join c1 in customers1 on c1 equals c

group c by c.Country into g

orderby g.Count() ascending

select new { Country = g.Key, CustCount = g.Count() };
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))
)
);
}
}

0 comments on commit c32bbfd

Please sign in to comment.