@@ -24,18 +24,18 @@ internal class DocumentPullDiagnosticsEndpoint : IRazorRequestHandler<VSInternal
2424 private readonly LanguageServerFeatureOptions _languageServerFeatureOptions ;
2525 private readonly ClientNotifierServiceBase _languageServer ;
2626 private readonly RazorTranslateDiagnosticsService _translateDiagnosticsService ;
27- private readonly ITelemetryReporter _telemetryReporter ;
27+ private readonly ITelemetryReporter ? _telemetryReporter ;
2828
2929 public DocumentPullDiagnosticsEndpoint (
3030 LanguageServerFeatureOptions languageServerFeatureOptions ,
3131 RazorTranslateDiagnosticsService translateDiagnosticsService ,
3232 ClientNotifierServiceBase languageServer ,
33- ITelemetryReporter telemetryReporter )
33+ ITelemetryReporter ? telemetryReporter )
3434 {
3535 _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException ( nameof ( languageServerFeatureOptions ) ) ;
3636 _translateDiagnosticsService = translateDiagnosticsService ?? throw new ArgumentNullException ( nameof ( translateDiagnosticsService ) ) ;
3737 _languageServer = languageServer ?? throw new ArgumentNullException ( nameof ( languageServer ) ) ;
38- _telemetryReporter = telemetryReporter ?? throw new ArgumentNullException ( nameof ( telemetryReporter ) ) ;
38+ _telemetryReporter = telemetryReporter ;
3939 }
4040
4141 public bool MutatesSolutionState => false ;
@@ -63,61 +63,59 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalDocumentDiagno
6363 }
6464
6565 var correlationId = Guid . NewGuid ( ) ;
66- using ( Track ( "diagnostics" , correlationId ) )
67- {
68- var documentContext = context . GetRequiredDocumentContext ( ) ;
66+ using var __ = Track ( "diagnostics" , correlationId ) ;
67+ var documentContext = context . GetRequiredDocumentContext ( ) ;
6968
70- var razorDiagnostics = await GetRazorDiagnosticsAsync ( documentContext , cancellationToken ) . ConfigureAwait ( false ) ;
69+ var razorDiagnostics = await GetRazorDiagnosticsAsync ( documentContext , cancellationToken ) . ConfigureAwait ( false ) ;
7170
72- var ( csharpDiagnostics , htmlDiagnostics ) = await GetHtmlCSharpDiagnosticsAsync ( documentContext , correlationId , cancellationToken ) . ConfigureAwait ( false ) ;
71+ var ( csharpDiagnostics , htmlDiagnostics ) = await GetHtmlCSharpDiagnosticsAsync ( documentContext , correlationId , cancellationToken ) . ConfigureAwait ( false ) ;
7372
74- using var _ = ListPool < VSInternalDiagnosticReport > . GetPooledObject ( out var allDiagnostics ) ;
75- allDiagnostics . SetCapacityIfLarger (
76- ( razorDiagnostics ? . Length ?? 0 ) +
77- ( csharpDiagnostics ? . Length ?? 0 ) +
78- ( htmlDiagnostics ? . Length ?? 0 ) ) ;
73+ using var _ = ListPool < VSInternalDiagnosticReport > . GetPooledObject ( out var allDiagnostics ) ;
74+ allDiagnostics . SetCapacityIfLarger (
75+ ( razorDiagnostics ? . Length ?? 0 ) +
76+ ( csharpDiagnostics ? . Length ?? 0 ) +
77+ ( htmlDiagnostics ? . Length ?? 0 ) ) ;
7978
80- if ( razorDiagnostics is not null )
81- {
82- // No extra work to do for Razor diagnostics
83- allDiagnostics . AddRange ( razorDiagnostics ) ;
84- }
79+ if ( razorDiagnostics is not null )
80+ {
81+ // No extra work to do for Razor diagnostics
82+ allDiagnostics . AddRange ( razorDiagnostics ) ;
83+ }
8584
86- if ( csharpDiagnostics is not null )
85+ if ( csharpDiagnostics is not null )
86+ {
87+ foreach ( var report in csharpDiagnostics )
8788 {
88- foreach ( var report in csharpDiagnostics )
89+ if ( report . Diagnostics is not null )
8990 {
90- if ( report . Diagnostics is not null )
91- {
92- var mappedDiagnostics = await _translateDiagnosticsService . TranslateAsync ( RazorLanguageKind . CSharp , report . Diagnostics , documentContext , cancellationToken ) . ConfigureAwait ( false ) ;
93- report . Diagnostics = mappedDiagnostics ;
94- }
95-
96- allDiagnostics . Add ( report ) ;
91+ var mappedDiagnostics = await _translateDiagnosticsService . TranslateAsync ( RazorLanguageKind . CSharp , report . Diagnostics , documentContext , cancellationToken ) . ConfigureAwait ( false ) ;
92+ report . Diagnostics = mappedDiagnostics ;
9793 }
94+
95+ allDiagnostics . Add ( report ) ;
9896 }
97+ }
9998
100- if ( htmlDiagnostics is not null )
99+ if ( htmlDiagnostics is not null )
100+ {
101+ foreach ( var report in htmlDiagnostics )
101102 {
102- foreach ( var report in htmlDiagnostics )
103+ if ( report . Diagnostics is not null )
103104 {
104- if ( report . Diagnostics is not null )
105- {
106- var mappedDiagnostics = await _translateDiagnosticsService . TranslateAsync ( RazorLanguageKind . Html , report . Diagnostics , documentContext , cancellationToken ) . ConfigureAwait ( false ) ;
107- report . Diagnostics = mappedDiagnostics ;
108- }
109-
110- allDiagnostics . Add ( report ) ;
105+ var mappedDiagnostics = await _translateDiagnosticsService . TranslateAsync ( RazorLanguageKind . Html , report . Diagnostics , documentContext , cancellationToken ) . ConfigureAwait ( false ) ;
106+ report . Diagnostics = mappedDiagnostics ;
111107 }
112- }
113108
114- return allDiagnostics . ToArray ( ) ;
109+ allDiagnostics . Add ( report ) ;
110+ }
115111 }
112+
113+ return allDiagnostics . ToArray ( ) ;
116114 }
117115
118116 private IDisposable ? Track ( string name , Guid correlationId )
119117 {
120- return _telemetryReporter . BeginBlock ( name , Severity . Normal , ImmutableDictionary . CreateRange ( new KeyValuePair < string , object ? > [ ]
118+ return _telemetryReporter ? . BeginBlock ( name , Severity . Normal , ImmutableDictionary . CreateRange ( new KeyValuePair < string , object ? > [ ]
121119 {
122120 new ( "eventscope.method" , "textdocument/_vs_diagnostic" ) ,
123121 new ( "eventscope.languageservername" , "Razor Language Server" ) ,
0 commit comments