MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / renderNode

Method renderNode

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

Source from the content-addressed store, hash-verified

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);
6690 });
6691
6692 for (let i = 0; i < children.length; i++) {
6693 const child = children[i]!;
6694 const nextPrefix = node.name ? prefix + childPrefix : prefix;
6695 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
6696 }
6697 };
6698
6699 renderNode(root, '', true, 0);
6700

Callers

nothing calls this directly

Calls 1

renderNodeFunction · 0.85

Tested by

no test coverage detected