Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -52,7 +52,8 @@ public async Task SetupAsync()
csharpCodeActionProviders: languageServer.GetRequiredService<IEnumerable<ICSharpCodeActionProvider>>(),
htmlCodeActionProviders: languageServer.GetRequiredService<IEnumerable<IHtmlCodeActionProvider>>(),
languageServer: languageServer.GetRequiredService<ClientNotifierServiceBase>(),
languageServerFeatureOptions: languageServer.GetRequiredService<LanguageServerFeatureOptions>());
languageServerFeatureOptions: languageServer.GetRequiredService<LanguageServerFeatureOptions>(),
telemetryReporter: null);

var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
var projectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class RazorSemanticTokensRangeEndpointBenchmark : RazorLanguageServerBenc

private static List<SemanticRange> PregeneratedRandomSemanticRanges { get; set; }


[GlobalSetup]
public async Task InitializeRazorSemanticAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public IDisposable BeginBlock(string name, Severity severity, ImmutableDictionar
return NullScope.Instance;
}

public IDisposable TrackLspRequest(string name, string lspMethodName, string lspServerName, Guid correlationId)
public IDisposable TrackLspRequest(string lspMethodName, string lspServerName, Guid correlationId)
{
return NullScope.Instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
Expand All @@ -35,6 +36,7 @@ internal sealed class CodeActionEndpoint : IRazorRequestHandler<VSCodeActionPara
private readonly IEnumerable<IHtmlCodeActionProvider> _htmlCodeActionProviders;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
private readonly ClientNotifierServiceBase _languageServer;
private readonly ITelemetryReporter? _telemetryReporter;

internal bool _supportsCodeActionResolve = false;

Expand All @@ -48,14 +50,16 @@ public CodeActionEndpoint(
IEnumerable<ICSharpCodeActionProvider> csharpCodeActionProviders,
IEnumerable<IHtmlCodeActionProvider> htmlCodeActionProviders,
ClientNotifierServiceBase languageServer,
LanguageServerFeatureOptions languageServerFeatureOptions)
LanguageServerFeatureOptions languageServerFeatureOptions,
ITelemetryReporter? telemetryReporter)
{
_documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService));
_razorCodeActionProviders = razorCodeActionProviders ?? throw new ArgumentNullException(nameof(razorCodeActionProviders));
_csharpCodeActionProviders = csharpCodeActionProviders ?? throw new ArgumentNullException(nameof(csharpCodeActionProviders));
_htmlCodeActionProviders = htmlCodeActionProviders ?? throw new ArgumentNullException(nameof(htmlCodeActionProviders));
_languageServer = languageServer ?? throw new ArgumentNullException(nameof(languageServer));
_languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions));
_telemetryReporter = telemetryReporter;

_allAvailableCodeActionNames = GetAllAvailableCodeActionNames();
}
Expand All @@ -81,14 +85,16 @@ public CodeActionEndpoint(

cancellationToken.ThrowIfCancellationRequested();

var correlationId = Guid.NewGuid();
using var __ = _telemetryReporter?.TrackLspRequest(Methods.TextDocumentCodeActionName, LanguageServerConstants.RazorLanguageServerName, correlationId);
var razorCodeActions = await GetRazorCodeActionsAsync(razorCodeActionContext, cancellationToken).ConfigureAwait(false);

cancellationToken.ThrowIfCancellationRequested();

// HTML code actions aren't currently supported in VS Code:
// https://github.com/dotnet/razor/issues/8062
var delegatedCodeActions = _languageServerFeatureOptions.SupportsDelegatedCodeActions
? await GetDelegatedCodeActionsAsync(documentContext, razorCodeActionContext, requestContext.Logger, cancellationToken).ConfigureAwait(false)
? await GetDelegatedCodeActionsAsync(documentContext, razorCodeActionContext, correlationId, requestContext.Logger, cancellationToken).ConfigureAwait(false)
: ImmutableArray.Create<RazorVSInternalCodeAction>();

cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -187,7 +193,7 @@ public RegistrationExtensionResult GetRegistration(VSInternalClientCapabilities
return context;
}

private async Task<ImmutableArray<RazorVSInternalCodeAction>> GetDelegatedCodeActionsAsync(VersionedDocumentContext documentContext, RazorCodeActionContext context, IRazorLogger logger, CancellationToken cancellationToken)
private async Task<ImmutableArray<RazorVSInternalCodeAction>> GetDelegatedCodeActionsAsync(VersionedDocumentContext documentContext, RazorCodeActionContext context, Guid correlationId, IRazorLogger logger, CancellationToken cancellationToken)
{
var languageKind = _documentMappingService.GetLanguageKind(context.CodeDocument, context.Location.AbsoluteIndex, rightAssociative: false);

Expand All @@ -197,7 +203,7 @@ private async Task<ImmutableArray<RazorVSInternalCodeAction>> GetDelegatedCodeAc
return ImmutableArray<RazorVSInternalCodeAction>.Empty;
}

var codeActions = await GetCodeActionsFromLanguageServerAsync(languageKind, documentContext, context, logger, cancellationToken).ConfigureAwait(false);
var codeActions = await GetCodeActionsFromLanguageServerAsync(languageKind, documentContext, context, correlationId, logger, cancellationToken).ConfigureAwait(false);
if (codeActions is not [_, ..])
{
return ImmutableArray<RazorVSInternalCodeAction>.Empty;
Expand Down Expand Up @@ -269,7 +275,7 @@ private static async Task<ImmutableArray<RazorVSInternalCodeAction>> FilterCodeA
}

// Internal for testing
internal async Task<RazorVSInternalCodeAction[]> GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, VersionedDocumentContext documentContext, RazorCodeActionContext context, IRazorLogger logger, CancellationToken cancellationToken)
internal async Task<RazorVSInternalCodeAction[]> GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, VersionedDocumentContext documentContext, RazorCodeActionContext context, Guid correlationId, IRazorLogger logger, CancellationToken cancellationToken)
{
if (languageKind == RazorLanguageKind.CSharp)
{
Expand Down Expand Up @@ -297,7 +303,8 @@ internal async Task<RazorVSInternalCodeAction[]> GetCodeActionsFromLanguageServe
{
HostDocumentVersion = documentContext.Version,
CodeActionParams = context.Request,
LanguageKind = languageKind
LanguageKind = languageKind,
CorrelationId = correlationId
};

try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Runtime.Serialization;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
Expand All @@ -18,4 +19,7 @@ internal class DelegatedCodeActionParams

[DataMember(Name = "languageKind")]
public RazorLanguageKind LanguageKind { get; set; }

[DataMember(Name = "correlationId")]
public Guid CorrelationId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalDocumentDiagno
}

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

var razorDiagnostics = await GetRazorDiagnosticsAsync(documentContext, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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);
IDisposable TrackLspRequest(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,7 +36,7 @@ public IDisposable BeginBlock(string name, Severity severity, ImmutableDictionar
return NullScope.Instance;
}

public IDisposable TrackLspRequest(string name, string lspMethodName, string lspServerName, Guid correlationId)
public IDisposable TrackLspRequest(string lspMethodName, string lspServerName, Guid correlationId)
{
return NullScope.Instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ 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)
public IDisposable TrackLspRequest(string lspMethodName, string languageServerName, Guid correlationId)
{
if (correlationId == Guid.Empty)
{
return NullTelemetryScope.Instance;
}

return BeginBlock(name, Severity.Normal, ImmutableDictionary.CreateRange(new KeyValuePair<string, object?>[]
return BeginBlock("TrackLspRequest", Severity.Normal, ImmutableDictionary.CreateRange(new KeyValuePair<string, object?>[]
{
new("eventscope.method", lspMethodName),
new("eventscope.languageservername", languageServerName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,22 @@ public override async Task<RazorDocumentFormattingResponse> HtmlOnTypeFormatting

bool synchronized;
VirtualDocumentSnapshot virtualDocumentSnapshot;
string languageServerName;
if (codeActionParams.LanguageKind == RazorLanguageKind.Html)
{
(synchronized, virtualDocumentSnapshot) = await _documentSynchronizer.TrySynchronizeVirtualDocumentAsync<HtmlVirtualDocumentSnapshot>(
codeActionParams.HostDocumentVersion,
codeActionParams.CodeActionParams.TextDocument.Uri,
cancellationToken);
languageServerName = RazorLSPConstants.RazorCSharpLanguageServerName;
}
else if (codeActionParams.LanguageKind == RazorLanguageKind.CSharp)
{
(synchronized, virtualDocumentSnapshot) = await _documentSynchronizer.TrySynchronizeVirtualDocumentAsync<CSharpVirtualDocumentSnapshot>(
codeActionParams.HostDocumentVersion,
codeActionParams.CodeActionParams.TextDocument.Uri,
cancellationToken);
languageServerName = RazorLSPConstants.HtmlLanguageServerName;
}
else
{
Expand All @@ -294,6 +297,7 @@ public override async Task<RazorDocumentFormattingResponse> HtmlOnTypeFormatting
codeActionParams.CodeActionParams.TextDocument.Uri = virtualDocumentSnapshot.Uri;

var textBuffer = virtualDocumentSnapshot.Snapshot.TextBuffer;
using var _ = _telemetryReporter.TrackLspRequest(Methods.TextDocumentCodeActionName, languageServerName, codeActionParams.CorrelationId);
var requests = _requestInvoker.ReinvokeRequestOnMultipleServersAsync<VSCodeActionParams, IReadOnlyList<VSInternalCodeAction>>(
textBuffer,
Methods.TextDocumentCodeActionName,
Expand Down Expand Up @@ -1165,7 +1169,7 @@ public override Task<ImplementationResult> ImplementationAsync(DelegatedPosition
},
};

using var _ = _telemetryReporter.TrackLspRequest(nameof(_requestInvoker.ReinvokeRequestOnServerAsync), VSInternalMethods.DocumentPullDiagnosticName, delegatedLanguageServerName, correlationId);
using var _ = _telemetryReporter.TrackLspRequest(VSInternalMethods.DocumentPullDiagnosticName, delegatedLanguageServerName, correlationId);
var response = await _requestInvoker.ReinvokeRequestOnServerAsync<VSInternalDocumentDiagnosticsParams, VSInternalDiagnosticReport[]?>(
virtualDocument.Snapshot.TextBuffer,
VSInternalMethods.DocumentPullDiagnosticName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private async Task ValidateCodeActionAsync(string input, string expected, string
};
var htmlCodeActionProviders = Array.Empty<IHtmlCodeActionProvider>();

var endpoint = new CodeActionEndpoint(DocumentMappingService, razorCodeActionProviders, csharpCodeActionProviders, htmlCodeActionProviders, LanguageServer, LanguageServerFeatureOptions);
var endpoint = new CodeActionEndpoint(DocumentMappingService, razorCodeActionProviders, csharpCodeActionProviders, htmlCodeActionProviders, LanguageServer, LanguageServerFeatureOptions, default);

// Call GetRegistration, so the endpoint knows we support resolve
endpoint.GetRegistration(new VSInternalClientCapabilities
Expand Down
Loading