Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task SetupAsync()
DocumentPullDiagnosticsEndpoint = new DocumentPullDiagnosticsEndpoint(
languageServerFeatureOptions: languageServer.GetRequiredService<LanguageServerFeatureOptions>(),
translateDiagnosticsService: languageServer.GetRequiredService<RazorTranslateDiagnosticsService>(),
languageServer: new ClientNotifierService(BuildDiagnostics(N)));
languageServer: new ClientNotifierService(BuildDiagnostics(N)), telemetryReporter: null);
var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
var projectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
_filePath = Path.Combine(projectRoot, "Components", "Pages", $"Generated.razor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public IDisposable BeginBlock(string name, Severity severity, ImmutableDictionar
return NullScope.Instance;
}

public IDisposable TrackLspRequest(string name, string lspMethodName, string lspServerName, Guid correlationId)
{
return NullScope.Instance;
}

private class NullScope : IDisposable
{
public static NullScope Instance { get; } = new NullScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static class LanguageServerConstants

public const string RazorProximityExpressionsEndpoint = "razor/proximityExpressions";

public const string RazorLanguageServerName = "Razor Language Server Client";

public const string RazorMonitorProjectConfigurationFilePathEndpoint = "razor/monitorProjectConfigurationFilePath";

public const string RazorMapToDocumentRangesEndpoint = "razor/mapToDocumentRanges";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// 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 Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;

// A file for delegated record types to be put. Each individually
// should be a plain record. If more logic is needed than record
Expand All @@ -10,7 +12,8 @@
namespace Microsoft.AspNetCore.Razor.LanguageServer.Protocol;

internal record DelegatedDiagnosticParams(
VersionedTextDocumentIdentifier HostDocument);
VersionedTextDocumentIdentifier HostDocument,
Guid CorrelationId);

internal record DelegatedPositionParams(
VersionedTextDocumentIdentifier HostDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand All @@ -22,15 +23,18 @@ internal class DocumentPullDiagnosticsEndpoint : IRazorRequestHandler<VSInternal
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
private readonly ClientNotifierServiceBase _languageServer;
private readonly RazorTranslateDiagnosticsService _translateDiagnosticsService;
private readonly ITelemetryReporter? _telemetryReporter;

public DocumentPullDiagnosticsEndpoint(
LanguageServerFeatureOptions languageServerFeatureOptions,
RazorTranslateDiagnosticsService translateDiagnosticsService,
ClientNotifierServiceBase languageServer)
ClientNotifierServiceBase languageServer,
ITelemetryReporter? telemetryReporter)
{
_languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions));
_translateDiagnosticsService = translateDiagnosticsService ?? throw new ArgumentNullException(nameof(translateDiagnosticsService));
_languageServer = languageServer ?? throw new ArgumentNullException(nameof(languageServer));
_telemetryReporter = telemetryReporter;
}

public bool MutatesSolutionState => false;
Expand All @@ -57,11 +61,13 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalDocumentDiagno
return default;
}

var correlationId = Guid.NewGuid();
using var __ = _telemetryReporter?.TrackLspRequest("diagnostics", VSInternalMethods.DocumentPullDiagnosticName, LanguageServerConstants.RazorLanguageServerName, correlationId);
var documentContext = context.GetRequiredDocumentContext();

var razorDiagnostics = await GetRazorDiagnosticsAsync(documentContext, cancellationToken).ConfigureAwait(false);

var (csharpDiagnostics, htmlDiagnostics) = await GetHtmlCSharpDiagnosticsAsync(documentContext, cancellationToken).ConfigureAwait(false);
var (csharpDiagnostics, htmlDiagnostics) = await GetHtmlCSharpDiagnosticsAsync(documentContext, correlationId, cancellationToken).ConfigureAwait(false);

using var _ = ListPool<VSInternalDiagnosticReport>.GetPooledObject(out var allDiagnostics);
allDiagnostics.SetCapacityIfLarger(
Expand Down Expand Up @@ -131,9 +137,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalDocumentDiagno
return razorDiagnostics;
}

private async Task<(VSInternalDiagnosticReport[]? CSharpDiagnostics, VSInternalDiagnosticReport[]? HtmlDiagnostics)> GetHtmlCSharpDiagnosticsAsync(VersionedDocumentContext documentContext, CancellationToken cancellationToken)
private async Task<(VSInternalDiagnosticReport[]? CSharpDiagnostics, VSInternalDiagnosticReport[]? HtmlDiagnostics)> GetHtmlCSharpDiagnosticsAsync(VersionedDocumentContext documentContext, Guid correlationId, CancellationToken cancellationToken)
{
var delegatedParams = new DelegatedDiagnosticParams(documentContext.Identifier);
var delegatedParams = new DelegatedDiagnosticParams(documentContext.Identifier, correlationId);
var delegatedResponse = await _languageServer.SendRequestAsync<DelegatedDiagnosticParams, RazorPullDiagnosticResponse?>(
RazorLanguageServerCustomMessageTargets.RazorPullDiagnosticEndpointName,
delegatedParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface ITelemetryReporter
{
IDisposable BeginBlock(string name, Severity severity);
IDisposable BeginBlock(string name, Severity severity, ImmutableDictionary<string, object?> values);
IDisposable TrackLspRequest(string name, string lspMethodName, string lspServerName, Guid correlationId);
void ReportEvent(string name, Severity severity);
void ReportEvent(string name, Severity severity, ImmutableDictionary<string, object?> values);
void ReportFault(Exception exception, string? message, params object?[] @params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public IDisposable BeginBlock(string name, Severity severity, ImmutableDictionar
return NullScope.Instance;
}

public IDisposable TrackLspRequest(string name, string lspMethodName, string lspServerName, Guid correlationId)
{
return NullScope.Instance;
}

private class NullScope : IDisposable
{
public static NullScope Instance { get; } = new NullScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,28 @@ public IDisposable BeginBlock(string name, Severity severity, ImmutableDictionar
return new TelemetryScope(this, name, severity, values.ToImmutableDictionary((tuple) => tuple.Key, (tuple) => (object?)tuple.Value));
}

public IDisposable TrackLspRequest(string name, string lspMethodName, string languageServerName, Guid correlationId)
{
if (correlationId == Guid.Empty)
{
return NullTelemetryScope.Instance;
}

return BeginBlock(name, Severity.Normal, ImmutableDictionary.CreateRange(new KeyValuePair<string, object?>[]
{
new("eventscope.method", lspMethodName),
new("eventscope.languageservername", languageServerName),
new("eventscope.correlationid", correlationId),
}));
}

private class NullTelemetryScope : IDisposable
{
public static NullTelemetryScope Instance { get; } = new NullTelemetryScope();
private NullTelemetryScope() { }
public void Dispose() { }
}

private class TelemetryScope : IDisposable
{
private readonly ITelemetryReporter _telemetryReporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal class DefaultRazorLanguageServerCustomMessageTarget : RazorLanguageServ
private readonly TrackingLSPDocumentManager _documentManager;
private readonly JoinableTaskFactory _joinableTaskFactory;
private readonly LSPRequestInvoker _requestInvoker;
private readonly ITelemetryReporter _telemetryReporter;
private readonly FormattingOptionsProvider _formattingOptionsProvider;
private readonly IClientSettingsManager _editorSettingsManager;
private readonly LSPDocumentSynchronizer _documentSynchronizer;
Expand Down Expand Up @@ -106,10 +107,11 @@ public DefaultRazorLanguageServerCustomMessageTarget(

_joinableTaskFactory = joinableTaskContext.Factory;

_requestInvoker = new TelemetryReportingLSPRequestInvoker(requestInvoker, telemetryReporter);
_requestInvoker = requestInvoker;
_formattingOptionsProvider = formattingOptionsProvider;
_editorSettingsManager = editorSettingsManager;
_documentSynchronizer = documentSynchronizer;
_telemetryReporter = telemetryReporter;
_outputWindowLogger = outputWindowLogger;
}

Expand Down Expand Up @@ -1117,8 +1119,8 @@ public override Task<ImplementationResult> ImplementationAsync(DelegatedPosition

public override async Task<RazorPullDiagnosticResponse?> DiagnosticsAsync(DelegatedDiagnosticParams request, CancellationToken cancellationToken)
{
var csharpTask = Task.Run(() => GetVirtualDocumentPullDiagnosticsAsync<CSharpVirtualDocumentSnapshot>(request.HostDocument, RazorLSPConstants.RazorCSharpLanguageServerName, cancellationToken), cancellationToken);
var htmlTask = Task.Run(() => GetVirtualDocumentPullDiagnosticsAsync<HtmlVirtualDocumentSnapshot>(request.HostDocument, RazorLSPConstants.HtmlLanguageServerName, cancellationToken), cancellationToken);
var csharpTask = Task.Run(() => GetVirtualDocumentPullDiagnosticsAsync<CSharpVirtualDocumentSnapshot>(request.HostDocument, request.CorrelationId, RazorLSPConstants.RazorCSharpLanguageServerName, cancellationToken), cancellationToken);
var htmlTask = Task.Run(() => GetVirtualDocumentPullDiagnosticsAsync<HtmlVirtualDocumentSnapshot>(request.HostDocument, request.CorrelationId, RazorLSPConstants.HtmlLanguageServerName, cancellationToken), cancellationToken);

try
{
Expand All @@ -1143,7 +1145,7 @@ public override Task<ImplementationResult> ImplementationAsync(DelegatedPosition
return new RazorPullDiagnosticResponse(csharpDiagnostics, htmlDiagnostics);
}

private async Task<VSInternalDiagnosticReport[]?> GetVirtualDocumentPullDiagnosticsAsync<TVirtualDocumentSnapshot>(VersionedTextDocumentIdentifier hostDocument, string delegatedLanguageServerName, CancellationToken cancellationToken)
private async Task<VSInternalDiagnosticReport[]?> GetVirtualDocumentPullDiagnosticsAsync<TVirtualDocumentSnapshot>(VersionedTextDocumentIdentifier hostDocument, Guid correlationId, string delegatedLanguageServerName, CancellationToken cancellationToken)
where TVirtualDocumentSnapshot : VirtualDocumentSnapshot
{
var (synchronized, virtualDocument) = await _documentSynchronizer.TrySynchronizeVirtualDocumentAsync<TVirtualDocumentSnapshot>(
Expand All @@ -1162,6 +1164,8 @@ public override Task<ImplementationResult> ImplementationAsync(DelegatedPosition
Uri = virtualDocument.Uri,
},
};

using var _ = _telemetryReporter.TrackLspRequest(nameof(_requestInvoker.ReinvokeRequestOnServerAsync), VSInternalMethods.DocumentPullDiagnosticName, delegatedLanguageServerName, correlationId);
var response = await _requestInvoker.ReinvokeRequestOnServerAsync<VSInternalDocumentDiagnosticsParams, VSInternalDiagnosticReport[]?>(
virtualDocument.Snapshot.TextBuffer,
VSInternalMethods.DocumentPullDiagnosticName,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private async Task ValidateDiagnosticsAsync(string input)
var requestContext = new RazorRequestContext(documentContext, Logger, null!);

var translateDiagnosticsService = new RazorTranslateDiagnosticsService(DocumentMappingService, LoggerFactory);
var diagnosticsEndPoint = new DocumentPullDiagnosticsEndpoint(LanguageServerFeatureOptions, translateDiagnosticsService, LanguageServer);
var diagnosticsEndPoint = new DocumentPullDiagnosticsEndpoint(LanguageServerFeatureOptions, translateDiagnosticsService, LanguageServer, telemetryReporter: null);

var diagnosticsRequest = new VSInternalDocumentDiagnosticsParams
{
Expand Down