Skip to content

Commit 1b158cf

Browse files
Update formatter
1 parent 9b55351 commit 1b158cf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

generators/Formatting.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.CSharp;
3+
using Microsoft.CodeAnalysis.Formatting;
34

45
namespace Generators;
56

67
internal static class Formatting
78
{
8-
internal static string FormatCode(string code) =>
9-
Parse(code).NormalizeWhitespace().AddTrailingNewLine().ToFullString();
9+
private static readonly AdhocWorkspace AdhocWorkspace = new();
1010

11-
private static SyntaxNode Parse(string code) =>
12-
CSharpSyntaxTree.ParseText(code).GetRoot();
11+
internal static string FormatCode(string code) =>
12+
CSharpSyntaxTree.ParseText(code).GetRoot().Format().ToFullString();
1313

14-
private static SyntaxNode AddTrailingNewLine(this SyntaxNode node) =>
15-
node.WithTrailingTrivia(SyntaxFactory.ElasticEndOfLine(Environment.NewLine));
14+
private static SyntaxNode Format(this SyntaxNode node) => Formatter.Format(node, AdhocWorkspace);
1615
}

0 commit comments

Comments
 (0)