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

Function renderNode

src/bin/codegraph.ts:1651–1679  ·  view source on GitHub ↗
(node: TreeNode, prefix: string, isLast: boolean, depth: number)

Source from the content-addressed store, hash-verified

1649 }
1650
1651 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
1652 if (maxDepth !== undefined && depth > maxDepth) return;
1653
1654 const glyphs = getGlyphs();
1655 const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
1656 const childPrefix = isLast ? ' ' : glyphs.treePipe;
1657
1658 if (node.name) {
1659 let line = prefix + connector + node.name;
1660 if (node.file && includeMetadata) {
1661 line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
1662 }
1663 console.log(line);
1664 }
1665
1666 const children = [...node.children.values()];
1667 children.sort((a, b) => {
1668 const aIsDir = a.children.size > 0 && !a.file;
1669 const bIsDir = b.children.size > 0 && !b.file;
1670 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
1671 return a.name.localeCompare(b.name);
1672 });
1673
1674 for (let i = 0; i < children.length; i++) {
1675 const child = children[i]!;
1676 const nextPrefix = node.name ? prefix + childPrefix : prefix;
1677 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
1678 }
1679 };
1680
1681 renderNode(root, '', true, 0);
1682}

Callers 3

renderNodeMethod · 0.85
formatFilesTreeMethod · 0.85
printFileTreeFunction · 0.85

Calls 1

getGlyphsFunction · 0.90

Tested by

no test coverage detected