/** * CallHierarchyBuilder Service * * Transforms QueryService call hierarchy data into visualization-ready formats. * Provides ASCII tree rendering, Mermaid diagrams, and depth-based tree pruning. * * Features: * - ASCII art tree visualization * - Mermaid flowchart export * - Bidirectional hierarchy (callers + callees) * - Depth limiting and smart pruning * - Navigation metadata (file paths, line numbers) * - Performance optimization for large trees */ import type { QueryService, CallHierarchyNode, CodeEntityInfo } from '../domain/query/queryService.js'; /** * Direction for call hierarchy traversal */ export type CallHierarchyDirection = 'callers' | 'callees' | 'both'; /** * Configuration for call hierarchy building */ export interface CallHierarchyConfig { /** * Maximum depth to traverse (default: 5) * Higher values = more complete tree but slower performance */ maxDepth?: number; /** * Direction to traverse * - 'callers': Show who calls this function (upstream) * - 'callees': Show what this function calls (downstream) * - 'both': Show both directions */ direction?: CallHierarchyDirection; /** * Maximum children per node before pruning (default: 20) * Prevents UI overload for popular functions */ pruneThreshold?: number; /** * Include file paths and line numbers (default: true) */ includeMetadata?: boolean; /** * Generate ASCII tree visualization (default: true) */ renderAsciiTree?: boolean; /** * Generate Mermaid diagram (default: false) * Can be large for complex hierarchies */ renderMermaidDiagram?: boolean; } /** * Input for call hierarchy request */ export interface CallHierarchyInput { projectPath: string; symbolName: string; symbolType?: 'function' | 'method' | 'any'; config?: CallHierarchyConfig; } /** * Call hierarchy result with visualization */ export interface CallHierarchyResult { query: { symbolName: string; symbolType?: string; direction: CallHierarchyDirection; maxDepth: number; }; rootEntity?: CodeEntityInfo; hierarchy: { callers?: CallHierarchyNode; callees?: CallHierarchyNode; }; visualizations: { asciiTree?: string; mermaidDiagram?: string; }; stats: { totalNodes: number; maxDepthReached: number; pruned: boolean; buildTimeMs: number; }; } /** * Service for building and visualizing call hierarchies */ export declare class CallHierarchyBuilder { private readonly deps; constructor(deps: { queryService: QueryService; }); /** * Build call hierarchy for a symbol */ buildHierarchy(input: CallHierarchyInput): Promise; /** * Check if tree should be pruned */ private shouldPrune; /** * Prune tree by limiting children per node */ private pruneTree; /** * Count total nodes in tree */ private countNodes; /** * Get maximum depth reached */ private getMaxDepth; /** * Render ASCII tree visualization */ private renderAsciiTree; /** * Recursively render tree node */ private renderTreeNode; /** * Render Mermaid flowchart diagram */ private renderMermaidDiagram; /** * Recursively render Mermaid nodes */ private renderMermaidNode; }