Repository navigation
Done
Labels
Milestone
Description
What
textDocument/semanticTokens/full/delta (3.16) sends the resultId of the last full or delta answer as previousResultId. The server answers with only the edits to the token array (SemanticTokensDelta), or with full tokens.
- The client announces it with
textDocument.semanticTokens.requests.full.delta: true. - The server announces it with
semanticTokensProvider.full.delta: true.
Why
- rust-analyzer:
full: { delta: true }(crates/rust-analyzer/src/lsp/capabilities.rs). - clangd:
"full": {"delta": true}(ClangdLSPServer.cpp), with its handleronSemanticTokensDelta. - No delta: gopls (its
SemanticTokensFullDeltais inunimplemented.go), jdtls (SemanticTokensServerFull(false)), typescript-language-server.
What users miss: on large files, every keystroke re-sends and re-parses all tokens of the file. That is 5 integers per token, so tens of thousands of integers for a big C++ or Rust file, on each highlighting pass. With delta it is a few edits.
Today
- LSP4IJ announces
requests: { full: true, range: false }and no delta (ClientCapabilitiesFactory.java#L310). - It only sends
semanticTokens/full(LSPSemanticTokensSupport.java#L92).resultIdis not kept. - The docs say so (LSPSupport.md#L768).
How it could be done
- Keep the last result per server and document: the
resultIdand theint[]data. They belong to the opened document of that server, and are dropped ondidClose, on a server restart and onworkspace/semanticTokens/refresh. - Send delta when the server announces
full.deltaand a previous result with aresultIdexists. Otherwise sendfull. - Apply the
SemanticTokensEdits (start, deleteCount, data) to a copy of the previous array, in order. BuildSemanticTokensDatafrom it as today. If the answer is fullSemanticTokens, use it as it is. - Error handling: if an edit doesn't fit the previous array (a server bug), drop the cache and send
fullonce. - Announce
full: { delta: true }(SemanticTokensClientCapabilitiesRequestsFull, in LSP4J 1.0).
No IntelliJ API changes. LSPSemanticTokensHighlightVisitor keeps working on the full array.
Test
Unit tests of the edit application:
- insert, delete, replace;
- several edits;
- an edit past the end, which falls back to full.
Plus a fixture test with a mock server that answers full and then delta.
Activity
fix: a language server with semantic tokens for a range only gets tex…
docs: semantic tokens are no longer experimental, with what is suppor…
fix: a language server with semantic tokens for a range only gets tex…
docs: semantic tokens are no longer experimental, with what is suppor…