neoclide/coc.nvim · error · Error
Unable to getCallHierarchyItem at current position
Error message
Unable to getCallHierarchyItem at current position
What it means
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.
Source
Thrown at src/handler/callHierarchy.ts:168
return items
}
private async prepare(doc: TextDocument, position: Position, token: CancellationToken): Promise<CallHierarchyItem[] | undefined> {
this.handler.checkProvider(ProviderName.CallHierarchy, doc)
const res = await languages.prepareCallHierarchy(doc, position, token)
return isCallHierarchyItem(res) ? [res] : res
}
private async getCallHierarchyItems(item: CallHierarchyItem | undefined, kind: 'outgoing'): Promise<CallHierarchyOutgoingCall[]>
private async getCallHierarchyItems(item: CallHierarchyItem | undefined, kind: 'incoming'): Promise<CallHierarchyIncomingCall[]>
private async getCallHierarchyItems(item: CallHierarchyItem | undefined, kind: 'incoming' | 'outgoing'): Promise<(CallHierarchyIncomingCall | CallHierarchyOutgoingCall)[]> {
const { doc, position } = await this.handler.getCurrentState()
const source = new CancellationTokenSource()
if (!item) {
await doc.synchronize()
let res = await this.prepare(doc.textDocument, position, source.token)
item = res ? res[0] : undefined
if (!res) throw new Error('Unable to getCallHierarchyItem at current position')
}
let method = kind == 'incoming' ? 'provideIncomingCalls' : 'provideOutgoingCalls'
return await languages[method](doc.textDocument, item, source.token)
}
public async getIncoming(item?: CallHierarchyItem): Promise<CallHierarchyIncomingCall[] | undefined> {
return await this.getCallHierarchyItems(item, 'incoming')
}
public async getOutgoing(item?: CallHierarchyItem): Promise<CallHierarchyOutgoingCall[] | undefined> {
return await this.getCallHierarchyItems(item, 'outgoing')
}
public async showCallHierarchyTree(kind: 'incoming' | 'outgoing'): Promise<void> {
const { doc, position, winid } = await this.handler.getCurrentState()
await doc.synchronize()
if (!languages.hasProvider(ProviderName.CallHierarchy, doc.textDocument)) {
void window.showErrorMessage(`CallHierarchy provider not found for current document, it's not supported by your languageserver`)View on GitHub (pinned to 50e974d969)
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
Example fix
// before const incoming = await callHierarchy.getIncoming() // cursor not on symbol // after const items = await callHierarchy.getCallHierarchyItems() if (items) const incoming = await callHierarchy.getIncoming(items[0])
Defensive patterns
Strategy: try-catch
Validate before calling
const providers = await coc.prompts // no public API; instead check server capabilities via workspace
// practical pre-check: ensure cursor is on a word/symbol
const char = await nvim.eval('getline(".")[col(".")-1]');
if (!/\w/.test(char)) return undefined; // not on a symbol Try / catch
try {
const incoming = await callHierarchy.getIncoming();
} catch (e) {
if (String(e.message).includes('Unable to getCallHierarchyItem')) {
// notify: cursor not on a symbol or server lacks callHierarchy support
return undefined;
}
throw e;
} Prevention
- Place cursor on a function/class symbol before call-hierarchy commands
- Confirm server advertises callHierarchyProvider
- Pass an explicit CallHierarchyItem when available
When it happens
Trigger: 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.
Common situations: Cursor placed inside a comment or string; running :CocCommand on a symbol type the server doesn't register; server lacks callHierarchy capability.
Related errors
- ${uri} changed before apply edit
- Action "${action.title}" is disabled: ${action.disabled.reas
- Format provider not found for buffer: ${doc.bufnr}
- ${id} provider not found for current buffer, your language s
- Inlay hint provider not found for current document
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/0f2fddf3f6631576.
Report an issue: GitHub.