MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / renderNode

Method renderNode

src/mcp/tools.ts:4212–4240  ·  view source on GitHub ↗
(node: TreeNode, prefix: string, isLast: boolean, depth: number)

Source from the content-addressed store, hash-verified

4210 const lines: string[] = [`**Project Structure (${files.length} files)**`, ''];
4211
4212 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
4213 if (maxDepth !== undefined && depth > maxDepth) return;
4214
4215 const connector = isLast ? '└── ' : '├── ';
4216 const childPrefix = isLast ? ' ' : '│ ';
4217
4218 if (node.name) {
4219 let line = prefix + connector + node.name;
4220 if (node.file && includeMetadata) {
4221 line += ` (${node.file.language}, ${node.file.nodeCount} symbols)`;
4222 }
4223 lines.push(line);
4224 }
4225
4226 const children = [...node.children.values()];
4227 // Sort: directories first, then files, both alphabetically
4228 children.sort((a, b) => {
4229 const aIsDir = a.children.size > 0 && !a.file;
4230 const bIsDir = b.children.size > 0 && !b.file;
4231 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
4232 return a.name.localeCompare(b.name);
4233 });
4234
4235 for (let i = 0; i < children.length; i++) {
4236 const child = children[i]!;
4237 const nextPrefix = node.name ? prefix + childPrefix : prefix;
4238 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
4239 }
4240 };
4241
4242 renderNode(root, '', true, 0);
4243

Callers

nothing calls this directly

Calls 1

renderNodeFunction · 0.85

Tested by

no test coverage detected