* Format files as a tree structure
(
files: { path: string; language: string; nodeCount: number }[],
includeMetadata: boolean,
maxDepth?: number
)
| 6630 | * Format files as a tree structure |
| 6631 | */ |
| 6632 | private formatFilesTree( |
| 6633 | files: { path: string; language: string; nodeCount: number }[], |
| 6634 | includeMetadata: boolean, |
| 6635 | maxDepth?: number |
| 6636 | ): string { |
| 6637 | // Build tree structure |
| 6638 | interface TreeNode { |
| 6639 | name: string; |
| 6640 | children: Map<string, TreeNode>; |
| 6641 | file?: { language: string; nodeCount: number }; |
| 6642 | } |
| 6643 | |
| 6644 | const root: TreeNode = { name: '', children: new Map() }; |
| 6645 | |
| 6646 | for (const file of files) { |
| 6647 | const parts = file.path.split('/'); |
| 6648 | let current = root; |
| 6649 | |
| 6650 | for (let i = 0; i < parts.length; i++) { |
| 6651 | const part = parts[i]; |
| 6652 | if (!part) continue; |
| 6653 | |
| 6654 | if (!current.children.has(part)) { |
| 6655 | current.children.set(part, { name: part, children: new Map() }); |
| 6656 | } |
| 6657 | current = current.children.get(part)!; |
| 6658 | |
| 6659 | // If this is the last part, it's a file |
| 6660 | if (i === parts.length - 1) { |
| 6661 | current.file = { language: file.language, nodeCount: file.nodeCount }; |
| 6662 | } |
| 6663 | } |
| 6664 | } |
| 6665 | |
| 6666 | // Render tree |
| 6667 | const lines: string[] = [`**Project Structure (${files.length} files)**`, '']; |
| 6668 | |
| 6669 | const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => { |
| 6670 | if (maxDepth !== undefined && depth > maxDepth) return; |
| 6671 | |
| 6672 | const connector = isLast ? '└── ' : '├── '; |
| 6673 | const childPrefix = isLast ? ' ' : '│ '; |
| 6674 | |
| 6675 | if (node.name) { |
| 6676 | let line = prefix + connector + node.name; |
| 6677 | if (node.file && includeMetadata) { |
| 6678 | line += ` (${node.file.language}, ${node.file.nodeCount} symbols)`; |
| 6679 | } |
| 6680 | lines.push(line); |
| 6681 | } |
| 6682 | |
| 6683 | const children = [...node.children.values()]; |
| 6684 | // Sort: directories first, then files, both alphabetically |
| 6685 | children.sort((a, b) => { |
| 6686 | const aIsDir = a.children.size > 0 && !a.file; |
| 6687 | const bIsDir = b.children.size > 0 && !b.file; |
| 6688 | if (aIsDir !== bIsDir) return aIsDir ? -1 : 1; |
| 6689 | return a.name.localeCompare(b.name); |
no test coverage detected