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

Function renderNode

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

Source from the content-addressed store, hash-verified

2108 }
2109
2110 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
2111 if (maxDepth !== undefined && depth > maxDepth) return;
2112
2113 const glyphs = getGlyphs();
2114 const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
2115 const childPrefix = isLast ? ' ' : glyphs.treePipe;
2116
2117 if (node.name) {
2118 let line = prefix + connector + node.name;
2119 if (node.file && includeMetadata) {
2120 line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
2121 }
2122 console.log(line);
2123 }
2124
2125 const children = [...node.children.values()];
2126 children.sort((a, b) => {
2127 const aIsDir = a.children.size > 0 && !a.file;
2128 const bIsDir = b.children.size > 0 && !b.file;
2129 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
2130 return a.name.localeCompare(b.name);
2131 });
2132
2133 for (let i = 0; i < children.length; i++) {
2134 const child = children[i]!;
2135 const nextPrefix = node.name ? prefix + childPrefix : prefix;
2136 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
2137 }
2138 };
2139
2140 renderNode(root, '', true, 0);
2141}

Callers 3

renderNodeMethod · 0.85
formatFilesTreeMethod · 0.85
printFileTreeFunction · 0.85

Calls 1

getGlyphsFunction · 0.90

Tested by

no test coverage detected