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
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
using Microsoft.CodeAnalysis.Razor.Workspaces;

namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;

[Export(typeof(IRazorCohostStartupService))]
[method: ImportingConstructor]
internal class CohostSemanticTokensInitializeService(
LanguageServerFeatureOptions languageServerFeatureOptions) : IRazorCohostStartupService
{
private readonly LanguageServerFeatureOptions _options = languageServerFeatureOptions;

public int Order => WellKnownStartupOrder.Default;

public Task StartupAsync(VSInternalClientCapabilities clientCapabilities, RazorCohostRequestContext requestContext, CancellationToken cancellationToken)
{
if (_options.UseRazorCohostServer)
{
// Normally, Roslyn triggers semantic tokens refreshes for additional document changes, but not for Razor documents.
// In cohosting, we want it to consider Razor documents too.
CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers.SemanticTokensRange.RegisterRefresh(requestContext);
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@
protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(SemanticTokensRangeParams request)
=> request.TextDocument.ToRazorTextDocumentIdentifier();

protected override async Task<SemanticTokens?> HandleRequestAsync(SemanticTokensRangeParams request, RazorCohostRequestContext context, TextDocument razorDocument, CancellationToken cancellationToken)
{
var result = await HandleRequestAsync(request, razorDocument, cancellationToken).ConfigureAwait(false);

if (result is not null)
{
// Roslyn uses frozen semantics for semantic tokens, so it could return results from an older project state.
// Every time they get a request they queue up a refresh, which will check the project checksums, and if there
// hasn't been any changes, will no-op. We call into that same logic here to ensure everything is up to date.
// See: https://github.com/dotnet/roslyn/blob/bb57f4643bb3d52eb7626f9863da177d9e219f1e/src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs#L48-L52
await CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers.SemanticTokensRange.TryEnqueueRefreshComputationAsync(context, razorDocument.Project, cancellationToken).ConfigureAwait(false);

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build Linux release)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build Linux release)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build Linux debug)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build Linux debug)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build macOS release)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build macOS release)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build macOS debug)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci (Build macOS debug)

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'

Check failure on line 52 in src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs

View check run for this annotation

Azure Pipelines / razor-tooling-ci

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs#L52

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SemanticTokens/CohostSemanticTokensRangeEndpoint.cs(52,89): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'SemanticTokensRange' does not contain a definition for 'TryEnqueueRefreshComputationAsync'
}

return result;
}

protected override Task<SemanticTokens?> HandleRequestAsync(SemanticTokensRangeParams request, TextDocument razorDocument, CancellationToken cancellationToken)
=> HandleRequestAsync(razorDocument, request.Range.ToLinePositionSpan(), cancellationToken);

Expand Down
Loading