neoclide/coc.nvim · error

Feature param could only starts with nvim and patch

Error message

Feature param could only starts with nvim and patch

What it means

The env feature check helper only supports editor-version features of the form 'nvim-x.y.z' or 'patch-x.y.z'. Any other feature string (e.g. 'python3', 'clipboard') is rejected as a programming error rather than silently returning false.

Source

Thrown at src/core/funcs.ts:35

const namespaceMap: Map<string, number> = new Map()
const mutex: Mutex = new Mutex()

export interface PartialEnv {
  isVim: boolean
  version: string
}

/**
 * Like vim's has(), but for version check only.
 * Check patch on neovim and check nvim on vim would return false.
 *
 * For example:
 * - has('nvim-0.6.0')
 * - has('patch-7.4.248')
 */
export function has(env: PartialEnv, feature: string): boolean {
  if (!feature.startsWith('nvim-') && !feature.startsWith('patch-')) {
    throw new Error('Feature param could only starts with nvim and patch')
  }
  if (!env.isVim && feature.startsWith('patch-')) {
    return false
  }
  if (env.isVim && feature.startsWith('nvim-')) {
    return false
  }
  if (env.isVim) {
    let [_, major, minor, patch] = env.version.match(/^(\d)(\d{2})(\d+)$/)
    let version = `${major}.${parseInt(minor, 10)}.${parseInt(patch, 10)}`
    return semver.gte(version, convertVersion(feature.slice(6)))
  }
  return semver.gte(env.version, feature.slice(5))
}

// convert to valid semver version 9.0.0138 to 9.0.138
function convertVersion(version: string): string {
  let parts = version.split('.')

View on GitHub (pinned to 50e974d969)

Solutions

  1. Only pass 'nvim-<version>' or 'patch-<version>' strings to this API
  2. Use nvim.call('has', 'python3') or the appropriate coc API for non-version features
  3. Check the feature string for typos/missing prefix

Example fix

// before
has(env, 'python3')
// after
if (feature.startsWith('nvim-') || feature.startsWith('patch-')) has(env, feature)
else env.nvim.call('has', feature)
Defensive patterns

Strategy: validation

Validate before calling

const supported = f => typeof f === 'string' && (f.startsWith('nvim-') || f.startsWith('patch-'))
if (!supported(feature)) return null // use nvim.call('has', feature) instead

Type guard

const isVersionFeature = (f): f is `nvim-${string}` | `patch-${string}` =>
  typeof f === 'string' && (f.startsWith('nvim-') || f.startsWith('patch-'))

Prevention

When it happens

Trigger: Calling workspace.hasFeature / env has('python3') or other arbitrary vim has() features through coc's has() helper.

Common situations: Porting vimscript logic where has() accepts any feature; extension authors checking non-version capabilities with the wrong API.

Related errors


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