{"record":{"id":"2c8d5f1825155bfb","repo":"neoclide/coc.nvim","slug":"semantic-tokens-highlight-not-enabled-for-current","errorCode":null,"errorMessage":"Semantic tokens highlight not enabled for current filetype: ${this.doc.filetype}","messagePattern":"Semantic tokens highlight not enabled for current filetype: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/handler/semanticTokens/buffer.ts","lineNumber":218,"sourceCode":"\n  private get buffer(): Buffer {\n    return this.nvim.createBuffer(this.bufnr)\n  }\n\n  public get enabled(): boolean {\n    if (!this.configEnabled || !this.hasLegend) return false\n    return this.hasProvider\n  }\n\n  private get shouldHighlight(): boolean {\n    if (!this.enabled) return false\n    const { doc } = this\n    if (doc.dirty || doc.version === this._version) return false\n    return true\n  }\n\n  public checkState(): void {\n    if (!this.configEnabled) throw new Error(`Semantic tokens highlight not enabled for current filetype: ${this.doc.filetype}`)\n    if (!this.hasProvider || !this.hasLegend) throw new Error(`SemanticTokens provider not found for ${this.doc.uri}`)\n  }\n\n  public async getTokenRanges(\n    tokens: number[],\n    legend: SemanticTokensLegend,\n    token: CancellationToken): Promise<SemanticTokenRange[] | null> {\n    let currentLine = 0\n    let currentCharacter = 0\n    let highlights: SemanticTokenRange[] = []\n    let toBytes: (characterIndex: number) => number | undefined\n    let textDocument = this.doc.textDocument\n    let tickStart = Date.now()\n    for (let i = 0; i < tokens.length; i += 5) {\n      if (i == 0 || Date.now() - tickStart > yieldEveryMilliseconds) {\n        await waitImmediate()\n        if (token.isCancellationRequested) break\n        tickStart = Date.now()","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/handler/semanticTokens/buffer.ts#L200-L236","documentation":"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.","triggerScenarios":"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`).","commonSituations":"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.","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."],"exampleFix":"// before (coc-settings.json)\n{ \"semanticTokens.filetypes\": [\"typescript\"] }\n// after\n{ \"semanticTokens.filetypes\": [\"typescript\", \"typescriptreact\", \"javascript\"] }","handlingStrategy":"validation","validationCode":"// gate on semanticTokens config before requesting highlights\nconst cfg = coc.workspace.getConfiguration('semanticTokens')\nconst fts: string[] = cfg.get('filetypes') ?? []\nif (!fts.includes(vim.bo.filetype)) return","typeGuard":null,"tryCatchPattern":"try {\n  await buffer.checkState()\n} catch (e) {\n  if (String(e?.message).includes('Semantic tokens highlight not enabled')) return\n  throw e\n}","preventionTips":["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"],"tags":["lsp","semantic-tokens","configuration","coc-nvim"],"backgroundTag":"feature-disabled-by-configuration","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}