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

Function walk

scripts/add-lang/dump-ast.mjs:83–94  ·  view source on GitHub ↗
(node, depth, fieldName)

Source from the content-addressed store, hash-verified

81};
82
83function walk(node, depth, fieldName) {
84 if (node.isNamed) freq.set(node.type, (freq.get(node.type) || 0) + 1);
85 if ((node.isNamed || showAll) && depth <= maxDepth) {
86 const field = fieldName ? `${fieldName}: ` : '';
87 const leaf = node.childCount === 0 ? ` "${snippet(node)}"` : '';
88 console.log(`${' '.repeat(depth)}${field}${node.type} @${node.startPosition.row + 1}:${node.startPosition.column}${leaf}`);
89 }
90 for (let i = 0; i < node.childCount; i++) {
91 const child = node.child(i);
92 if (child) walk(child, depth + 1, node.fieldNameForChild(i));
93 }
94}
95
96console.log(`\n# AST for ${sampleFile} (grammar: ${wasmPath.split('/').pop()})\n`);
97walk(tree.rootNode, 0, null);

Callers 1

dump-ast.mjsFile · 0.70

Calls 3

snippetFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected