88using Microsoft . AspNetCore . Razor . Language ;
99using Microsoft . AspNetCore . Razor . Language . Syntax ;
1010using Microsoft . CodeAnalysis . ExternalAccess . Razor ;
11+ using Microsoft . CodeAnalysis . Razor . Formatting ;
1112using Microsoft . CodeAnalysis . Razor . Remote ;
1213using Microsoft . CodeAnalysis . Remote . Razor . ProjectSystem ;
1314
@@ -21,7 +22,7 @@ protected override IRemoteDevToolsService CreateService(in ServiceArgs args)
2122 => new RemoteDevToolsService ( in args ) ;
2223 }
2324
24- public ValueTask < string ? > GetCSharpDocumentTextAsync (
25+ public ValueTask < Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse ? > GetCSharpDocumentTextAsync (
2526 RazorPinnedSolutionInfoWrapper solutionInfo ,
2627 DocumentId razorDocumentId ,
2728 CancellationToken cancellationToken )
@@ -31,7 +32,7 @@ protected override IRemoteDevToolsService CreateService(in ServiceArgs args)
3132 context => GetCSharpDocumentTextAsync ( context , cancellationToken ) ,
3233 cancellationToken ) ;
3334
34- public ValueTask < string ? > GetHtmlDocumentTextAsync (
35+ public ValueTask < Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse ? > GetHtmlDocumentTextAsync (
3536 RazorPinnedSolutionInfoWrapper solutionInfo ,
3637 DocumentId razorDocumentId ,
3738 CancellationToken cancellationToken )
@@ -41,7 +42,7 @@ protected override IRemoteDevToolsService CreateService(in ServiceArgs args)
4142 context => GetHtmlDocumentTextAsync ( context , cancellationToken ) ,
4243 cancellationToken ) ;
4344
44- public ValueTask < string ? > GetFormattingDocumentTextAsync (
45+ public ValueTask < Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse ? > GetFormattingDocumentTextAsync (
4546 RazorPinnedSolutionInfoWrapper solutionInfo ,
4647 DocumentId razorDocumentId ,
4748 CancellationToken cancellationToken )
@@ -71,23 +72,45 @@ public ValueTask<string> GetTagHelpersJsonAsync(
7172 context => GetRazorSyntaxTreeAsync ( context , cancellationToken ) ,
7273 cancellationToken ) ;
7374
74- private async ValueTask < string ? > GetCSharpDocumentTextAsync ( RemoteDocumentContext documentContext , CancellationToken cancellationToken )
75+ private async ValueTask < Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse ? > GetCSharpDocumentTextAsync ( RemoteDocumentContext documentContext , CancellationToken cancellationToken )
7576 {
7677 var codeDocument = await documentContext . GetCodeDocumentAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
77- return codeDocument . GetCSharpSourceText ( ) . ToString ( ) ;
78+ var contents = codeDocument . GetCSharpSourceText ( ) . ToString ( ) ;
79+ var filePath = documentContext . Snapshot . FilePath + ".g.cs" ;
80+
81+ return new Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse
82+ {
83+ Contents = contents ,
84+ FilePath = filePath
85+ } ;
7886 }
7987
80- private async ValueTask < string ? > GetHtmlDocumentTextAsync ( RemoteDocumentContext documentContext , CancellationToken cancellationToken )
88+ private async ValueTask < Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse ? > GetHtmlDocumentTextAsync ( RemoteDocumentContext documentContext , CancellationToken cancellationToken )
8189 {
8290 var codeDocument = await documentContext . GetCodeDocumentAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
83- return codeDocument . GetHtmlSourceText ( ) . ToString ( ) ;
91+ var contents = codeDocument . GetHtmlSourceText ( ) . ToString ( ) ;
92+ var filePath = documentContext . Snapshot . FilePath + ".g.html" ;
93+
94+ return new Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse
95+ {
96+ Contents = contents ,
97+ FilePath = filePath
98+ } ;
8499 }
85100
86- private async ValueTask < string ? > GetFormattingDocumentTextAsync ( RemoteDocumentContext documentContext , CancellationToken cancellationToken )
101+ private async ValueTask < Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse ? > GetFormattingDocumentTextAsync ( RemoteDocumentContext documentContext , CancellationToken cancellationToken )
87102 {
88- // For formatting, we typically want the C# generated document
89103 var codeDocument = await documentContext . GetCodeDocumentAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
90- return codeDocument . GetCSharpSourceText ( ) . ToString ( ) ;
104+ #pragma warning disable CS0618 // Type or member is obsolete
105+ var contents = CSharpFormattingPass . GetFormattingDocumentContentsForSyntaxVisualizer ( codeDocument ) ;
106+ #pragma warning restore CS0618 // Type or member is obsolete
107+ var filePath = documentContext . Snapshot . FilePath + ".formatting.cs" ;
108+
109+ return new Microsoft . CodeAnalysis . Razor . Protocol . DevTools . DocumentContentsResponse
110+ {
111+ Contents = contents ,
112+ FilePath = filePath
113+ } ;
91114 }
92115
93116 private async ValueTask < string > GetTagHelpersJsonAsync ( RemoteDocumentContext documentContext , CancellationToken cancellationToken )
@@ -119,7 +142,6 @@ private static Microsoft.CodeAnalysis.Razor.Protocol.DevTools.RazorSyntaxNode Co
119142 Kind = node . Kind . ToString ( ) ,
120143 SpanStart = node . SpanStart ,
121144 SpanEnd = node . Span . End ,
122- SpanLength = node . Span . Length ,
123145 Children = children
124146 } ;
125147 }
0 commit comments