neoclide/coc.nvim · error · Error

Failed to resolve link target

Error message

Failed to resolve link target

What it means

openLink throws when a DocumentLink has no resolved `target` — the language server returned a link whose target was meant to be resolved lazily via `document/linkResolve`, and resolution either was not performed or returned nothing. coc.nvim refuses to open an undefined URI.

Source

Thrown at src/handler/links.ts:127

      if (start <= pos.character && start + arr[0].length >= pos.character) {
        link = DocumentLink.create(Range.create(pos.line, start, pos.line, start + arr[0].length), arr[0])
        break
      }
    }
    return link
  }

  public async openCurrentLink(): Promise<boolean> {
    let link = await this.getCurrentLink()
    if (link) {
      await this.openLink(link)
      return true
    }
    return false
  }

  public async openLink(link: DocumentLink): Promise<void> {
    if (!link.target) throw new Error(`Failed to resolve link target`)
    await workspace.openResource(link.target)
  }

  public getBuffer(bufnr: number): LinkBuffer | undefined {
    return this.buffers.getItem(bufnr)
  }

  private cancel(): void {
    if (this.tokenSource) {
      this.tokenSource.cancel()
      this.tokenSource = null
    }
  }

  public dispose(): void {
    disposeAll(this.disposables)
  }
}

View on GitHub (pinned to 50e974d969)

Solutions

  1. Update the language server; unresolved links that fail to resolve are usually a server bug.
  2. Check the server's output log (`:CocCommand workspace.showOutput`) for errors on the `documentLink/resolve` request.
  3. Report the missing resolved target to the server's repository with the specific document/link.
  4. Use an alternative navigation (e.g. `gd` or `:CocDefinition`) for the same symbol.

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// only attempt to open links that already carry a target
const link = links?.find(l => contains(l.range, cursorRange))
if (!link?.target) return

Try / catch

try {
  await coc.commands.executeCommand('document.openLink')
} catch (e) {
  if (String(e?.message).includes('Failed to resolve link target'))
    return vim.notify('Link target could not be resolved by the server')
  throw e
}

Prevention

When it happens

Trigger: Calling `:CocCommand document.openLink` (via openCurrentLink) on a link whose `link.target` is undefined because the server only provides a range and expects the client to call the linkResolve callback, and resolution failed or returned an empty result.

Common situations: Language servers that use unresolved document links (target resolved on demand) when the resolve request fails or returns null; hovering/opening a link in a buffer where the server emitted placeholder links.

Related errors


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