neoclide/coc.nvim · error · Error
Document not attached
Error message
Document not attached
What it means
Thrown by the outline (DocumentSymbol) tree data provider when its provideData callback runs and the requested buffer (bufnr) is no longer a tracked/attached document in coc's buffer collection. The outline view cannot fetch symbols for a document coc is not managing.
Source
Thrown at src/handler/symbols/outline.ts:184
return a.kind - b.kind
}
return comparePosition(a.selectRange.start, b.selectRange.start)
}
return symbols.map(s => this.convertSymbolToNode(s, sortFn)).sort(sortFn)
}
public onSymbolsUpdate(bufnr: number, symbols: DocumentSymbol[]): void {
let provider = this.providersMap.get(bufnr)
if (provider) provider.update(this.convertSymbols(bufnr, symbols))
}
private createProvider(bufnr: number): BasicDataProvider<OutlineNode> {
let { nvim } = this
let provider = new BasicDataProvider({
expandLevel: this.config.expandLevel,
provideData: async () => {
let buf = this.buffers.getItem(bufnr)
if (!buf) throw new Error('Document not attached')
let doc = workspace.getDocument(bufnr)
if (!languages.hasProvider(ProviderName.DocumentSymbol, doc.textDocument)) {
throw new Error('Document symbol provider not found')
}
let meta = languages.getDocumentSymbolMetadata(doc.textDocument)
if (meta && meta.label) {
let views = this.treeViewList.filter(v => v.valid && v.targetBufnr == bufnr)
views.forEach(view => view.description = meta.label)
}
this.setMessage(bufnr, 'Loading document symbols')
let arr = await buf.getSymbols()
if (!arr || arr.length == 0) {
// server may return empty symbols on buffer initialize, throw error to force reload.
throw new Error('Empty symbols returned from language server. ')
}
this.setMessage(bufnr, undefined)
return this.convertSymbols(bufnr, arr)
},View on GitHub (pinned to 50e974d969)
Solutions
- Reopen the outline (:CocOutline) from the buffer you want; a fresh bufnr resolves it.
- Check the buffer is a normal attached file buffer: run :CocCommand workspace.showOutput or `:echo getbufvar(bufnr,'&buftype')` — use real file buffers for outline.
- Restart coc (:CocRestart) to resync the buffers collection and reopen the outline.
- Close stale tree views; upgrade coc.nvim if outline windows persistently outlive their buffers.
Defensive patterns
Strategy: validation
Validate before calling
// vimscript: only run outline on attached, normal buffers if empty(getbufvar(bufnr, 'coc_diagnostic_info')) && &buftype !=# '' echom 'Outline not available for this buffer' else CocOutline endif
Try / catch
try {
await outline.show(bufnr)
} catch (e) {
if (String(e).includes('Document not attached')) {
// stale view: reopen outline for the current buffer
}
} Prevention
- Open the outline only from a normal file buffer that coc has attached.
- Close outline windows when their source buffer is wiped/deleted.
- Avoid non-file buftypes (nofile, quickfix, help) as outline targets.
- After :CocRestart, reopen the outline instead of relying on old views.
When it happens
Trigger: Opening the outline (:CocOutline) for a buffer, then the buffer is deleted, wiped (`:bwipe`), unloaded, or was never attached (e.g. non-opened scratch/quickfix/help buffer), and the tree view later refreshes and calls provideData with the stale bufnr.
Common situations: Keeping an outline window open while cycling buffers and closing the source buffer; running :CocOutline in a non-file buffer (nofile buftype); using a session that restored a deleted buffer; coc restart clearing the buffers registry while an old tree view remains.
Related errors
- Unable to perform semantic highlights for current buffer.
- Document symbol provider not found
- Inlay hint provider not found for current document
- Filetype "${this.doc.filetype}" not enabled by inlayHint con
- Failed to resolve link target
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/e5225262ac729529.
Report an issue: GitHub.