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

Method renderNode

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

Source from the content-addressed store, hash-verified

9082 const lines: string[] = [`**Project Structure (${files.length} files)**`, ''];
9083
9084 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
9085 if (maxDepth !== undefined && depth > maxDepth) return;
9086
9087 const connector = isLast ? '└── ' : '├── ';
9088 const childPrefix = isLast ? ' ' : '│ ';
9089
9090 if (node.name) {
9091 let line = prefix + connector + node.name;
9092 if (node.file && includeMetadata) {
9093 line += ` (${node.file.language}, ${node.file.nodeCount} symbols)`;
9094 }
9095 lines.push(line);
9096 }
9097
9098 const children = [...node.children.values()];
9099 // Sort: directories first, then files, both alphabetically
9100 children.sort((a, b) => {
9101 const aIsDir = a.children.size > 0 && !a.file;
9102 const bIsDir = b.children.size > 0 && !b.file;
9103 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
9104 return a.name.localeCompare(b.name);
9105 });
9106
9107 for (let i = 0; i < children.length; i++) {
9108 const child = children[i]!;
9109 const nextPrefix = node.name ? prefix + childPrefix : prefix;
9110 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
9111 }
9112 };
9113
9114 renderNode(root, '', true, 0);
9115

Callers

nothing calls this directly

Calls 2

renderNodeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected