Skip to content

Commit 5a53d6f

Browse files
committed
feat: add Microsoft.CodeAnalysis.CSharp package and improve source normalization in generator context
1 parent 5506928 commit 5a53d6f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<PackageVersion Include="Autofac" Version="8.2.1" />
3737
<PackageVersion Include="CaseExtensions" Version="1.1.0" />
3838
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" />
39+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
3940
<PackageVersion Include="Namotion.Reflection" Version="3.3.0" />
4041
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
4142
<PackageVersion Include="NJsonSchema" Version="11.2.0" />

src/LibKubernetesGenerator/GeneratorExecutionContextExt.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.Text;
3+
using Microsoft.CodeAnalysis.CSharp;
34
using Scriban;
45
using Scriban.Runtime;
56
using System.Text;
@@ -19,7 +20,10 @@ public static void RenderToContext(this IncrementalGeneratorPostInitializationCo
1920
{
2021
var template = Template.Parse(EmbedResource.GetResource(templatefile));
2122
var generated = template.Render(tc);
22-
context.AddSource(generatedfile, SourceText.From(generated, Encoding.UTF8));
23+
24+
var syntaxTree = CSharpSyntaxTree.ParseText(generated);
25+
var normalized = syntaxTree.GetRoot().NormalizeWhitespace().ToFullString();
26+
context.AddSource(generatedfile, SourceText.From(normalized, Encoding.UTF8));
2327
}
2428
}
2529
}

src/LibKubernetesGenerator/LibKubernetesGenerator.target

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.CodeAnalysis.Common" PrivateAssets="all" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
1617
</ItemGroup>
1718

1819
<ItemGroup>

0 commit comments

Comments
 (0)