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

Function renderNode

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

Source from the content-addressed store, hash-verified

1635 }
1636
1637 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
1638 if (maxDepth !== undefined && depth > maxDepth) return;
1639
1640 const glyphs = getGlyphs();
1641 const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
1642 const childPrefix = isLast ? ' ' : glyphs.treePipe;
1643
1644 if (node.name) {
1645 let line = prefix + connector + node.name;
1646 if (node.file && includeMetadata) {
1647 line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
1648 }
1649 console.log(line);
1650 }
1651
1652 const children = [...node.children.values()];
1653 children.sort((a, b) => {
1654 const aIsDir = a.children.size > 0 && !a.file;
1655 const bIsDir = b.children.size > 0 && !b.file;
1656 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
1657 return a.name.localeCompare(b.name);
1658 });
1659
1660 for (let i = 0; i < children.length; i++) {
1661 const child = children[i]!;
1662 const nextPrefix = node.name ? prefix + childPrefix : prefix;
1663 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
1664 }
1665 };
1666
1667 renderNode(root, '', true, 0);
1668}

Callers 3

renderNodeMethod · 0.85
formatFilesTreeMethod · 0.85
printFileTreeFunction · 0.85

Calls 1

getGlyphsFunction · 0.90

Tested by

no test coverage detected