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

Method renderNode

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

Source from the content-addressed store, hash-verified

9056 const lines: string[] = [`**Project Structure (${files.length} files)**`, ''];
9057
9058 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
9059 if (maxDepth !== undefined && depth > maxDepth) return;
9060
9061 const connector = isLast ? '└── ' : '├── ';
9062 const childPrefix = isLast ? ' ' : '│ ';
9063
9064 if (node.name) {
9065 let line = prefix + connector + node.name;
9066 if (node.file && includeMetadata) {
9067 line += ` (${node.file.language}, ${node.file.nodeCount} symbols)`;
9068 }
9069 lines.push(line);
9070 }
9071
9072 const children = [...node.children.values()];
9073 // Sort: directories first, then files, both alphabetically
9074 children.sort((a, b) => {
9075 const aIsDir = a.children.size > 0 && !a.file;
9076 const bIsDir = b.children.size > 0 && !b.file;
9077 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
9078 return a.name.localeCompare(b.name);
9079 });
9080
9081 for (let i = 0; i < children.length; i++) {
9082 const child = children[i]!;
9083 const nextPrefix = node.name ? prefix + childPrefix : prefix;
9084 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
9085 }
9086 };
9087
9088 renderNode(root, '', true, 0);
9089

Callers

nothing calls this directly

Calls 2

renderNodeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected