Semantic tokens with per-client legend downgrade#11
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The server now answers
textDocument/semanticTokens/fullfor refs: alias declarations in fence info strings, ref names (block alias vs possible environment variable) and path segments, with theunresolvedmodifier marking refs whose alias is not in scope anddeclarationmarking thealias=...site.Legend mechanics
Token types are unique per range and clients silently ignore types outside their announced capabilities, so the fallback is a server-side downgrade computed at
initialize: anhttui.*kind is registered in the legend only when the client announced it viatextDocument.semanticTokens.tokenTypes; otherwise its LSP-standard fallback (variable/property) takes the slot. Modifiers are intersected with the client's announced list the same way. This matches the canonical token-kinds spec inspec/token-kinds.md.Implementation
lib/semantic_tokens.mlstays protocol-free: abstract tokens (byte ranges + kind + flags) sorted by position; the binary maps kinds to legend indices and emits the delta-encoded stride-5 data with UTF-16 lengths viaDoc_position.Refs.occurrencenow exposes path segment ranges (needed forhttui.ref_pathtokens; also unlocks future per-segment diagnostics).Tests
43 checks total. New ones: token extraction (count, declaration flag, unresolved ghost, env-var kind, ordering) plus two integration sessions against the real binary — a vanilla client whose legend downgrades to
["property"; "variable"], and a client announcinghttui.*whose legend keeps the specific kinds and whose first data token decodes exactly to thereq1declaration with thedeclarationmodifier bit.