neoclide/coc.nvim · error · Error
Semantic tokens highlight not enabled for current filetype:
Error message
Semantic tokens highlight not enabled for current filetype: ${this.doc.filetype} What it means
SemanticTokensBuffer.checkState throws when semantic highlight is not enabled for the buffer's filetype per the `semanticTokens.filetypes` configuration. This check runs before the provider check, so it is purely a configuration gate.
Source
Thrown at src/handler/semanticTokens/buffer.ts:218
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
- Add the filetype to `semanticTokens.filetypes` in coc-settings.json, e.g. `["typescript", "rust", "python"]`.
- Confirm the exact filetype via `:set filetype?` and match it in config.
- If per-filetype config exists (`semanticTokens.<ft>.enable`), enable it for the active filetype.
- Remember coc also needs a server exposing semanticTokensProvider; the separate provider error follows once config passes.
Example fix
// before (coc-settings.json)
{ "semanticTokens.filetypes": ["typescript"] }
// after
{ "semanticTokens.filetypes": ["typescript", "typescriptreact", "javascript"] } Defensive patterns
Strategy: validation
Validate before calling
// gate on semanticTokens config before requesting highlights
const cfg = coc.workspace.getConfiguration('semanticTokens')
const fts: string[] = cfg.get('filetypes') ?? []
if (!fts.includes(vim.bo.filetype)) return Try / catch
try {
await buffer.checkState()
} catch (e) {
if (String(e?.message).includes('Semantic tokens highlight not enabled')) return
throw e
} Prevention
- List every filetype you want highlights for in semanticTokens.filetypes
- Match exact filetype names from `:set filetype?` (e.g. typescriptreact, not tsx)
- Revisit config after changing stacks/filetypes
When it happens
Trigger: Calling checkState (via token refresh/highlight paths, or `:CocCommand semanticTokens.clear`/refresh APIs) on a buffer whose filetype is not listed in `semanticTokens.filetypes` (or enabled via `semanticTokens.<ft>.enable`).
Common situations: User enabled semantic tokens but forgot their filetype in the filetypes list; using a filetype alias mismatch (e.g. 'tsx' vs 'typescriptreact'); expecting highlight in a filetype coc hasn't been configured for.
Related errors
- Filetype "${this.doc.filetype}" not enabled by inlayHint con
- SemanticTokens provider not found for ${this.doc.uri}
- Unable to perform semantic highlights for current buffer.
- Inlay hint provider not found for current document
- Failed to resolve link target
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/2c8d5f1825155bfb.
Report an issue: GitHub.