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

Another cpm fix #195

Merged
merged 2 commits into from
Aug 27, 2024
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
13 changes: 8 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Antlr4.Runtime.Standard" Version="4.9.3" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
<PackageVersion Include="FsCheck" Version="2.15.3" />
<PackageVersion Include="FsCheck.Xunit" Version="2.15.3" />
<PackageVersion Include="FsCheck" Version="2.16.6" />
<PackageVersion Include="FsCheck.Xunit" Version="2.16.6" />
<PackageVersion Include="NuGetizer" Version="0.9.0" />
<PackageVersion Include="StaticCs" Version="0.2.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0-1.final" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.6.0-1.final" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageVersion Include="Newtonsoft.JSON" Version="13.0.1" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Security.Cryptography.X509Certificates" Version="4.3.2" />
<PackageVersion Include="PolyKit.Embedded" Version="2.0.30" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.2.0" />
<PackageVersion Include="Verify.XUnit" Version="25.0.4" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/generator/Generator.Deserialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static MethodDeclarationSyntax GenerateEnumDeserializeMethod(
throw new InvalidDeserializeValueException($"Unexpected value: {errorName}");
}
return index switch {
{{string.Join("," + Environment.NewLine, members
{{string.Join("," + Utilities.NewLine, members
.Select((m, i) => $"{i} => {typeSyntax}.{m.Name}")) }},
_ => throw new InvalidDeserializeValueException($"Unexpected index: {index}")
};
Expand Down
6 changes: 3 additions & 3 deletions src/generator/Generator.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ internal static void GenerateImpl(
usings: List(new[] { UsingDirective(IdentifierName("System")), UsingDirective(IdentifierName("Serde")) }),
attributeLists: default,
members: List<MemberDeclarationSyntax>(new[] { newType }));
tree = tree.NormalizeWhitespace(eol: Environment.NewLine);
tree = tree.NormalizeWhitespace(eol: Utilities.NewLine);

context.AddSource(srcName,
Environment.NewLine + "#nullable enable" + Environment.NewLine + tree.ToFullString());
Utilities.NewLine + "#nullable enable" + Utilities.NewLine + tree.ToFullString());
}

internal static (string FileName, string Body) MakePartialDecl(
Expand Down Expand Up @@ -126,7 +126,7 @@ internal static (string FileName, string Body) MakePartialDecl(

newType = typeDeclContext.WrapNewType(newType);

return (srcName, Environment.NewLine + "#nullable enable" + Environment.NewLine + newType);
return (srcName, Utilities.NewLine + "#nullable enable" + Utilities.NewLine + newType);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/generator/Generator.Serialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static (MemberDeclarationSyntax[], BaseListSyntax) GenSerialize(
statements.Add(ParseStatement($$"""
var index = value switch
{
{{string.Join("," + Environment.NewLine, fieldsAndProps
{{string.Join("," + Utilities.NewLine, fieldsAndProps
.Select((m, i) => $"{typeSyntax}.{m.Name} => {i}")) }},
var v => throw new InvalidOperationException($"Cannot serialize unnamed enum value '{v}' of enum '{{enumType.Name}}'"),
};
Expand Down
4 changes: 4 additions & 0 deletions src/generator/HelpersAndUtilities/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static bool IsSorted<T>(this ReadOnlySpan<T> span, IComparer<T> comparer)

internal static class Utilities
{
#pragma warning disable RS1035
public static readonly string NewLine = Environment.NewLine;
#pragma warning restore RS1035

public static T NotNull<T>(this T? value) where T : struct => value!.Value;

public static string Concat(this string recv, string other)
Expand Down
1 change: 1 addition & 0 deletions src/generator/SerdeGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<DefineConstants>$(DefineConstants);SRCGEN</DefineConstants>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/generator/SerdeInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void GenerateSerdeInfo(
typeString = typeString + "<" + new string(',', receiverType.TypeParameters.Length - 1) + ">";
}

var membersString = string.Join("," + Environment.NewLine,
var membersString = string.Join("," + Utilities.NewLine,
SymbolUtilities.GetDataMembers(receiverType, SerdeUsage.Both).SelectNotNull(GetMemberEntry));

List<string> makeArgs = [ $"\"{receiverType.Name}\"", $"typeof({typeString}).GetCustomAttributesData()" ];
Expand All @@ -83,7 +83,7 @@ public static void GenerateSerdeInfo(
}
""");

var argsString = string.Join("," + Environment.NewLine + " ", makeArgs);
var argsString = string.Join("," + Utilities.NewLine + " ", makeArgs);

var body = $$"""
static global::Serde.ISerdeInfo global::Serde.ISerdeInfoProvider.SerdeInfo { get; } = Serde.SerdeInfo.Make{{makeFuncSuffix}}(
Expand Down
2 changes: 1 addition & 1 deletion src/generator/TypeDeclContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public string WrapNewType(string newType)
}
if (NamespaceNames.Count > 0)
{
newType = "namespace " + string.Join(".", NamespaceNames) + ";" + Environment.NewLine + newType;
newType = "namespace " + string.Join(".", NamespaceNames) + ";" + Utilities.NewLine + newType;
}

return newType;
Expand Down
4 changes: 2 additions & 2 deletions src/generator/Wrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ readonly partial struct {{wrapperName}} { }
usings: default,
attributeLists: default,
members: List<MemberDeclarationSyntax>(new[] { newType }));
tree = tree.NormalizeWhitespace(eol: Environment.NewLine);
tree = tree.NormalizeWhitespace(eol: Utilities.NewLine);

context.AddSource(fullWrapperName, Environment.NewLine + tree.ToFullString());
context.AddSource(fullWrapperName, Utilities.NewLine + tree.ToFullString());
}

// If the target is a core type, we can wrap it
Expand Down
2 changes: 1 addition & 1 deletion src/pack/Serde.Pkg.proj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ProjectReference Include="../serde/Serde.csproj" />
<ProjectReference Include="../generator/SerdeGenerator.csproj" />

<PackageReference Include="NuGetizer" Version="0.9.0">
<PackageReference Include="NuGetizer">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading