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

Function renderNode

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

Source from the content-addressed store, hash-verified

2243 }
2244
2245 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
2246 if (maxDepth !== undefined && depth > maxDepth) return;
2247
2248 const glyphs = getGlyphs();
2249 const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
2250 const childPrefix = isLast ? ' ' : glyphs.treePipe;
2251
2252 if (node.name) {
2253 let line = prefix + connector + node.name;
2254 if (node.file && includeMetadata) {
2255 line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
2256 }
2257 console.log(line);
2258 }
2259
2260 const children = [...node.children.values()];
2261 children.sort((a, b) => {
2262 const aIsDir = a.children.size > 0 && !a.file;
2263 const bIsDir = b.children.size > 0 && !b.file;
2264 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
2265 return a.name.localeCompare(b.name);
2266 });
2267
2268 for (let i = 0; i < children.length; i++) {
2269 const child = children[i]!;
2270 const nextPrefix = node.name ? prefix + childPrefix : prefix;
2271 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
2272 }
2273 };
2274
2275 renderNode(root, '', true, 0);
2276}

Callers 3

renderNodeMethod · 0.85
formatFilesTreeMethod · 0.85
printFileTreeFunction · 0.85

Calls 1

getGlyphsFunction · 0.90

Tested by

no test coverage detected