Skip to content

Commit

Permalink
Support for c# 12 collection expressions (#966)
Browse files Browse the repository at this point in the history
* Support for c# 12 collection expressions

closes #964

* bump up sdk version

---------

Co-authored-by: Lasath Fernando <[email protected]>
  • Loading branch information
belav and shocklateboy92 authored Oct 3, 2023
1 parent 7291f2b commit 0a2de08
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format_repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
path: csharpier
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.304'
dotnet-version: '7.0.400'
- uses: actions/checkout@v2
with:
repository: belav/csharpier-repos
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish_nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 CSharpier.sln
Expand All @@ -28,7 +28,7 @@ jobs:
- uses: actions/setup-dotnet@v1
with:
dotnet-version: |
7.0.304
7.0.400
6.0.300
- run: |
dotnet tool restore
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions/setup-dotnet@v1
with:
dotnet-version: |
7.0.304
7.0.400
6.0.300
- run: |
dotnet build Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<PackageVersion Include="Ignore" Version="0.1.48" />
<PackageVersion Include="ini-parser-netstandard" Version="2.5.2" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.6.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.7.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CSharp" Version="4.5.0" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageVersion Include="NUnit" Version="3.12.0" />
Expand All @@ -29,8 +29,8 @@
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="13.2.29" />
<PackageVersion Include="System.IO.Hashing" Version="7.0.0-preview.7.22375.6" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageVersion Include="System.Text.Json" Version="7.0.0" />
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="YamlDotNet" Version="11.1.1" />
<PackageVersion Include="YamlDotNet" Version="13.4.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:7.0.304 AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0.400 AS build

RUN apt-get update && \
apt-get install curl gnupg -yq && \
Expand Down
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]
];
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);
}
}
2 changes: 1 addition & 1 deletion global.json
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"
}
}

0 comments on commit 0a2de08

Please sign in to comment.