* Format files as a tree structure
(
files: { path: string; language: string; nodeCount: number }[],
includeMetadata: boolean,
maxDepth?: number
)
| 9294 | * Format files as a tree structure |
| 9295 | */ |
| 9296 | private formatFilesTree( |
| 9297 | files: { path: string; language: string; nodeCount: number }[], |
| 9298 | includeMetadata: boolean, |
| 9299 | maxDepth?: number |
| 9300 | ): string { |
| 9301 | // Build tree structure |
| 9302 | interface TreeNode { |
| 9303 | name: string; |
| 9304 | children: Map<string, TreeNode>; |
| 9305 | file?: { language: string; nodeCount: number }; |
| 9306 | } |
| 9307 | |
| 9308 | const root: TreeNode = { name: '', children: new Map() }; |
| 9309 | |
| 9310 | for (const file of files) { |
| 9311 | const parts = file.path.split('/'); |
| 9312 | let current = root; |
| 9313 | |
| 9314 | for (let i = 0; i < parts.length; i++) { |
| 9315 | const part = parts[i]; |
| 9316 | if (!part) continue; |
| 9317 | |
| 9318 | if (!current.children.has(part)) { |
| 9319 | current.children.set(part, { name: part, children: new Map() }); |
| 9320 | } |
| 9321 | current = current.children.get(part)!; |
| 9322 | |
| 9323 | // If this is the last part, it's a file |
| 9324 | if (i === parts.length - 1) { |
| 9325 | current.file = { language: file.language, nodeCount: file.nodeCount }; |
| 9326 | } |
| 9327 | } |
| 9328 | } |
| 9329 | |
| 9330 | // Render tree |
| 9331 | const lines: string[] = [`**Project Structure (${files.length} files)**`, '']; |
| 9332 | |
| 9333 | const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => { |
| 9334 | if (maxDepth !== undefined && depth > maxDepth) return; |
| 9335 | |
| 9336 | const connector = isLast ? '└── ' : '├── '; |
| 9337 | const childPrefix = isLast ? ' ' : '│ '; |
| 9338 | |
| 9339 | if (node.name) { |
| 9340 | let line = prefix + connector + node.name; |
| 9341 | if (node.file && includeMetadata) { |
| 9342 | line += ` (${node.file.language}, ${node.file.nodeCount} symbols)`; |
| 9343 | } |
| 9344 | lines.push(line); |
| 9345 | } |
| 9346 | |
| 9347 | const children = [...node.children.values()]; |
| 9348 | // Sort: directories first, then files, both alphabetically |
| 9349 | children.sort((a, b) => { |
| 9350 | const aIsDir = a.children.size > 0 && !a.file; |
| 9351 | const bIsDir = b.children.size > 0 && !b.file; |
| 9352 | if (aIsDir !== bIsDir) return aIsDir ? -1 : 1; |
| 9353 | return a.name.localeCompare(b.name); |
no test coverage detected