-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for c# 12 collection expressions (#966)
* Support for c# 12 collection expressions closes #964 * bump up sdk version --------- Co-authored-by: Lasath Fernando <[email protected]>
- Loading branch information
1 parent
7291f2b
commit 0a2de08
Showing
8 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ jobs: | |
- uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: | | ||
7.0.304 | ||
7.0.400 | ||
6.0.300 | ||
- run: > | ||
dotnet test Src/CSharpier.Tests/CSharpier.Tests.csproj | ||
|
@@ -32,7 +32,7 @@ jobs: | |
- uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: | | ||
7.0.304 | ||
7.0.400 | ||
6.0.300 | ||
- name: Publish CSharpier.Core library on version change | ||
uses: alirezanet/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; | ||
|
||
Span<int> b = [ 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i' ]; | ||
|
||
string[] c = | ||
[ | ||
"________________________", | ||
"________________________", | ||
"________________________", | ||
"________________________" | ||
]; | ||
|
||
int[][] d = | ||
[ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9] | ||
]; |
38 changes: 38 additions & 0 deletions
38
Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/CollectionExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace CSharpier.SyntaxPrinter.SyntaxNodePrinters; | ||
|
||
internal static class CollectionExpression | ||
{ | ||
public static Doc Print(CollectionExpressionSyntax node, FormattingContext context) | ||
{ | ||
Doc separator = node.Parent | ||
is AssignmentExpressionSyntax | ||
or EqualsValueClauseSyntax { Parent: not PropertyDeclarationSyntax } | ||
? Doc.Line | ||
: Doc.Null; | ||
|
||
var alwaysBreak = | ||
node.Elements.FirstOrDefault() | ||
is ExpressionElementSyntax { Expression: CollectionExpressionSyntax }; | ||
|
||
var result = Doc.Concat( | ||
separator, | ||
Token.Print(node.OpenBracketToken, context), | ||
Doc.Indent( | ||
alwaysBreak ? Doc.HardLine : Doc.Line, | ||
SeparatedSyntaxList.Print( | ||
node.Elements, | ||
Node.Print, | ||
alwaysBreak ? Doc.HardLine : Doc.Line, | ||
context | ||
) | ||
), | ||
node.Elements.Any() | ||
? alwaysBreak | ||
? Doc.HardLine | ||
: Doc.Line | ||
: Doc.Null, | ||
Token.Print(node.CloseBracketToken, context) | ||
); | ||
return Doc.Group(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.304", | ||
"version": "7.0.400", | ||
"rollForward": "latestFeature" | ||
} | ||
} |