{"record":{"id":"ddf1797ea0fee5d8","repo":"neoclide/coc.nvim","slug":"unable-to-perform-semantic-highlights-for-current","errorCode":null,"errorMessage":"Unable to perform semantic highlights for current buffer.","messagePattern":"Unable to perform semantic highlights for current buffer\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/handler/semanticTokens/index.ts","lineNumber":173,"sourceCode":"\n  public closeFloat(): void {\n    floatFactory?.close()\n  }\n\n  public async getCurrentItem(): Promise<SemanticTokensBuffer | undefined> {\n    let buf = await this.nvim.buffer\n    return this.getItem(buf.id)\n  }\n\n  public getItem(bufnr: number): SemanticTokensBuffer | undefined {\n    return this.highlighters.getItem(bufnr)\n  }\n  /**\n   * Force highlight of current buffer\n   */\n  public async highlightCurrent(): Promise<void> {\n    let item = await this.getCurrentItem()\n    if (!item || !item.enabled) throw new Error(`Unable to perform semantic highlights for current buffer.`)\n    await item.forceHighlight()\n  }\n\n  /**\n   * Show semantic highlight info in temporarily buffer\n   */\n  public async showHighlightInfo(): Promise<void> {\n    let bufnr = await this.nvim.call('bufnr', ['%']) as number\n    workspace.getAttachedDocument(bufnr)\n    let { nvim } = this\n    let item = this.highlighters.getItem(bufnr)\n    let hl = new Highlighter()\n    nvim.pauseNotification()\n    nvim.command(`vs +setl\\\\ buftype=nofile __coc_semantic_highlights_${bufnr}__`, true)\n    nvim.command(`setl bufhidden=wipe noswapfile nobuflisted wrap undolevels=-1`, true)\n    nvim.call('bufnr', ['%'], true)\n    let res = await nvim.resumeNotification()\n    hl.addLine('Semantic highlights info', headGroup)","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/handler/semanticTokens/index.ts#L155-L191","documentation":"coc.nvim throws this when `CocAction('semanticHighlights')` (SemanticTokensHandler.highlightCurrent) is called for the current buffer but no semantic-tokens highlighting item exists for that buffer, or the item exists but semantic highlighting is disabled for it. It is a guard against forcing a highlight operation on a buffer that has no registered semantic-token provider/state.","triggerScenarios":"Calling CocAction('semanticHighlights') (or the JS API highlightCurrent) in a buffer that (a) has no attached language server providing semantic tokens, (b) is not a semanticTokensHighlights item (getCurrentItem returns undefined), or (c) has semantic highlighting disabled for that buffer/document (item.enabled is false).","commonSituations":"Running the command in a plain text/markdown buffer without an LSP; the language server doesn't advertise the `semanticTokensProvider` capability; semanticTokens is disabled globally via `semanticTokens.enable: false` or per-filetype; calling the action during VimEnter before the server finishes initialization; buffer isn't attached because coc hasn't opened it as a document.","solutions":["Ensure a language server with semanticTokensProvider capability is attached (run :CocCommand workspace.showOutput or :CocInfo to confirm the server started).","Enable semantic tokens: set \"semanticTokens.enable\": true in coc-settings.json (and highlight.enable if relevant).","Wait for the server to finish initialization or retry after buffer attach; call the action from a User autocmd (e.g. CocGitStatusChanged / BufEnter after attach).","Wrap the call in try/catch and treat the error as 'no semantic highlights available for this buffer' rather than a hard failure."],"exampleFix":"// before\nCocAction('semanticHighlights')  // throws in non-LSP buffer\n\n// after\n\" user command guarded in vimscript\ntry\n  call CocAction('semanticHighlights')\ncatch\n  echom 'Semantic highlights unavailable: ' . v:exception\nendtry","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let highlights\ntry {\n  highlights = await CocAction('semanticHighlights')\n} catch (e) {\n  // buffer has no semantic tokens provider or it's disabled\n  highlights = []\n}","preventionTips":["Only call semanticHighlights in buffers with an attached LSP that advertises semanticTokensProvider.","Confirm \"semanticTokens.enable\": true in coc-settings.json.","Defer the call until the server is attached (e.g. on CocAttach / after diagnostics appear).","Use :CocCommand documentSymbols or workspace.showOutput to verify server capabilities first."],"tags":["semantic-tokens","lsp","buffer-attach","coc-nvim"],"backgroundTag":"semantic-tokens-provider-missing","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}