* Format files as a tree structure
(
files: { path: string; language: string; nodeCount: number }[],
includeMetadata: boolean,
maxDepth?: number
)
| 9045 | * Format files as a tree structure |
| 9046 | */ |
| 9047 | private formatFilesTree( |
| 9048 | files: { path: string; language: string; nodeCount: number }[], |
| 9049 | includeMetadata: boolean, |
| 9050 | maxDepth?: number |
| 9051 | ): string { |
| 9052 | // Build tree structure |
| 9053 | interface TreeNode { |
| 9054 | name: string; |
| 9055 | children: Map<string, TreeNode>; |
| 9056 | file?: { language: string; nodeCount: number }; |
| 9057 | } |
| 9058 | |
| 9059 | const root: TreeNode = { name: '', children: new Map() }; |
| 9060 | |
| 9061 | for (const file of files) { |
| 9062 | const parts = file.path.split('/'); |
| 9063 | let current = root; |
| 9064 | |
| 9065 | for (let i = 0; i < parts.length; i++) { |
| 9066 | const part = parts[i]; |
| 9067 | if (!part) continue; |
| 9068 | |
| 9069 | if (!current.children.has(part)) { |
| 9070 | current.children.set(part, { name: part, children: new Map() }); |
| 9071 | } |
| 9072 | current = current.children.get(part)!; |
| 9073 | |
| 9074 | // If this is the last part, it's a file |
| 9075 | if (i === parts.length - 1) { |
| 9076 | current.file = { language: file.language, nodeCount: file.nodeCount }; |
| 9077 | } |
| 9078 | } |
| 9079 | } |
| 9080 | |
| 9081 | // Render tree |
| 9082 | const lines: string[] = [`**Project Structure (${files.length} files)**`, '']; |
| 9083 | |
| 9084 | const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => { |
| 9085 | if (maxDepth !== undefined && depth > maxDepth) return; |
| 9086 | |
| 9087 | const connector = isLast ? '└── ' : '├── '; |
| 9088 | const childPrefix = isLast ? ' ' : '│ '; |
| 9089 | |
| 9090 | if (node.name) { |
| 9091 | let line = prefix + connector + node.name; |
| 9092 | if (node.file && includeMetadata) { |
| 9093 | line += ` (${node.file.language}, ${node.file.nodeCount} symbols)`; |
| 9094 | } |
| 9095 | lines.push(line); |
| 9096 | } |
| 9097 | |
| 9098 | const children = [...node.children.values()]; |
| 9099 | // Sort: directories first, then files, both alphabetically |
| 9100 | children.sort((a, b) => { |
| 9101 | const aIsDir = a.children.size > 0 && !a.file; |
| 9102 | const bIsDir = b.children.size > 0 && !b.file; |
| 9103 | if (aIsDir !== bIsDir) return aIsDir ? -1 : 1; |
| 9104 | return a.name.localeCompare(b.name); |
no test coverage detected