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
7 changes: 5 additions & 2 deletions src/Features/Lsif/Generator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,22 @@ private static async Task GenerateSemanticTokensAsync(
IdFactory idFactory,
LsifDocument documentVertex)
{
var cancellationToken = CancellationToken.None;

// Compute colorization data.
//
// Unlike the mainline LSP scenario, where we control both the syntactic colorizer (in-proc syntax tagger)
// and the semantic colorizer (LSP semantic tokens) LSIF is more likely to be consumed by clients which may
// have different syntactic classification behavior than us, resulting in missing colors. To avoid this, we
// include syntax tokens in the generated data.
var text = await document.GetTextAsync(cancellationToken);
var data = await SemanticTokensHelpers.ComputeSemanticTokensDataAsync(
// Just get the pure-lsp semantic tokens here.
document,
spans: [],
spans: [text.Lines.GetLinePositionSpan(new TextSpan(0, text.Length))],
supportsVisualStudioExtensions: true,
options: Classification.ClassificationOptions.Default,
cancellationToken: CancellationToken.None);
cancellationToken);

var semanticTokensResult = new SemanticTokensResult(new SemanticTokens { Data = data }, idFactory);
var semanticTokensEdge = Edge.Create(Methods.TextDocumentSemanticTokensFullName, documentVertex.GetId(), semanticTokensResult.GetId(), idFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,35 @@
namespace Microsoft.CodeAnalysis.LanguageServer.ExternalAccess.Razor;

[Method(SemanticRangesMethodName)]
internal class SemanticTokensRangesHandler : ILspServiceDocumentRequestHandler<SemanticTokensRangesParams, SemanticTokens>
internal sealed class SemanticTokensRangesHandler(
IGlobalOptionService globalOptions,
SemanticTokensRefreshQueue semanticTokensRefreshQueue)
: ILspServiceDocumentRequestHandler<SemanticTokensRangesParams, SemanticTokens>
{
public const string SemanticRangesMethodName = "roslyn/semanticTokenRanges";
private readonly IGlobalOptionService _globalOptions;
private readonly SemanticTokensRefreshQueue _semanticTokenRefreshQueue;

private readonly IGlobalOptionService _globalOptions = globalOptions;
private readonly SemanticTokensRefreshQueue _semanticTokenRefreshQueue = semanticTokensRefreshQueue;

public bool MutatesSolutionState => false;

public bool RequiresLSPSolution => true;

public SemanticTokensRangesHandler(
IGlobalOptionService globalOptions,
SemanticTokensRefreshQueue semanticTokensRefreshQueue)
{
_globalOptions = globalOptions;
_semanticTokenRefreshQueue = semanticTokensRefreshQueue;
}

public TextDocumentIdentifier GetTextDocumentIdentifier(SemanticTokensRangesParams request)
{
Contract.ThrowIfNull(request.TextDocument);
return request.TextDocument;
}

public async Task<SemanticTokens> HandleRequestAsync(
SemanticTokensRangesParams request,
RequestContext context,
CancellationToken cancellationToken)
SemanticTokensRangesParams request,
RequestContext context,
CancellationToken cancellationToken)
{
Contract.ThrowIfNull(request.TextDocument, "TextDocument is null.");
if (request.Ranges.Length == 0)
return new SemanticTokens { Data = [] };

var tokensData = await SemanticTokensHelpers.HandleRequestHelperAsync(_globalOptions, _semanticTokenRefreshQueue, request.Ranges, context, cancellationToken).ConfigureAwait(false);
var tokensData = await SemanticTokensHelpers.HandleRequestHelperAsync(
_globalOptions, _semanticTokenRefreshQueue, request.Ranges, context, cancellationToken).ConfigureAwait(false);
return new SemanticTokens { Data = tokensData };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(LSP.SemanticTokensFullPa
CancellationToken cancellationToken)
{
Contract.ThrowIfNull(request.TextDocument);
// Passing an empty array of ranges will cause the helper to return tokens for the entire document.
var tokensData = await SemanticTokensHelpers.HandleRequestHelperAsync(_globalOptions, _semanticTokenRefreshQueue, ranges: [], context, cancellationToken).ConfigureAwait(false);

// Passing an null array of ranges will cause the helper to return tokens for the entire document.
var tokensData = await SemanticTokensHelpers.HandleRequestHelperAsync(
_globalOptions, _semanticTokenRefreshQueue, ranges: null, context, cancellationToken).ConfigureAwait(false);
return new LSP.SemanticTokens { Data = tokensData };
}
}
Loading
Loading