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

Function renderNode

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

Source from the content-addressed store, hash-verified

1742 }
1743
1744 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
1745 if (maxDepth !== undefined && depth > maxDepth) return;
1746
1747 const glyphs = getGlyphs();
1748 const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
1749 const childPrefix = isLast ? ' ' : glyphs.treePipe;
1750
1751 if (node.name) {
1752 let line = prefix + connector + node.name;
1753 if (node.file && includeMetadata) {
1754 line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
1755 }
1756 console.log(line);
1757 }
1758
1759 const children = [...node.children.values()];
1760 children.sort((a, b) => {
1761 const aIsDir = a.children.size > 0 && !a.file;
1762 const bIsDir = b.children.size > 0 && !b.file;
1763 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
1764 return a.name.localeCompare(b.name);
1765 });
1766
1767 for (let i = 0; i < children.length; i++) {
1768 const child = children[i]!;
1769 const nextPrefix = node.name ? prefix + childPrefix : prefix;
1770 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
1771 }
1772 };
1773
1774 renderNode(root, '', true, 0);
1775}

Callers 3

renderNodeMethod · 0.85
formatFilesTreeMethod · 0.85
printFileTreeFunction · 0.85

Calls 1

getGlyphsFunction · 0.90

Tested by

no test coverage detected