MCPcopy
hub / github.com/colbymchenry/codegraph / renderNode

Function renderNode

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

Source from the content-addressed store, hash-verified

1404 }
1405
1406 const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => {
1407 if (maxDepth !== undefined && depth > maxDepth) return;
1408
1409 const glyphs = getGlyphs();
1410 const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
1411 const childPrefix = isLast ? ' ' : glyphs.treePipe;
1412
1413 if (node.name) {
1414 let line = prefix + connector + node.name;
1415 if (node.file && includeMetadata) {
1416 line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
1417 }
1418 console.log(line);
1419 }
1420
1421 const children = [...node.children.values()];
1422 children.sort((a, b) => {
1423 const aIsDir = a.children.size > 0 && !a.file;
1424 const bIsDir = b.children.size > 0 && !b.file;
1425 if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
1426 return a.name.localeCompare(b.name);
1427 });
1428
1429 for (let i = 0; i < children.length; i++) {
1430 const child = children[i]!;
1431 const nextPrefix = node.name ? prefix + childPrefix : prefix;
1432 renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
1433 }
1434 };
1435
1436 renderNode(root, '', true, 0);
1437}

Callers 3

renderNodeMethod · 0.85
formatFilesTreeMethod · 0.85
printFileTreeFunction · 0.85

Calls 1

getGlyphsFunction · 0.90

Tested by

no test coverage detected