Skip to content

Commit a62f7d7

Browse files
committed
Apply PR feedback
1 parent 02740ad commit a62f7d7

File tree

5 files changed

+42
-45
lines changed

5 files changed

+42
-45
lines changed

src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task SetupAsync()
4848
DocumentPullDiagnosticsEndpoint = new DocumentPullDiagnosticsEndpoint(
4949
languageServerFeatureOptions: languageServer.GetRequiredService<LanguageServerFeatureOptions>(),
5050
translateDiagnosticsService: languageServer.GetRequiredService<RazorTranslateDiagnosticsService>(),
51-
languageServer: new ClientNotifierService(BuildDiagnostics(N)), null!);
51+
languageServer: new ClientNotifierService(BuildDiagnostics(N)), null);
5252
var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
5353
var projectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
5454
_filePath = Path.Combine(projectRoot, "Components", "Pages", $"Generated.razor");

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Protocol/DelegatedTypes.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
1111

1212
internal record DelegatedDiagnosticParams(
1313
VersionedTextDocumentIdentifier HostDocument,
14-
System.Guid CorrelationId
15-
);
14+
System.Guid CorrelationId);
1615

1716
internal record DelegatedPositionParams(
1817
VersionedTextDocumentIdentifier HostDocument,

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/DocumentPullDiagnosticsEndpoint.cs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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"),

src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/TelemetryReportingLSPRequestInvoker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public override Task<ReinvokeResponse<TOut>> ReinvokeRequestOnServerAsync<TIn, T
8080
}
8181
}
8282

83-
internal IDisposable? Track(string name, string method, string languageServerName, Guid correlationId = default)
83+
internal IDisposable? Track(string name, string method, string languageServerName, Guid correlationId = default(Guid))
8484
{
85-
if (correlationId == default)
85+
if (correlationId == Guid.Empty)
8686
return default;
8787

8888
return _telemetryReporter.BeginBlock(name, Severity.Normal, ImmutableDictionary.CreateRange(new KeyValuePair<string, object?>[]

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/CSharpDiagnosticsEndToEndTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private async Task ValidateDiagnosticsAsync(string input)
5656
var requestContext = new RazorRequestContext(documentContext, Logger, null!);
5757

5858
var translateDiagnosticsService = new RazorTranslateDiagnosticsService(DocumentMappingService, LoggerFactory);
59-
var diagnosticsEndPoint = new DocumentPullDiagnosticsEndpoint(LanguageServerFeatureOptions, translateDiagnosticsService, LanguageServer, null!);
59+
var diagnosticsEndPoint = new DocumentPullDiagnosticsEndpoint(LanguageServerFeatureOptions, translateDiagnosticsService, LanguageServer, null);
6060

6161
var diagnosticsRequest = new VSInternalDocumentDiagnosticsParams
6262
{

0 commit comments

Comments
 (0)