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 @@ -43,7 +43,7 @@ public async Task SetupAsync()

var delegatedCompletionListProvider = new TestDelegatedCompletionListProvider(responseRewriters, documentMappingService, clientNotifierServiceBase, completionListCache);
var completionListProvider = new CompletionListProvider(razorCompletionListProvider, delegatedCompletionListProvider);
CompletionEndpoint = new RazorCompletionEndpoint(completionListProvider);
CompletionEndpoint = new RazorCompletionEndpoint(completionListProvider, telemetryReporter: null);

var clientCapabilities = new VSInternalClientCapabilities
{
Expand Down Expand Up @@ -147,7 +147,7 @@ public TestDelegatedCompletionListProvider(IEnumerable<DelegatedCompletionRespon
{
}

public override Task<VSInternalCompletionList?> GetCompletionListAsync(int absoluteIndex, VSInternalCompletionContext completionContext, VersionedDocumentContext documentContext, VSInternalClientCapabilities clientCapabilities, CancellationToken cancellationToken)
public override Task<VSInternalCompletionList?> GetCompletionListAsync(int absoluteIndex, VSInternalCompletionContext completionContext, VersionedDocumentContext documentContext, VSInternalClientCapabilities clientCapabilities, Guid correlationId, CancellationToken cancellationToken)
{
return Task.FromResult<VSInternalCompletionList?>(
new VSInternalCompletionList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ public async Task RazorSemanticTokensRangeAsync()
};
var cancellationToken = CancellationToken.None;
var documentVersion = 1;
var correlationId = Guid.Empty;

await UpdateDocumentAsync(documentVersion, DocumentSnapshot, cancellationToken).ConfigureAwait(false);
await RazorSemanticTokenService.GetSemanticTokensAsync(
textDocumentIdentifier, Range, DocumentContext, SemanticTokensLegend, cancellationToken).ConfigureAwait(false);
textDocumentIdentifier, Range, DocumentContext, SemanticTokensLegend, correlationId, cancellationToken).ConfigureAwait(false);
}

private async Task UpdateDocumentAsync(int newVersion, IDocumentSnapshot documentSnapshot, CancellationToken cancellationToken)
Expand Down Expand Up @@ -142,6 +143,7 @@ internal override Task<List<SemanticRange>> GetCSharpSemanticRangesAsync(
TextDocumentIdentifier textDocumentIdentifier,
Range razorRange,
long documentVersion,
Guid correlationId,
CancellationToken cancellationToken,
string previousResultId = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task InitializeRazorSemanticAsync()
var version = 1;
DocumentContext = new VersionedDocumentContext(documentUri, documentSnapshot, version);
Logger = new NoopLogger();
SemanticTokensRangeEndpoint = new SemanticTokensRangeEndpoint();
SemanticTokensRangeEndpoint = new SemanticTokensRangeEndpoint(telemetryReporter: null);
_ = SemanticTokensRangeEndpoint.GetRegistration(new VSInternalClientCapabilities() { SupportsVisualStudioExtensions = true });

var text = await DocumentContext.GetSourceTextAsync(CancellationToken.None).ConfigureAwait(false);
Expand Down Expand Up @@ -163,6 +163,7 @@ internal override Task<List<SemanticRange>> GetCSharpSemanticRangesAsync(
TextDocumentIdentifier textDocumentIdentifier,
Range razorRange,
long documentVersion,
Guid correlationId,
CancellationToken cancellationToken,
string previousResultId = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public async Task RazorSemanticTokensRangeScrollingAsync()
Uri = DocumentUri
};
var cancellationToken = CancellationToken.None;
var correlationId = Guid.Empty;
var documentVersion = 1;

await UpdateDocumentAsync(documentVersion, DocumentSnapshot).ConfigureAwait(false);
Expand All @@ -105,6 +106,7 @@ public async Task RazorSemanticTokensRangeScrollingAsync()
range,
DocumentContext,
SemanticTokensLegend,
correlationId,
cancellationToken);

lineCount = newLineCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ internal record DelegatedCompletionParams(
Position ProjectedPosition,
RazorLanguageKind ProjectedKind,
VSInternalCompletionContext Context,
TextEdit? ProvisionalTextEdit) : IDelegatedParams;
TextEdit? ProvisionalTextEdit,
Guid CorrelationId) : IDelegatedParams;

internal record DelegatedCompletionResolutionContext(
DelegatedCompletionParams OriginalRequestParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

[LanguageServerEndpoint(Methods.TextDocumentCodeActionName)]
[LanguageServerEndpoint(LspEndpointName)]
internal sealed class CodeActionEndpoint : IRazorRequestHandler<VSCodeActionParams, SumType<Command, CodeAction>[]?>, IRegistrationExtension
{
public const string LspEndpointName = Methods.TextDocumentCodeActionName;
private readonly IRazorDocumentMappingService _documentMappingService;
private readonly IEnumerable<IRazorCodeActionProvider> _razorCodeActionProviders;
private readonly IEnumerable<ICSharpCodeActionProvider> _csharpCodeActionProviders;
Expand Down Expand Up @@ -86,7 +87,7 @@ public CodeActionEndpoint(
cancellationToken.ThrowIfCancellationRequested();

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

cancellationToken.ThrowIfCancellationRequested();
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.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand Down Expand Up @@ -33,11 +34,12 @@ public CompletionListProvider(RazorCompletionListProvider razorCompletionListPro
VSInternalCompletionContext completionContext,
VersionedDocumentContext documentContext,
VSInternalClientCapabilities clientCapabilities,
Guid correlationId,
CancellationToken cancellationToken)
{
// First we delegate to get completion items from the individual language server
var delegatedCompletionList = IsValidTrigger(_delegatedCompletionListProvider.TriggerCharacters, completionContext)
? await _delegatedCompletionListProvider.GetCompletionListAsync(absoluteIndex, completionContext, documentContext, clientCapabilities, cancellationToken).ConfigureAwait(false)
? await _delegatedCompletionListProvider.GetCompletionListAsync(absoluteIndex, completionContext, documentContext, clientCapabilities, correlationId, cancellationToken).ConfigureAwait(false)
: null;

// Extract the items we got back from the delegated server, to inform tag helper completion
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.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand Down Expand Up @@ -48,6 +49,7 @@ public DelegatedCompletionListProvider(
VSInternalCompletionContext completionContext,
VersionedDocumentContext documentContext,
VSInternalClientCapabilities clientCapabilities,
Guid correlationId,
CancellationToken cancellationToken)
{
var positionInfo = await _documentMappingService.GetPositionInfoAsync(documentContext, absoluteIndex, cancellationToken).ConfigureAwait(false);
Expand All @@ -73,7 +75,8 @@ public DelegatedCompletionListProvider(
positionInfo.Position,
positionInfo.LanguageKind,
completionContext,
provisionalTextEdit);
provisionalTextEdit,
correlationId);

var delegatedResponse = await _languageServer.SendRequestAsync<DelegatedCompletionParams, VSInternalCompletionList?>(
LanguageServerConstants.RazorCompletionEndpointName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
// 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.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion;

internal class RazorCompletionEndpoint : IVSCompletionEndpoint
{
private readonly CompletionListProvider _completionListProvider;
private readonly ITelemetryReporter? _telemetryReporter;
private VSInternalClientCapabilities? _clientCapabilities;

public RazorCompletionEndpoint(CompletionListProvider completionListProvider)
public RazorCompletionEndpoint(CompletionListProvider completionListProvider, ITelemetryReporter? telemetryReporter)
{
_completionListProvider = completionListProvider;
_telemetryReporter = telemetryReporter;
}

public bool MutatesSolutionState => false;
Expand Down Expand Up @@ -65,11 +70,14 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(CompletionParams request
return null;
}

var correlationId = Guid.NewGuid();
using var _ = _telemetryReporter?.TrackLspRequest(Methods.TextDocumentCompletionName, LanguageServerConstants.RazorLanguageServerName, correlationId);
var completionList = await _completionListProvider.GetCompletionListAsync(
hostDocumentIndex,
completionContext,
documentContext,
_clientCapabilities!,
correlationId,
cancellationToken).ConfigureAwait(false);
return completionList;
}
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.VisualStudio.LanguageServer.Protocol;

Expand All @@ -14,10 +15,14 @@ internal class ProvideSemanticTokensRangeParams : SemanticTokensParams
[DataMember(Name = "range", IsRequired = true)]
public Range Range { get; }

public ProvideSemanticTokensRangeParams(TextDocumentIdentifier textDocument, long requiredHostDocumentVersion, Range range)
[DataMember(Name = "correlationId", IsRequired = true)]
public Guid CorrelationId { get; }

public ProvideSemanticTokensRangeParams(TextDocumentIdentifier textDocument, long requiredHostDocumentVersion, Range range, Guid correlationId)
{
TextDocument = textDocument;
RequiredHostDocumentVersion = requiredHostDocumentVersion;
Range = range;
CorrelationId = correlationId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic.Models;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic;

[LanguageServerEndpoint(Methods.TextDocumentSemanticTokensRangeName)]
[LanguageServerEndpoint(LspEndpointName)]
internal sealed class SemanticTokensRangeEndpoint : IRazorRequestHandler<SemanticTokensRangeParams, SemanticTokens?>, IRegistrationExtension
{
public const string LspEndpointName = Methods.TextDocumentSemanticTokensRangeName;
private RazorSemanticTokensLegend? _razorSemanticTokensLegend;
private readonly ITelemetryReporter? _telemetryReporter;

public SemanticTokensRangeEndpoint(ITelemetryReporter? telemetryReporter)
{
_telemetryReporter = telemetryReporter;
}

public bool MutatesSolutionState { get; } = false;

Expand Down Expand Up @@ -49,7 +58,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(SemanticTokensRangeParam
var documentContext = requestContext.GetRequiredDocumentContext();
var semanticTokensInfoService = requestContext.GetRequiredService<IRazorSemanticTokensInfoService>();

var semanticTokens = await semanticTokensInfoService.GetSemanticTokensAsync(request.TextDocument, request.Range, documentContext, _razorSemanticTokensLegend.AssumeNotNull(), cancellationToken).ConfigureAwait(false);
var correlationId = Guid.NewGuid();
using var _ = _telemetryReporter?.TrackLspRequest(LspEndpointName, LanguageServerConstants.RazorLanguageServerName, correlationId);
var semanticTokens = await semanticTokensInfoService.GetSemanticTokensAsync(request.TextDocument, request.Range, documentContext, _razorSemanticTokensLegend.AssumeNotNull(), correlationId, cancellationToken).ConfigureAwait(false);
var amount = semanticTokens is null ? "no" : (semanticTokens.Data.Length / 5).ToString(Thread.CurrentThread.CurrentCulture);

requestContext.Logger.LogInformation("Returned {amount} semantic tokens for range {request.Range} in {request.TextDocument.Uri}.", amount, request.Range, request.TextDocument.Uri);
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.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand All @@ -9,5 +10,5 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic;

internal interface IRazorSemanticTokensInfoService
{
Task<SemanticTokens?> GetSemanticTokensAsync(TextDocumentIdentifier textDocumentIdentifier, Range range, VersionedDocumentContext documentContext, RazorSemanticTokensLegend razorSemanticTokensLegend, CancellationToken cancellationToken);
Task<SemanticTokens?> GetSemanticTokensAsync(TextDocumentIdentifier textDocumentIdentifier, Range range, VersionedDocumentContext documentContext, RazorSemanticTokensLegend razorSemanticTokensLegend, Guid correlationId, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public RazorSemanticTokensInfoService(
Range range,
VersionedDocumentContext documentContext,
RazorSemanticTokensLegend razorSemanticTokensLegend,
Guid correlationId,
CancellationToken cancellationToken)
{
var codeDocument = await documentContext.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -58,7 +59,7 @@ public RazorSemanticTokensInfoService(
try
{
csharpSemanticRanges = await GetCSharpSemanticRangesAsync(
codeDocument, textDocumentIdentifier, range, documentContext.Version, cancellationToken).ConfigureAwait(false);
codeDocument, textDocumentIdentifier, range, documentContext.Version, correlationId, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -108,6 +109,7 @@ public RazorSemanticTokensInfoService(
TextDocumentIdentifier textDocumentIdentifier,
Range razorRange,
long documentVersion,
Guid correlationId,
CancellationToken cancellationToken,
string? previousResultId = null)
{
Expand All @@ -120,7 +122,7 @@ public RazorSemanticTokensInfoService(
return new List<SemanticRange>();
}

var csharpResponse = await GetMatchingCSharpResponseAsync(textDocumentIdentifier, documentVersion, csharpRange, cancellationToken).ConfigureAwait(false);
var csharpResponse = await GetMatchingCSharpResponseAsync(textDocumentIdentifier, documentVersion, csharpRange, correlationId, cancellationToken).ConfigureAwait(false);

// Indicates an issue with retrieving the C# response (e.g. no response or C# is out of sync with us).
// Unrecoverable, return default to indicate no change. We've already queued up a refresh request in
Expand Down Expand Up @@ -210,9 +212,10 @@ internal static bool TryGetMinimalCSharpRange(RazorCodeDocument codeDocument, Ra
TextDocumentIdentifier textDocumentIdentifier,
long documentVersion,
Range csharpRange,
Guid correlationId,
CancellationToken cancellationToken)
{
var parameter = new ProvideSemanticTokensRangeParams(textDocumentIdentifier, documentVersion, csharpRange);
var parameter = new ProvideSemanticTokensRangeParams(textDocumentIdentifier, documentVersion, csharpRange, correlationId);

var csharpResponse = await _languageServer.SendRequestAsync<ProvideSemanticTokensRangeParams, ProvideSemanticTokensResponse>(
RazorLanguageServerCustomMessageTargets.RazorProvideSemanticTokensRangeEndpoint,
Expand Down
Loading