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

Function renderNode

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

Source from the content-addressed store, hash-verified

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

Callers 3

renderNodeMethod · 0.85
formatFilesTreeMethod · 0.85
printFileTreeFunction · 0.85

Calls 1

getGlyphsFunction · 0.90

Tested by

no test coverage detected