Repository navigation
Description
What "experimental" refers to today
Two places in the docs say it:
- docs/UserGuide.md#L187: "LSP4IJ provides experimental support for LSP Semantic Tokens".
- docs/LSPSupport.md#L66: "textDocument/semanticTokens (experimental)", and #L786 says only
textDocument/semanticTokens/fullis used.
Both lines come from the first implementation, 97980bd by azerr (#392, merged 2024-07-01, fixes #238, first released in 0.3.0). In #392 and in #238 the support was described as experimental, needing "some improvements", with an invitation to send PRs that improve it or change its API. No issue says what has to be true to drop the label, and the wording hasn't changed since, although many fixes followed (#394, #401, #477, #828, #1437, #1440, #1511, #2047, ...).
LSPSemanticTokensFeature is @ApiStatus.Experimental, but so is every feature class of LSPClientFeatures, so that annotation is not specific to semantic tokens.
This issue lists what LSP4IJ does today, what is missing or fragile, and a plan to get to a state where the label can go. Code references are to main at 0fd429a.
Where it stands, against the LSP 3.17 spec
| Feature | Status | Code |
|---|---|---|
textDocument/semanticTokens/full |
Supported | LSPSemanticTokensSupport#L90-L92 |
full/delta, resultId |
Not supported. The client announces requests: { full: true, range: false }, no delta; resultId is ignored (#2239) |
ClientCapabilitiesFactory#L312 |
range, visible-range requests |
Not supported (#2240). A server with range but no full still gets full requests, because any semanticTokensProvider counts as support |
SemanticTokensCapabilityRegistry#L31-L32 |
workspace/semanticTokens/refresh |
Partly. Supported, but the re-highlighting waits at least 2 s, and any other restart request of the file within those 2 s postpones it again | LanguageClientImpl#L358-L375, LSPFileSupport#L79, #L511-L536 |
multilineTokenSupport |
Supported: declared true, a token is start offset + length |
ClientCapabilitiesFactory#L310, SemanticTokensData#L125-L130 |
overlappingTokenSupport |
Not declared, which is right: the PSI path keeps one token per start offset | LSPSemanticTokensHighlightVisitor#L289-L297 |
augmentsSyntaxTokens |
Not declared (#1101) | ClientCapabilitiesFactory#L270-L315 |
serverCancelSupport |
Declared true, not honoured: a ServerCancelled answer becomes an empty result that is kept until the next edit, and the request is not sent again |
ClientCapabilitiesFactory#L311, CancellationSupport#L146-L160, CancellationUtil#L46 |
formats |
Supported (relative, the only format) |
ClientCapabilitiesFactory#L313 |
| Token types in the client capabilities | All 23 standard 3.17 types, plus label |
ClientCapabilitiesFactory#L272-L297 |
| Token modifiers in the client capabilities | Partly: 4 of 10 (declaration, definition, readonly, static). The rest is commented out, including defaultLibrary, which the default colors do use |
ClientCapabilitiesFactory#L298-L309 |
| Server legend, static and dynamic registration | Supported, per server. With dynamic registration, the legend of the first registration is used | LSPSemanticTokensSupport#L105-L119, SemanticTokensCapabilityRegistry#L67-L73 |
| Colors of the standard types | Supported, through DefaultSemanticTokensColorsProvider. Of the modifiers, only declaration/definition, static, readonly and defaultLibrary (for function only) change the color; deprecated, abstract, async, modification and documentation don't |
DefaultSemanticTokensColorsProvider#L28-L205 |
| Custom types from a server's legend | Partly: three are hard-coded (label, TypeScript's member, SourceKit's identifier); every other custom type is not colored. A plugin can supply its own provider through the semanticTokensColorsProvider extension point; a user-defined server has no way to (#871) |
LSPSemanticTokenTypes#L29-L66 |
| Several language servers on one file | Partly: the request goes to every server, and the answer of one is used, the one that happened to finish starting first | LSPSemanticTokensSupport#L73-L80, LanguageServiceAccessor#L703-L735 |
Partial results (partialResultToken) |
Not supported (#2244) | |
| Cancellation on typing | Supported: after an edit, the next highlighting pass cancels the earlier request ($/cancelRequest) and sends a new one. There is no debounce of its own; the daemon's auto-reparse delay acts as one |
AbstractLSPFeatureSupport#L60-L96, AbstractLSPDocumentFeatureSupport#L80-L83 |
| TextMate and plain-text files | Supported: the highlights are added on top of the lexer's | LSPSemanticTokensHighlightVisitor#L114-L119 |
| A language plugin's own PSI | Supported (#1040): highlights per leaf element, on top of the plugin's highlighting. Not tested | LSPSemanticTokensHighlightVisitor#L120-L158, LSPSemanticTokensFeature#L112-L151 |
| Positions (UTF-16) | Supported: only UTF-16 is offered, which matches IntelliJ's document offsets. Not tested with characters outside the BMP | ClientCapabilitiesFactory#L41 |
| Themes and color schemes | Supported: each LSP_* key inherits a DefaultLanguageHighlighterColors key, so every scheme gets colors; the four scheme files only set LSP_TYPE_PARAMETER. One global "Language Server" color page |
SemanticTokensHighlightingColors, SemanticTokensDark.xml |
| Semantic Tokens Inspector | Supported | features/semanticTokens/inspector |
Gaps and risks, in priority order
"Verified" means read in the code; "inferred" means it follows from the code and the platform's behaviour but hasn't been reproduced.
1. A failed or server-cancelled request wipes the semantic colors and is not retried
- Verified:
CancellationSupportturns aResponseErrorExceptioninto anullresult:RequestCancelledandServerCancelled(L148, CancellationUtil#L46),ContentModified(L152), and any other error after reporting it (L157).LSPSemanticTokensSupportmapsnullto no data (L93-L97), and the visitor then adds no highlights. The future completed normally, soAbstractLSPFeatureSupport.isValidLSPFuturekeeps it until the file is modified: no new request is sent until the next edit or refresh. - Inferred: a highlighting pass that adds nothing removes the semantic highlights of the earlier pass, so the file loses its semantic colors until the user types. Syntax Highlighting breaks since Jetbrains version 2024.2.1 on error #780 (a server that answers an error while the document doesn't parse) looks like this.
- Against the spec: with
serverCancelSupport: true, "If a server does the client needs to retrigger the request." - Fix: keep the last good result per server and document, and keep showing the current highlights on an error or cancellation instead of replacing them with nothing. Don't cache an empty answer that came from an error; for
ServerCancelledandContentModified, ask again after a short delay (bounded retries). - Test: a mock server that answers tokens, then an error after an edit: the earlier highlights stay. A mock server that answers
ServerCancelledonce, then tokens: the tokens show without any edit.
2. Several language servers on one file: one answer is used, and which one is not deterministic
- Verified: the request is sent to every server with the capability (L73-L77), and only
semanticTokensPerServerFutures.get(0)is used (L80, the merge is commented out). The list of servers is filled in the order in which they finish starting and connecting the file (LanguageServiceAccessor#L703, L730), so the server whose colors show can change from one IDE start to the next. The other servers' work is thrown away. - Fix: decode each server's tokens with its own legend and colors provider and add all of them (each as its own set of highlights), or let the definitions say which server wins; at the least, pick one deterministically (mapping order) and send the request to that one only. The view provider and the inspector should say which server a token came from.
- Test: two mock servers with different legends and tokens on one file, with one of them slower to initialize: the result is the same whichever starts first.
3. The highlighting pass waits for the language server, and a cancelled wait empties the colors
- Verified:
analyzewaits for the answer inside the highlighting read action (L191-L235). The future includes starting the server andinitialize(getLanguageServerswaits forgetInitializedServer()), so on opening a file the pass can wait for as long as the server takes to start. This is the wait of the freezes in Semantic tokens, document links and LSP intentions hold highlighting read actions while they wait for the language server #2017. Since 2024.2 IntelliJ runs the visitors of a pass concurrently, so other visitors are not blocked, but the pass, and what waits for it, is. - Verified: when the future is cancelled while a pass waits, for example by
workspace/semanticTokens/refresh(SemanticTokensEditorFeature#L40-L44), the visitor returns no tokens (L212-L216). Inferred: that pass then removes the semantic highlights, and they come back with the pass that the refresh restarts 2 s later. - Fix: the approach of Semantic tokens, document links and LSP intentions hold highlighting read actions while they wait for the language server #2017: don't wait in the pass. Use the answer if it is there for the current modification stamp; otherwise keep the current highlights and restart the highlighting of the file when the answer arrives (as
refreshWhenLoadedand the document links'pendingFuturedo). Whatever the approach, a pass must never end with no tokens only because the answer isn't there yet. - Test: a mock server that answers after a delay (no fixed sleeps in the test, wait for the request and the restart): a write action during the wait completes promptly, the earlier highlights stay until the answer, and the answer is applied without an edit. A refresh during a request doesn't make the colors disappear.
4. workspace/semanticTokens/refresh is slow, and can be postponed indefinitely
- Verified: the refresh clears the cache and calls
restartDaemonCodeAnalyzerWithDebounce(EditorFeatureManager#L140-L146), which waits 2000 ms (LSPFileSupport#L79) and cancels the pending restart each time another restart of the file is asked for (L519). Inferred: a server that sends refreshes (of any feature of the file) more often than every 2 s, as some do while indexing, keeps the semantic tokens from being updated. - Fix: a shorter delay for visible editors (the spec allows delaying only invisible ones), and a maximum wait so that repeated requests can't postpone the restart forever.
- Test: a mock server changes its tokens and sends a refresh: the new tokens show within a bound well under 2 s; with refreshes sent every 500 ms, the tokens still update.
5. Range-only servers get no semantic tokens; no range and no delta
- Verified: a server announcing
range: true, full: falsestill getstextDocument/semanticTokens/full(SemanticTokensCapabilityRegistry#L31-L32), e.g. lua-language-server withuseSemanticByRange(LSP: support the textDocument/semanticTokens/range request #2240). - Missing:
rangefor the visible part on first paint (LSP: support the textDocument/semanticTokens/range request #2240) andfull/delta(LSP: support the textDocument/semanticTokens/full/delta request #2239). - Fix: first, for a server without
full, sendrangefor the whole document; then LSP: support the textDocument/semanticTokens/range request #2240 and LSP: support the textDocument/semanticTokens/full/delta request #2239. A note for LSP: support the textDocument/semanticTokens/range request #2240: the spec doesn't say what the first token of a range answer is relative to; as far as I can tell VS Code and rust-analyzer encode it relative to (0,0), like a full answer, not to the range's start line. That needs checking against a few servers before it's implemented. - Test: a mock server with
rangeonly shows tokens, and the request log has nofull.
6. Colors: custom types, modifiers and a few default mappings
- Verified: custom types other than the three hard-coded ones get no color (Add support for custom semantic token types and modifiers #871);
deprecatedisn't rendered (IntelliJ users expect strike-through);defaultLibraryis only used forfunction. - Verified:
variablewithoutreadonly/staticmaps toLSP_VARIABLE, which inheritsREASSIGNED_LOCAL_VARIABLE(SemanticTokensHighlightingColors#L51), and IntelliJ's Default and Darcula schemes underline that key. So with a server that doesn't sendreadonly(most), every variable is underlined (as in the screenshots of Semantic tokens attributes not applied on first start #475). - Verified: the client capabilities list 4 modifiers, not the ones the colors use (
defaultLibrary);augmentsSyntaxTokensis not set (Set theaugmentsSyntaxTokensclient capability if appropriate #1101), although LSP4IJ always adds semantic colors on top of a lexer (TextMate, a plugin's) except for plain text. - Verified: a user-defined language server can't turn semantic tokens off or map custom types; only a plugin can, by overriding
LSPSemanticTokensFeature(Is there a configuration option for disabling semantic highlighting #1005, Add support for custom semantic token types and modifiers #871). - Fix: Add support for custom semantic token types and modifiers #871 (custom types and modifiers, by API and by client configuration); add modifier layers (at least
deprecatedas a second highlight with the platform's deprecated attributes); map plainvariabletoLOCAL_VARIABLEor a non-underlined key; declare in the client capabilities the modifiers that are used; Set theaugmentsSyntaxTokensclient capability if appropriate #1101; a client setting to disable semantic tokens per server. - Test: a parameterized unit test of
DefaultSemanticTokensColorsProviderthat is the mapping table of the docs; a test that a custom type configured in the client settings gets its key.
7. Performance on large files
- Verified: every highlighting pass decodes the whole token array again, even when the cached answer hasn't changed (SemanticTokensData#L68-L169), looks up colors per token and, for the PSI path, allocates an array as long as the document (LSPSemanticTokensHighlightVisitor#L289).
- Verified: for TEXT, TextMate and plugin file types without a language, the view provider stores one
ConcurrentHashMapentry per character of every token (LSPSemanticTokensFileViewProviderHelper#L161-L177), refilled by each pass. The map is not cleared on a refresh without an edit (it's a cached value of the file), so tokens that a refresh removed stay in it (inferred). - Verified: the data arrives as
List<Integer>(boxed), 5 per token. - Fix: decode once per answer into sorted
int[]arrays (start, end, key index) kept with the result; reuse them across passes and for the view provider (binary search instead of a per-character map); no document-length array. - Test: a benchmark-style test with a file of 50,000 tokens: decode time, allocations, and that a second pass without changes doesn't decode again.
8. Correctness details
- Verified: tokens are checked against the document length (L144) but not against their line: a token on the same line as the previous one is placed by adding the delta (L113-L114), with no clamp to the end of the line. Mostly harmless with the stamp checks, but a server bug spills colors onto the next line.
- Verified: the PSI path keeps one token per start offset (L294-L296), so overlapping tokens from a server that sends them anyway are dropped silently.
- Not checked: injected fragments and files with several PSI roots (template languages), where
analyzemay run once per root. - Test: unit tests of the decoder for tokens past the line end, past the document end, of length 0, with a type index outside the legend, and with modifier bits beyond the legend; and one with characters outside the BMP (emoji) before tokens on the same line.
9. Test coverage
What exists: one decoding test (LuaSemanticTokensTest, two tokens), three inspector tests, the file view provider tests (CSS, Go, JavaScript, TypeScript, plugin file type), the documentation provider, and a refresh-clears-the-cache test (EditorRefreshBatchTest). The mock server only answers semanticTokens/full, with a fixed answer (MockTextDocumentService#L691-L693).
Not covered: the fixes of #1437, #1440 and #1511, which came without tests; edits during a request; errors and cancellation; refresh end to end; several servers; dynamic registration with a legend; the PSI path (#1040); the color mapping; Unicode; large files. Each gap above lists its test. The tests should wait for events, not fixed times, as the rest of the suite does since #2252.
10. Inspector and docs
- Verified: with the inspector open, each pass formats the tokens on a pooled thread through
WriteCommandAction.runWriteCommandAction(SemanticTokensInspectorManager#L77), that is a write action on the UI thread, only to insert tags into a throwaway document. AStringBuilderdoes the same without a write action (which also cancels running highlighting passes). The inspector shows no server name, legend or raw data, and only the tokens of the one server used. - Docs: the limits above (one server,
fullonly, refresh delay, uncolored custom types, how to disable) aren't documented. The Javadoc ofLSPSemanticTokensFeature.shouldVisitPsiElementsays the opposite of the code (L118-L120 vs L127-L129);LSPSemanticTokensHighlightVisitor#L265still says "see issue #XXX" (it is IllegalArgumentException on inverted semantic token offsets caused by concurrent document edits #1440);LSPSemanticTokensSupporthas comments copied from folding ranges (L67, L79).
Related open issues
- Semantic tokens, document links and LSP intentions hold highlighting read actions while they wait for the language server #2017 Semantic tokens, document links and LSP intentions hold highlighting read actions while they wait for the language server (gap 3)
- LSP: support the textDocument/semanticTokens/full/delta request #2239 support
textDocument/semanticTokens/full/delta(gap 5) - LSP: support the textDocument/semanticTokens/range request #2240 support
textDocument/semanticTokens/range(gap 5) - LSP: client-initiated work done progress and partial results for requests (workDoneToken, partialResultToken) #2244 work done progress and partial results (partial results for semantic tokens)
- Add support for custom semantic token types and modifiers #871 custom semantic token types and modifiers (gap 6)
- Set the
augmentsSyntaxTokensclient capability if appropriate #1101 setaugmentsSyntaxTokens(gap 6) - Incorrect highlight on open reference (clangd) #1153 incorrect highlight on open reference (clangd): Ctrl+hover range in a file whose semantic tokens are missing
Proposed plan
- Agree on the bar for dropping "experimental": gaps 1 to 4 fixed with tests, range-only servers working (first part of gap 5), the default colors reviewed (gap 6, without Add support for custom semantic token types and modifiers #871), and a manual check with a set of real servers (for example rust-analyzer, clangd, gopls, typescript-language-server, lua-language-server, jdtls, zls) in TextMate files and in one plugin with its own PSI.
- Correctness (gaps 1 and 2): keep the last good result, retry
ServerCancelled/ContentModified, deterministic multi-server handling. Small, testable changes inLSPSemanticTokensSupportand the visitor. - Threading and refresh (gaps 3 and 4): decide on Semantic tokens, document links and LSP intentions hold highlighting read actions while they wait for the language server #2017's non-blocking approach with a reproduction; never end a pass empty because the answer is pending; a refresh that applies promptly.
- Tests (gap 9) alongside 2 and 3: a mock server that can delay, fail, cancel and change its tokens; decoder unit tests (gap 8).
- Colors (gap 6): default mapping review,
deprecated, client capabilities, Set theaugmentsSyntaxTokensclient capability if appropriate #1101, a per-server switch; Add support for custom semantic token types and modifiers #871 can follow. - Then drop the label: update the User Guide and LSPSupport.md with what is supported and its limits, and remove "experimental".
- After that, as improvements: decode-once performance work (gap 7), LSP: support the textDocument/semanticTokens/range request #2240 visible range, LSP: support the textDocument/semanticTokens/full/delta request #2239 delta, inspector improvements (gap 10).
Activity
test: the semantic tokens decoder, for answers that a language server…
docs: semantic tokens are no longer experimental, with what is suppor…
test: the semantic tokens decoder, for answers that a language server…
docs: semantic tokens are no longer experimental, with what is suppor…
test: the semantic tokens decoder, for answers that a language server…
lagergren commentedon Dec 1, 2026
The live check that the plan asked for before dropping "experimental", with real servers and on both paths:
textDocument/semanticTokens/full(legend and data) for a small file of its language, with a little LSP client.\u{1F600}The "experimental" wording is already gone from the docs:
LSPSupport.mdliststextDocument/semanticTokensas ✅, and the user guide no longer calls it experimental.The gaps of the plan:
deprecated.So this plan is done. I'm closing it; #2017 and #2349 stay open for what's left.