Skip to content

Commit e35fce7

Browse files
Simplify formatting
1 parent 3aaa9d4 commit e35fce7

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

generators/Formatting.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
using System.Globalization;
2-
31
using Microsoft.CodeAnalysis;
42
using Microsoft.CodeAnalysis.CSharp;
5-
using Microsoft.CodeAnalysis.Formatting;
63

74
namespace Generators;
85

96
internal static class Formatting
107
{
11-
private static readonly AdhocWorkspace AdhocWorkspace = new();
12-
13-
internal static string FormatCode(string code) =>
14-
Formatter.Format(Parse(code).NormalizeWhitespace(), AdhocWorkspace)
15-
.ToFullString() + Environment.NewLine;
8+
internal static string FormatCode(string code) =>
9+
Parse(code).NormalizeWhitespace().AddTrailingNewLine().ToFullString();
1610

1711
private static SyntaxNode Parse(string code) =>
1812
CSharpSyntaxTree.ParseText(code).GetRoot();
19-
20-
internal static string FormatLiteral(object obj) =>
21-
SymbolDisplay.FormatLiteral(Convert.ToString(obj, CultureInfo.InvariantCulture)!, obj is string);
13+
14+
private static SyntaxNode AddTrailingNewLine(this SyntaxNode node) =>
15+
node.WithTrailingTrivia(SyntaxFactory.ElasticEndOfLine(Environment.NewLine));
2216
}

0 commit comments

Comments
 (0)