Skip to content

Commit 9b55351

Browse files
Simplify formatting (#2367)
1 parent 3aaa9d4 commit 9b55351

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

generators/Formatting.cs

Lines changed: 4 additions & 10 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();
1913

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

0 commit comments

Comments
 (0)