neoclide/coc.nvim · error · Error
SemanticTokens provider not found for ${this.doc.uri}
Error message
SemanticTokens provider not found for ${this.doc.uri} What it means
checkState throws this when the semantic tokens configuration is enabled for the filetype, but the buffer either has no attached server that registers a SemanticTokens provider (hasProvider false) or the server did not register the token legend needed to decode token types (hasLegend false).
Source
Thrown at src/handler/semanticTokens/buffer.ts:219
private get buffer(): Buffer {
return this.nvim.createBuffer(this.bufnr)
}
public get enabled(): boolean {
if (!this.configEnabled || !this.hasLegend) return false
return this.hasProvider
}
private get shouldHighlight(): boolean {
if (!this.enabled) return false
const { doc } = this
if (doc.dirty || doc.version === this._version) return false
return true
}
public checkState(): void {
if (!this.configEnabled) throw new Error(`Semantic tokens highlight not enabled for current filetype: ${this.doc.filetype}`)
if (!this.hasProvider || !this.hasLegend) throw new Error(`SemanticTokens provider not found for ${this.doc.uri}`)
}
public async getTokenRanges(
tokens: number[],
legend: SemanticTokensLegend,
token: CancellationToken): Promise<SemanticTokenRange[] | null> {
let currentLine = 0
let currentCharacter = 0
let highlights: SemanticTokenRange[] = []
let toBytes: (characterIndex: number) => number | undefined
let textDocument = this.doc.textDocument
let tickStart = Date.now()
for (let i = 0; i < tokens.length; i += 5) {
if (i == 0 || Date.now() - tickStart > yieldEveryMilliseconds) {
await waitImmediate()
if (token.isCancellationRequested) break
tickStart = Date.now()
}View on GitHub (pinned to 50e974d969)
Solutions
- Upgrade the language server to one supporting semanticTokens with a proper legend.
- Verify capability with `:CocCommand document.checkBuffer` and check `:CocInfo` for client attachment.
- Run `:CocRestart` if the server exited and the buffer is orphaned.
- Remove the filetype from `semanticTokens.filetypes` if the server will never support it, to silence refresh attempts.
Defensive patterns
Strategy: validation
Validate before calling
// only refresh when a semanticTokens provider is attached for this uri
const caps = await coc.commands.executeCommand('document.checkBuffer')
if (!caps?.capabilities?.semanticTokensProvider) return Try / catch
try {
await buffer.checkState()
} catch (e) {
if (String(e?.message).includes('SemanticTokens provider not found')) return
throw e
} Prevention
- Use language servers supporting LSP >= 3.16 semantic tokens
- Check client attachment after long sessions; run :CocRestart when orphaned
- Only enable semanticTokens.filetypes for servers known to provide the capability and legend
When it happens
Trigger: Semantic highlight enabled for the filetype, then a refresh runs on a buffer where `languages.hasProvider(SemanticTokens, uri)` is false or `languages.getLegend(...)` returned undefined — no server attached, server without semanticTokens capability, or server registered the capability without a legend.
Common situations: Language server version without semanticTokens support (pre-LSP 3.16); capability registered but legend negotiation failed; buffer detached from its client (server exited) while highlights refresh.
Related errors
- Inlay hint provider not found for current document
- Rename provider not found for current buffer
- Semantic tokens highlight not enabled for current filetype:
- Unable to perform semantic highlights for current buffer.
- Filetype "${this.doc.filetype}" not enabled by inlayHint con
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/1e0a213adb332e1d.
Report an issue: GitHub.