Skip to content

Commit 984ece1

Browse files
authored
Init semantic token refresh, and queue on request (#12367)
Fixes #11848 ~Consumes dotnet/roslyn#80815 to won't build until we bump Roslyn~ Update: This now needs to consume dotnet/roslyn#80830 because we already had an EA service for semantic tokens, so we should use it Just a bit of finishing touches to semantic tokens in cohosting.
2 parents bcb02e6 + 56d7009 commit 984ece1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ internal sealed class CohostSemanticTokensRangeEndpoint(
3939
protected override RazorTextDocumentIdentifier? GetRazorTextDocumentIdentifier(SemanticTokensRangeParams request)
4040
=> request.TextDocument.ToRazorTextDocumentIdentifier();
4141

42+
protected override async Task<SemanticTokens?> HandleRequestAsync(SemanticTokensRangeParams request, RazorCohostRequestContext context, TextDocument razorDocument, CancellationToken cancellationToken)
43+
{
44+
var result = await HandleRequestAsync(request, razorDocument, cancellationToken).ConfigureAwait(false);
45+
46+
if (result is not null)
47+
{
48+
// Roslyn uses frozen semantics for semantic tokens, so it could return results from an older project state.
49+
// Every time they get a request they queue up a refresh, which will check the project checksums, and if there
50+
// hasn't been any changes, will no-op. We call into that same logic here to ensure everything is up to date.
51+
// See: https://github.com/dotnet/roslyn/blob/bb57f4643bb3d52eb7626f9863da177d9e219f1e/src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs#L48-L52
52+
var semanticTokensWrapperService = context.GetRequiredService<IRazorSemanticTokensRefreshQueue>();
53+
await semanticTokensWrapperService.TryEnqueueRefreshComputationAsync(razorDocument.Project, cancellationToken).ConfigureAwait(false);
54+
}
55+
56+
return result;
57+
}
58+
4259
protected override Task<SemanticTokens?> HandleRequestAsync(SemanticTokensRangeParams request, TextDocument razorDocument, CancellationToken cancellationToken)
4360
=> HandleRequestAsync(razorDocument, request.Range.ToLinePositionSpan(), cancellationToken);
4461

0 commit comments

Comments
 (0)