File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 11using Microsoft . CodeAnalysis ;
22using Microsoft . CodeAnalysis . CSharp ;
3+ using Microsoft . CodeAnalysis . Formatting ;
34
45namespace Generators ;
56
67internal 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}
You can’t perform that action at this time.
0 commit comments