( result: CallHierarchyIncomingCall[] | null, cwd?: string, )
| 476 | * Shows all functions/methods that call the target |
| 477 | */ |
| 478 | export function formatIncomingCallsResult( |
| 479 | result: CallHierarchyIncomingCall[] | null, |
| 480 | cwd?: string, |
| 481 | ): string { |
| 482 | if (!result || result.length === 0) { |
| 483 | return 'No incoming calls found (nothing calls this function)' |
| 484 | } |
| 485 | |
| 486 | const lines = [ |
| 487 | `Found ${result.length} incoming ${plural(result.length, 'call')}:`, |
| 488 | ] |
| 489 | |
| 490 | // Group by file |
| 491 | const byFile = new Map<string, CallHierarchyIncomingCall[]>() |
| 492 | for (const call of result) { |
| 493 | if (!call.from) { |
| 494 | logForDebugging( |
| 495 | 'formatIncomingCallsResult: CallHierarchyIncomingCall has undefined from field', |
| 496 | { level: 'warn' }, |
| 497 | ) |
| 498 | continue |
| 499 | } |
| 500 | const filePath = formatUri(call.from.uri, cwd) |
| 501 | const existing = byFile.get(filePath) |
| 502 | if (existing) { |
| 503 | existing.push(call) |
| 504 | } else { |
| 505 | byFile.set(filePath, [call]) |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | for (const [filePath, calls] of byFile) { |
| 510 | lines.push(`\n${filePath}:`) |
| 511 | for (const call of calls) { |
| 512 | if (!call.from) { |
| 513 | continue // Already logged above |
| 514 | } |
| 515 | const kind = symbolKindToString(call.from.kind) |
| 516 | const line = call.from.range.start.line + 1 |
| 517 | let callLine = ` ${call.from.name} (${kind}) - Line ${line}` |
| 518 | |
| 519 | // Show call sites within the caller |
| 520 | if (call.fromRanges && call.fromRanges.length > 0) { |
| 521 | const callSites = call.fromRanges |
| 522 | .map(r => `${r.start.line + 1}:${r.start.character + 1}`) |
| 523 | .join(', ') |
| 524 | callLine += ` [calls at: ${callSites}]` |
| 525 | } |
| 526 | |
| 527 | lines.push(callLine) |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | return lines.join('\n') |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | * Formats outgoingCalls result |
no test coverage detected