* Format files as a tree structure
(
files: { path: string; language: string; nodeCount: number }[],
includeMetadata: boolean,
maxDepth?: number
)
| 4302 | * Format files as a tree structure |
| 4303 | */ |
| 4304 | private formatFilesTree( |
| 4305 | files: { path: string; language: string; nodeCount: number }[], |
| 4306 | includeMetadata: boolean, |
| 4307 | maxDepth?: number |
| 4308 | ): string { |
| 4309 | // Build tree structure |
| 4310 | interface TreeNode { |
| 4311 | name: string; |
| 4312 | children: Map<string, TreeNode>; |
| 4313 | file?: { language: string; nodeCount: number }; |
| 4314 | } |
| 4315 | |
| 4316 | const root: TreeNode = { name: '', children: new Map() }; |
| 4317 | |
| 4318 | for (const file of files) { |
| 4319 | const parts = file.path.split('/'); |
| 4320 | let current = root; |
| 4321 | |
| 4322 | for (let i = 0; i < parts.length; i++) { |
| 4323 | const part = parts[i]; |
| 4324 | if (!part) continue; |
| 4325 | |
| 4326 | if (!current.children.has(part)) { |
| 4327 | current.children.set(part, { name: part, children: new Map() }); |
| 4328 | } |
| 4329 | current = current.children.get(part)!; |
| 4330 | |
| 4331 | // If this is the last part, it's a file |
| 4332 | if (i === parts.length - 1) { |
| 4333 | current.file = { language: file.language, nodeCount: file.nodeCount }; |
| 4334 | } |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | // Render tree |
| 4339 | const lines: string[] = [`**Project Structure (${files.length} files)**`, '']; |
| 4340 | |
| 4341 | const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => { |
| 4342 | if (maxDepth !== undefined && depth > maxDepth) return; |
| 4343 | |
| 4344 | const connector = isLast ? '└── ' : '├── '; |
| 4345 | const childPrefix = isLast ? ' ' : '│ '; |
| 4346 | |
| 4347 | if (node.name) { |
| 4348 | let line = prefix + connector + node.name; |
| 4349 | if (node.file && includeMetadata) { |
| 4350 | line += ` (${node.file.language}, ${node.file.nodeCount} symbols)`; |
| 4351 | } |
| 4352 | lines.push(line); |
| 4353 | } |
| 4354 | |
| 4355 | const children = [...node.children.values()]; |
| 4356 | // Sort: directories first, then files, both alphabetically |
| 4357 | children.sort((a, b) => { |
| 4358 | const aIsDir = a.children.size > 0 && !a.file; |
| 4359 | const bIsDir = b.children.size > 0 && !b.file; |
| 4360 | if (aIsDir !== bIsDir) return aIsDir ? -1 : 1; |
| 4361 | return a.name.localeCompare(b.name); |
no test coverage detected