{"record":{"id":"0f2fddf3f6631576","repo":"neoclide/coc.nvim","slug":"unable-to-getcallhierarchyitem-at-current-position","errorCode":null,"errorMessage":"Unable to getCallHierarchyItem at current position","messagePattern":"Unable to getCallHierarchyItem at current position","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/handler/callHierarchy.ts","lineNumber":168,"sourceCode":"    return items\n  }\n\n  private async prepare(doc: TextDocument, position: Position, token: CancellationToken): Promise<CallHierarchyItem[] | undefined> {\n    this.handler.checkProvider(ProviderName.CallHierarchy, doc)\n    const res = await languages.prepareCallHierarchy(doc, position, token)\n    return isCallHierarchyItem(res) ? [res] : res\n  }\n\n  private async getCallHierarchyItems(item: CallHierarchyItem | undefined, kind: 'outgoing'): Promise<CallHierarchyOutgoingCall[]>\n  private async getCallHierarchyItems(item: CallHierarchyItem | undefined, kind: 'incoming'): Promise<CallHierarchyIncomingCall[]>\n  private async getCallHierarchyItems(item: CallHierarchyItem | undefined, kind: 'incoming' | 'outgoing'): Promise<(CallHierarchyIncomingCall | CallHierarchyOutgoingCall)[]> {\n    const { doc, position } = await this.handler.getCurrentState()\n    const source = new CancellationTokenSource()\n    if (!item) {\n      await doc.synchronize()\n      let res = await this.prepare(doc.textDocument, position, source.token)\n      item = res ? res[0] : undefined\n      if (!res) throw new Error('Unable to getCallHierarchyItem at current position')\n    }\n    let method = kind == 'incoming' ? 'provideIncomingCalls' : 'provideOutgoingCalls'\n    return await languages[method](doc.textDocument, item, source.token)\n  }\n\n  public async getIncoming(item?: CallHierarchyItem): Promise<CallHierarchyIncomingCall[] | undefined> {\n    return await this.getCallHierarchyItems(item, 'incoming')\n  }\n\n  public async getOutgoing(item?: CallHierarchyItem): Promise<CallHierarchyOutgoingCall[] | undefined> {\n    return await this.getCallHierarchyItems(item, 'outgoing')\n  }\n\n  public async showCallHierarchyTree(kind: 'incoming' | 'outgoing'): Promise<void> {\n    const { doc, position, winid } = await this.handler.getCurrentState()\n    await doc.synchronize()\n    if (!languages.hasProvider(ProviderName.CallHierarchy, doc.textDocument)) {\n      void window.showErrorMessage(`CallHierarchy provider not found for current document, it's not supported by your languageserver`)","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/handler/callHierarchy.ts#L150-L186","documentation":"Thrown when a call-hierarchy request (incoming/outgoing calls) is made at a cursor position where no LSP server can prepare a CallHierarchyItem. The language server returned no result for prepareCallHierarchy at that position, so there is nothing to operate on.","triggerScenarios":"Calling handler/services getIncoming()/getOutgoing() without an item while the cursor is on a non-symbol position (whitespace, comment, keyword not supported), or the server does not implement callHierarchy provider.","commonSituations":"Cursor placed inside a comment or string; running :CocCommand on a symbol type the server doesn't register; server lacks callHierarchy capability.","solutions":["Place the cursor directly on a function/method symbol before invoking call hierarchy","Confirm the language server supports callHierarchy (check :CocCommand workspace diagnostics / server capabilities)","Explicitly pass a CallHierarchyItem to getIncoming/getOutgoing instead of relying on cursor position"],"exampleFix":"// before\nconst incoming = await callHierarchy.getIncoming() // cursor not on symbol\n// after\nconst items = await callHierarchy.getCallHierarchyItems()\nif (items) const incoming = await callHierarchy.getIncoming(items[0])","handlingStrategy":"try-catch","validationCode":"const providers = await coc.prompts // no public API; instead check server capabilities via workspace\n// practical pre-check: ensure cursor is on a word/symbol\nconst char = await nvim.eval('getline(\".\")[col(\".\")-1]');\nif (!/\\w/.test(char)) return undefined; // not on a symbol","typeGuard":null,"tryCatchPattern":"try {\n  const incoming = await callHierarchy.getIncoming();\n} catch (e) {\n  if (String(e.message).includes('Unable to getCallHierarchyItem')) {\n    // notify: cursor not on a symbol or server lacks callHierarchy support\n    return undefined;\n  }\n  throw e;\n}","preventionTips":["Place cursor on a function/class symbol before call-hierarchy commands","Confirm server advertises callHierarchyProvider","Pass an explicit CallHierarchyItem when available"],"tags":["lsp","call-hierarchy","cursor-position"],"backgroundTag":"provider-not-supported","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}