neoclide/coc.nvim · error

function "coc#source#${name}#${fn}" not found

Error message

function "coc#source#${name}#${fn}" not found

What it means

When coc loads a remote vim completion source, it asks the editor for the list of remote functions the source exports and requires that both 'init' and 'complete' (case-insensitively) exist. If either is missing, source loading aborts with this error, preventing a broken source from registering.

Source

Thrown at src/completion/sources.ts:127

      dispose: () => {
        this.sourceMap.delete(name)
      }
    }
  }
  /**
   * @internal
   */

  public async createVimSourceExtension(filepath: string): Promise<void> {
    let { nvim } = this
    try {
      let name = path.basename(filepath, '.vim')
      await nvim.command(`source ${filepath.split(path.sep).join(path.posix.sep)}`)
      let fns = await nvim.call('coc#_remote_fns', name) as string[]
      let lowercased = fns.map(fn => fn[0].toLowerCase() + fn.slice(1))
      for (let fn of ['init', 'complete']) {
        if (!lowercased.includes(fn)) {
          throw new Error(`function "coc#source#${name}#${fn}" not found`)
        }
      }
      let props = await nvim.call(`coc#source#${name}#${getMethodName('init', fns)}`, []) as VimSourceConfig
      let packageJSON = {
        name: `coc-vim-source-${name}`,
        engines: {
          coc: ">= 0.0.1"
        },
        activationEvents: props.filetypes ? props.filetypes.map(f => `onLanguage:${f}`) : ['*'],
        contributes: {
          configuration: {
            properties: {
              [`coc.source.${name}.enable`]: {
                type: 'boolean',
                default: true
              },
              [`coc.source.${name}.firstMatch`]: {
                type: 'boolean',

View on GitHub (pinned to 50e974d969)

Solutions

  1. Add the missing coc#source#<name>#init or #complete function to the .vim source
  2. Verify the source with :echo coc#_remote_fns('<name>')
  3. Update the source plugin to a coc-compatible version
  4. Remove/disable the broken source plugin

Example fix

// before: source missing complete
function! coc#source#demo#init() abort
  return {...}
endfunction
// after
function! coc#source#demo#complete(opt, cb) abort
  call a:cb([], v:false)
endfunction
Defensive patterns

Strategy: validation

Validate before calling

const fns = await nvim.call('coc#_remote_fns', name)
if (!['init','complete'].every(fn => fns.map(f=>f[0].toLowerCase()+f.slice(1)).includes(fn))) {
  return logger.warn(`vim source ${name} missing required functions`)
}

Type guard

const remoteSourceOk = (fns) => Array.isArray(fns) &&
  fns.some(f => /^init$/i.test(f)) && fns.some(f => /^complete$/i.test(f))

Try / catch

try {
  await createVimSources([filepath])
} catch (e) {
  if (String(e.message).includes('not found')) logger.warn(`skipping invalid vim source: ${e.message}`)
  else throw e
}

Prevention

When it happens

Trigger: Loading a .vim file as a completion source whose autoload functions do not include the required init/complete functions, e.g. the sourced file defines only 'on_enter' or the functions are not declared with coc#remote#init style registration.

Common situations: Installing a vim completion source plugin incompatible with current coc source API; function name typos; the remote-fns list not including expected names because the plugin was not properly sourced.

Related errors


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