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

Method collect

src/extraction/tree-sitter.ts:3460–3494  ·  view source on GitHub ↗
(n: SyntaxNode, prefix: string)

Source from the content-addressed store, hash-verified

3458 const paths: { text: string; node: SyntaxNode }[] = [];
3459 const join = (prefix: string, seg: string): string => (prefix ? `${prefix}::${seg}` : seg);
3460 const collect = (n: SyntaxNode, prefix: string): void => {
3461 switch (n.type) {
3462 case 'identifier':
3463 paths.push({ text: join(prefix, getNodeText(n, this.source)), node: n });
3464 break;
3465 case 'scoped_identifier': {
3466 // Full scoped path (`a::b::C`); combine with any outer group prefix.
3467 const full = getNodeText(n, this.source).trim();
3468 paths.push({ text: prefix ? `${prefix}::${full}` : full, node: n });
3469 break;
3470 }
3471 case 'scoped_use_list': {
3472 // `path::{ ... }` — the group's path becomes the prefix for each item.
3473 const pathNode = getChildByField(n, 'path');
3474 const seg = pathNode ? getNodeText(pathNode, this.source).trim() : '';
3475 const newPrefix = seg ? join(prefix, seg) : prefix;
3476 const list = getChildByField(n, 'list') ?? n.namedChildren.find((c) => c.type === 'use_list');
3477 if (list) collect(list, newPrefix);
3478 break;
3479 }
3480 case 'use_list':
3481 for (let i = 0; i < n.namedChildCount; i++) {
3482 const c = n.namedChild(i);
3483 if (c) collect(c, prefix);
3484 }
3485 break;
3486 case 'use_as_clause': {
3487 // `Path as Alias` → link the source path (the definition), not the alias.
3488 const p = getChildByField(n, 'path') ?? n.namedChild(0);
3489 if (p) collect(p, prefix);
3490 break;
3491 }
3492 // use_wildcard → no specific binding to link.
3493 }
3494 };
3495 for (let i = 0; i < node.namedChildCount; i++) {
3496 const c = node.namedChild(i);
3497 if (c) collect(c, '');

Callers

nothing calls this directly

Calls 3

getNodeTextFunction · 0.90
getChildByFieldFunction · 0.90
collectFunction · 0.85

Tested by

no test coverage detected