neoclide/coc.nvim · error · Error

Rename provider not found for current buffer

Error message

Rename provider not found for current buffer

What it means

doRefactor (refactor of the current symbol) requires the language server for the buffer to register a Rename provider. coc.nvim checks `languages.hasProvider(ProviderName.Rename, ...)` up front and throws before issuing prepareRename. Without this the whole refactor panel cannot be built.

Source

Thrown at src/handler/refactor/index.ts:69

  private setConfiguration(e?: IConfigurationChangeEvent): void {
    if (e && !e.affectsConfiguration('refactor')) return
    let config = workspace.getConfiguration('refactor', null)
    this.config = Object.assign(this.config || {}, {
      afterContext: config.get('afterContext', 3),
      beforeContext: config.get('beforeContext', 3),
      openCommand: config.get('openCommand', 'vsplit'),
      saveToFile: config.get('saveToFile', true),
      showMenu: config.get('showMenu', '<Tab>')
    })
  }

  /**
   * Refactor of current symbol
   */
  public async doRefactor(): Promise<void> {
    let { doc, position } = await this.handler.getCurrentState()
    if (!languages.hasProvider(ProviderName.Rename, doc.textDocument)) {
      throw new Error(`Rename provider not found for current buffer`)
    }
    await doc.synchronize()
    let edit = await this.handler.withRequestToken('refactor', async token => {
      let res = await languages.prepareRename(doc.textDocument, position, token)
      if (token.isCancellationRequested) return null
      if (res === false) throw new Error(`Provider returns null on prepare, unable to rename at current position`)
      let edit = await languages.provideRenameEdits(doc.textDocument, position, 'NewName', token)
      if (token.isCancellationRequested) return null
      if (!edit) throw new Error('Provider returns null for rename edits.')
      return edit
    })
    if (edit) {
      await this.fromWorkspaceEdit(edit, doc.filetype)
    }
  }

  /**
   * Search by rg

View on GitHub (pinned to 50e974d969)

Solutions

  1. Attach a capable language server for the filetype (e.g. via a coc extension or lsp config).
  2. Verify with `:CocCommand document.checkBuffer` that rename capability is registered.
  3. If the server crashed at startup, restart coc (`:CocRestart`) and check `:CocInfo`.
  4. Fall back to `:CocRename`-only flow or manual rename when no server supports rename.
Defensive patterns

Strategy: try-catch

Validate before calling

// skip when the attached server lacks rename capability
const caps = await coc.commands.executeCommand('document.checkBuffer')
if (!caps?.capabilities?.renameProvider) return

Try / catch

try {
  await coc.commands.executeCommand('document.renameRefactor')
} catch (e) {
  if (String(e?.message).includes('Rename provider not found'))
    return vim.notify('Current language server does not support rename')
  throw e
}

Prevention

When it happens

Trigger: Running `:CocCommand document.renameRefactor` in a buffer whose attached server lacks the `renameProvider` capability, or in a buffer with no attached language server at all.

Common situations: Plain/unsupported filetype; old language server without rename support; server failed to initialize so no capabilities registered; invoking the command in a non-code buffer.

Related errors


AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31). Data as JSON: /api/errors/51cf34055ac8e9e1. Report an issue: GitHub.