Skip to content
Draft
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
19 changes: 19 additions & 0 deletions RoslynPreviewSdkReferences.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project>
<PropertyGroup>
<RoslynPreviewSdkPath>/usr/share/dotnet/sdk/11.0.100-preview.5.26302.115/Roslyn/bincore</RoslynPreviewSdkPath>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<!--
DRAFT PR HACK: use the Roslyn bits from .NET 11 Preview 5 so CSharpier can
parse C# 15 closed/union syntax before matching NuGet packages are published.
Replace this import with Microsoft.CodeAnalysis.CSharp from NuGet once available.
-->
<Reference Include="Microsoft.CodeAnalysis">
<HintPath>$(RoslynPreviewSdkPath)/Microsoft.CodeAnalysis.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp">
<HintPath>$(RoslynPreviewSdkPath)/Microsoft.CodeAnalysis.CSharp.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Src/CSharpier.Cli/CSharpier.Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../Nuget/Build.props" />
<Import Project="../../RoslynPreviewSdkReferences.props" />
<PropertyGroup>
<NoWarn>$(NoWarn);NU1510</NoWarn>
<OutputType>Exe</OutputType>
Expand Down
1 change: 1 addition & 0 deletions Src/CSharpier.Core/CSharp/SyntaxPrinter/Modifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private class DefaultOrder : IComparer<SyntaxToken>
"new",
"virtual",
"abstract",
"closed",
"sealed",
"override",
"readonly",
Expand Down
5 changes: 4 additions & 1 deletion Src/CSharpier.Core/CSharpier.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../Nuget/Build.props" />
<Import Project="../../RoslynPreviewSdkReferences.props" />
<PropertyGroup>
<PackageId>CSharpier.Core</PackageId>
<TargetFrameworks>net8.0;net9.0;net10.0;netstandard2.0</TargetFrameworks>
Expand All @@ -13,7 +14,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LovettSoftware.XmlDiff" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -24,6 +24,9 @@
</PackageReference>
<PackageReference Include="System.IO.Abstractions" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net10.0'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net10.0'">
<PackageReference Include="System.Text.Json" />
</ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion Src/CSharpier.Generators/NodePrinterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class NodePrinterGenerator : IIncrementalGenerator
nameof(SyntaxKind.RecordStructDeclaration),
nameof(SyntaxKind.EnumDeclaration),
nameof(SyntaxKind.ExtensionBlockDeclaration),
"(SyntaxKind)9082", // SyntaxKind.UnionDeclaration in .NET 11 Preview 5
}
},
{
Expand Down Expand Up @@ -275,7 +276,12 @@ private object GetModel(ImmutableArray<SyntaxTree> syntaxTrees)
PrinterName = fileName,
SyntaxNodeName = $"{fileName}Syntax",
SyntaxKinds = SpecialCase.TryGetValue($"{fileName}Syntax", out var kinds)
? string.Join(" or ", kinds.Select(x => $"SyntaxKind.{x}"))
? string.Join(
" or ",
kinds.Select(x =>
x.StartsWith("(", StringComparison.Ordinal) ? x : $"SyntaxKind.{x}"
)
)
: $"SyntaxKind.{fileName}",
})
.OrderBy(o => o.SyntaxNodeName)
Expand Down
1 change: 1 addition & 0 deletions Src/CSharpier.Tests/CSharpier.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../RoslynPreviewSdkReferences.props" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<RootNamespace>CSharpier.Tests</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public closed record class JobStatus;

public record class Queued : JobStatus;

public record class Running(int PercentComplete) : JobStatus;

public union Pet(Cat, Dog, Bird);

public union Length(Meters, Feet)
{
public double TotalMeters =>
this switch
{
Meters m => m.Value,
Feet f => f.Value * 0.3048,
_ => throw new InvalidOperationException("The Length has no value."),
};

public Length Add(Length other) => new Meters(TotalMeters + other.TotalMeters);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public closed record class JobStatus;

public record class Queued : JobStatus;

public record class Running(int PercentComplete) : JobStatus;

public union Pet(Cat, Dog, Bird);

public union Length(Meters, Feet)
{
public double TotalMeters => this switch
{
Meters m => m.Value,
Feet f => f.Value * 0.3048,
_ => throw new InvalidOperationException("The Length has no value."),
};

public Length Add(Length other) => new Meters(TotalMeters + other.TotalMeters);
}