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

Support for c# 12 collection expressions #966

Merged
merged 3 commits into from
Oct 3, 2023
Merged
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
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/publish-nuget@v3.0.4
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

On an unrelated note, I think you can the whole "default variables" feature to share this constant between all the different yaml files you have, so you only have to update it once in future:
https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the whole variables thing I said in the other comment works out, you can make this an ARG and pass it from the yaml.


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"
}
}
Loading