Support textDocument/semanticTokens/full#77665
Conversation
|
@dotnet-policy-service agree |
src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensFullHandler.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullParams.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/ExternalAccess/Razor/SemanticTokensRangesHandler.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensFullHandler.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensFullHandler.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensFullHandler.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensFullHandlerFactory.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensFullHandlerFactory.cs
Outdated
Show resolved
Hide resolved
| if (ranges.Length == 0) | ||
| { | ||
| return []; | ||
| } |
There was a problem hiding this comment.
i actually like this. i would just make ranges nullable and say that if it is null that you get the entire doc. but if it is empty you get nothing back.
There was a problem hiding this comment.
note: this was not a joke :)
src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullParams.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullParams.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullParams.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/ProtocolUnitTests/SemanticTokens/SemanticTokensFullTests.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/ProtocolUnitTests/SemanticTokens/SemanticTokensFullTests.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/ProtocolUnitTests/SemanticTokens/SemanticTokensFullTests.cs
Outdated
Show resolved
Hide resolved
dibarbet
left a comment
There was a problem hiding this comment.
Not 100% opposed to allowing others to opt in to full semantic tokens, but we need to make sure this does not accidentally opt vscode into using full.
With Roslyn's semantic model, providing full document semantic tokens is incredibly expensive (but small ranges are very fast). We previously used full and had to disable it due to perf issues, especially on large documents.
| capabilities.SemanticTokensOptions = new SemanticTokensOptions | ||
| { | ||
| Full = false, | ||
| Full = true, |
There was a problem hiding this comment.
We need some kind of mechanism to allow different clients to either enable this or not. We do not want to enable this in VSCode (which is what will happen with this PR IIRC).
Potentially setting this capability dynamically in response to an option change could work. Not 100% sure yet.
There was a problem hiding this comment.
Hm right, that's true. Could we perhaps check if the client capabilities include semantic token ranges, and if not, enable this? Since we get those straight away
There was a problem hiding this comment.
That definitely sounds like a reasonable approach! We would always only use range, unless the client does not support range. Works for me
d560425 to
dd7c9ce
Compare
dd7c9ce to
b07f304
Compare
| // potentially run a diff between the old and new tokens. Therefore, we only enable full handling if | ||
| // the client does not support ranges. | ||
| var rangeCapabilities = clientCapabilities.TextDocument?.SemanticTokens?.Requests?.Range; | ||
| var supportsSemanticTokensRange = rangeCapabilities?.Value is not (false or null); |
There was a problem hiding this comment.
is this just asking is true?
There was a problem hiding this comment.
Range here is a sum type that can be either bool or object? so if you just did is true it would return false if there is an object instead, in which case the client would actually have the range capability, afaik
| CancellationToken cancellationToken) | ||
| { | ||
| Contract.ThrowIfNull(request.TextDocument); | ||
| // Passing an empty array of ranges will cause the helper to return tokens for the entire document. |
There was a problem hiding this comment.
i would still like us to use 'null' for this, and having empty return empty.
|
Note: i won't block on my feedback. But i may just make the change if this merges in as is :) |
|
Thanks @PaddiM8 ! |
Solves #70536 (apart from delta). Some editors, such as neovim, don't support textDocument/semanticTokens/range, which means that you currently don't get semantic highlighting for .NET in these editors. Getting semantic tokens for the entire document is of course slower, but the editor can decide what to do anyway.
Tested and working with neovim.