neoclide/coc.nvim · error · Error
Format provider not found for buffer: ${doc.bufnr}
Error message
Format provider not found for buffer: ${doc.bufnr} What it means
Thrown by documentFormat when no language server registered a document formatting provider for the given buffer. coc cannot format the buffer because no provider handles textDocument/formatting for it.
Source
Thrown at src/handler/format.ts:111
await doc.applyEdits(edits, false, true)
this.logProvider(doc.bufnr, edits)
return true
}
public async formatCurrentBuffer(): Promise<boolean> {
let { doc } = await this.handler.getCurrentState()
return await this.documentFormat(doc)
}
public async formatCurrentRange(mode: string): Promise<number> {
let { doc } = await this.handler.getCurrentState()
return await this.documentRangeFormat(doc, mode)
}
public async documentFormat(doc: Document): Promise<boolean> {
await doc.synchronize()
if (!languages.hasFormatProvider(doc.textDocument)) {
throw new Error(`Format provider not found for buffer: ${doc.bufnr}`)
}
let options = await workspace.getFormatOptions(doc.uri)
let textEdits = await this.handler.withRequestToken('format', token => {
return languages.provideDocumentFormattingEdits(doc.textDocument, options, token)
})
if (textEdits && textEdits.length > 0) {
await doc.applyEdits(textEdits, false, true)
this.logProvider(doc.bufnr, textEdits)
return true
}
return false
}
public async handleEnter(bufnr: number): Promise<void> {
let { nvim } = this
let { bracketEnterImprove } = this.preferences
let doc = workspace.getDocument(bufnr)
if (!doc || !doc.attached) returnView on GitHub (pinned to 50e974d969)
Solutions
- Install/enable a formatter provider for the filetype (e.g. coc-prettier for js/ts/json)
- Check the server's capabilities support documentFormattingProvider
- Use rangeFormat or an external formatter if the server only supports range formatting
Example fix
// before :CocCommand format # buffer without provider // after :CocInstall coc-prettier # or configure a server with formatting capability for the filetype
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check via coc API surface used internally
const hasProvider = await nvim.call('coc#client#request', ['format']) // or gate on known formatter extensions installed for filetype Try / catch
try {
await formatCurrentBuffer();
} catch (e) {
if (String(e.message).includes('Format provider not found')) {
console.warn('Install a formatter extension for this filetype (e.g. coc-prettier)');
return false;
}
throw e;
} Prevention
- Install formatter extensions for filetypes you edit
- Verify server formatting capability in :CocCommand workspace diagnostics
- Gate format commands on known filetype support
When it happens
Trigger: Invoking format (:CocCommand or CocAction format) on a buffer whose filetype has no server with documentFormattingProvider capability, after doc.synchronize() confirms provider absence via languages.hasFormatProvider().
Common situations: Buffer filetype not covered by any installed language server; server running but without formatting capability; formatting extensions (prettier etc.) not installed/enabled for that filetype.
Related errors
- ${id} provider not found for current buffer, your language s
- ${uri} changed before apply edit
- Unable to getCallHierarchyItem at current position
- Action "${action.title}" is disabled: ${action.disabled.reas
- Inlay hint provider not found for current document
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/8124427d45d5a919.
Report an issue: GitHub.