-
Notifications
You must be signed in to change notification settings - Fork 219
Move VS Code To Pull Diagnostics #11602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
efc682a
It works. Needs changes in VS Code. Idk if I like it... should it sha…
9287e3e
Remove diagnostic publisher
d71b345
Change naming
201e718
I think this naming makes more sense. Also move reporting code into a…
b5de43b
Merge branch 'main' into vscode_pull_diagnostics
4b2b2d5
Rename test file
dcd2893
Update src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagno…
562ba7a
Use DelegatedDiagnosticParams
6521382
Merge branch 'vscode_pull_diagnostics' of https://github.com/ryzngard…
de3084a
Remove unused parameter
af05467
Async suffix
c471c65
Remove type and fix test
03f9c47
Register in rzls and fix tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
.../src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/DocumentDiagnosticsEndpoint.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Razor.Language; | ||
| using Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics; | ||
| using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; | ||
| using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; | ||
| using Microsoft.AspNetCore.Razor.PooledObjects; | ||
| using Microsoft.AspNetCore.Razor.ProjectSystem; | ||
| using Microsoft.AspNetCore.Razor.Telemetry; | ||
| using Microsoft.CodeAnalysis.Razor.Diagnostics; | ||
| using Microsoft.CodeAnalysis.Razor.Protocol; | ||
| using Microsoft.CodeAnalysis.Razor.Workspaces.Telemetry; | ||
| using Microsoft.VisualStudio.LanguageServer.Protocol; | ||
|
|
||
| namespace Microsoft.AspNetCore.Razor.LanguageServer.Hosting.Diagnostics; | ||
|
|
||
| [RazorLanguageServerEndpoint(Methods.TextDocumentDiagnosticName)] | ||
| internal sealed class DocumentDiagnosticsEndpoint( | ||
| RazorTranslateDiagnosticsService translateDiagnosticsService, | ||
| IClientConnection clientConnection, | ||
| ITelemetryReporter? telemetryReporter) | ||
| : IRazorRequestHandler<DocumentDiagnosticParams, FullDocumentDiagnosticReport?>, ICapabilitiesProvider | ||
| { | ||
| private readonly RazorTranslateDiagnosticsService _translateDiagnosticsService = translateDiagnosticsService; | ||
| private readonly IClientConnection _clientConnection = clientConnection; | ||
| private readonly ITelemetryReporter? _telemetryReporter = telemetryReporter; | ||
| private readonly MissingTagHelperTelemetryReporter? _missingTagHelperTelemetryReporter = telemetryReporter is null ? null : new(telemetryReporter); | ||
|
|
||
| public bool MutatesSolutionState => false; | ||
|
|
||
| public TextDocumentIdentifier GetTextDocumentIdentifier(DocumentDiagnosticParams request) | ||
| => request.TextDocument; | ||
|
|
||
| public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, VSInternalClientCapabilities clientCapabilities) | ||
| { | ||
| serverCapabilities.SupportsDiagnosticRequests = true; | ||
| serverCapabilities.DiagnosticOptions = new() | ||
| { | ||
| InterFileDependencies = false, | ||
| WorkspaceDiagnostics = false, | ||
| WorkDoneProgress = false | ||
| }; | ||
| } | ||
|
|
||
| public async Task<FullDocumentDiagnosticReport?> HandleRequestAsync(DocumentDiagnosticParams request, RazorRequestContext context, CancellationToken cancellationToken) | ||
| { | ||
| var documentContext = context.DocumentContext; | ||
| if (documentContext is null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var correlationId = Guid.NewGuid(); | ||
| using var __ = _telemetryReporter?.TrackLspRequest(Methods.TextDocumentDiagnosticName, LanguageServerConstants.RazorLanguageServerName, TelemetryThresholds.DiagnosticsRazorTelemetryThreshold, correlationId); | ||
|
|
||
| var documentSnapshot = documentContext.Snapshot; | ||
| var razorDiagnostics = await RazorDiagnosticHelper.GetRazorDiagnosticsAsync(documentSnapshot, cancellationToken).ConfigureAwait(false); | ||
| var csharpDiagnostics = await GetCSharpDiagnosticsAsync(documentSnapshot, request.TextDocument, correlationId, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| var diagnosticCount = | ||
| (razorDiagnostics?.Length ?? 0) + | ||
| (csharpDiagnostics?.Length ?? 0); | ||
|
|
||
| using var _ = ListPool<Diagnostic>.GetPooledObject(out var allDiagnostics); | ||
| allDiagnostics.SetCapacityIfLarger(diagnosticCount); | ||
|
|
||
| if (razorDiagnostics is not null) | ||
| { | ||
| // No extra work to do for Razor diagnostics | ||
| allDiagnostics.AddRange(razorDiagnostics); | ||
|
|
||
| if (_missingTagHelperTelemetryReporter is not null) | ||
| { | ||
| await _missingTagHelperTelemetryReporter.ReportRZ10012TelemetryAsync(documentContext, razorDiagnostics, cancellationToken).ConfigureAwait(false); | ||
| } | ||
| } | ||
|
|
||
| if (csharpDiagnostics is not null) | ||
| { | ||
| var mappedDiagnostics = await _translateDiagnosticsService | ||
| .TranslateAsync(RazorLanguageKind.CSharp, csharpDiagnostics, documentSnapshot, cancellationToken) | ||
| .ConfigureAwait(false); | ||
| allDiagnostics.AddRange(mappedDiagnostics); | ||
| } | ||
|
|
||
| return new() | ||
| { | ||
| Items = [.. allDiagnostics] | ||
| }; | ||
| } | ||
|
|
||
| private async Task<Diagnostic[]?> GetCSharpDiagnosticsAsync(IDocumentSnapshot documentSnapshot, TextDocumentIdentifier razorDocumentIdentifier, Guid correlationId, CancellationToken cancellationToken) | ||
| { | ||
| var delegatedParams = new DelegatedDiagnosticParams( | ||
| new(razorDocumentIdentifier, documentSnapshot.Version), | ||
| correlationId | ||
| ); | ||
|
|
||
| var delegatedResponse = await _clientConnection | ||
| .SendRequestAsync<DelegatedDiagnosticParams, SumType<FullDocumentDiagnosticReport, UnchangedDocumentDiagnosticReport>?>( | ||
| CustomMessageNames.RazorCSharpPullDiagnosticsEndpointName, | ||
| delegatedParams, | ||
| cancellationToken) | ||
| .ConfigureAwait(false); | ||
|
|
||
| return delegatedResponse.HasValue | ||
| ? delegatedResponse.Value.TryGetFirst(out var fullReport) | ||
| ? fullReport.Items | ||
| : null | ||
| : null; | ||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
...icrosoft.AspNetCore.Razor.LanguageServer/Diagnostics/MissingTagHelperTelemetryReporter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Razor.Language.Components; | ||
| using Microsoft.AspNetCore.Razor.ProjectSystem; | ||
| using Microsoft.AspNetCore.Razor.Telemetry; | ||
| using Microsoft.CodeAnalysis.Razor.ProjectSystem; | ||
| using Microsoft.VisualStudio.LanguageServer.Protocol; | ||
|
|
||
| namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics; | ||
|
|
||
| internal sealed class MissingTagHelperTelemetryReporter(ITelemetryReporter telemetryReporter) | ||
| { | ||
| private readonly ITelemetryReporter _telemetryReporter = telemetryReporter; | ||
| private ImmutableDictionary<ProjectKey, int> _lastReportedProjectTagHelperCount = ImmutableDictionary<ProjectKey, int>.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Reports telemetry for RZ10012 "Found markup element with unexpected name" to help track down potential issues | ||
| /// with taghelpers being discovered (or lack thereof) | ||
| /// </summary> | ||
| public async ValueTask ReportRZ10012TelemetryAsync(DocumentContext documentContext, IEnumerable<Diagnostic> razorDiagnostics, CancellationToken cancellationToken) | ||
| { | ||
| var relevantDiagnosticsCount = razorDiagnostics.Count(d => d.Code == ComponentDiagnosticFactory.UnexpectedMarkupElement.Id); | ||
| if (relevantDiagnosticsCount == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var tagHelpers = await documentContext.Project.GetTagHelpersAsync(cancellationToken).ConfigureAwait(false); | ||
| var tagHelperCount = tagHelpers.Length; | ||
| var shouldReport = false; | ||
|
|
||
| ImmutableInterlocked.AddOrUpdate( | ||
| ref _lastReportedProjectTagHelperCount, | ||
| documentContext.Project.Key, | ||
| (k) => | ||
| { | ||
| shouldReport = true; | ||
| return tagHelperCount; | ||
| }, | ||
| (k, currentValue) => | ||
| { | ||
| shouldReport = currentValue != tagHelperCount; | ||
| return tagHelperCount; | ||
| }); | ||
|
|
||
| if (shouldReport) | ||
| { | ||
| _telemetryReporter.ReportEvent( | ||
| "RZ10012", | ||
| Severity.Low, | ||
| new("tagHelpers", tagHelperCount), | ||
| new("RZ10012errors", relevantDiagnosticsCount), | ||
| new("project", documentContext.Project.Key.Id)); | ||
| } | ||
| } | ||
| } |
31 changes: 0 additions & 31 deletions
31
...crosoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.Comparer.cs
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
...oft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.TestAccessor.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.