MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / extractSymbolName

Function extractSymbolName

src/context/ast-chunk.ts:72–92  ·  view source on GitHub ↗

Best-effort name extraction for a declaration node.

(node: any, source: string)

Source from the content-addressed store, hash-verified

70
71/** Best-effort name extraction for a declaration node. */
72function extractSymbolName(node: any, source: string): string | undefined {
73 // Most grammars expose a `name` child; some wrap (export_statement → declaration → name).
74 const nameNode = node.childForFieldName?.('name');
75 if (nameNode) return source.slice(nameNode.startIndex, nameNode.endIndex);
76 // export_statement / decorated_definition: dig one level.
77 for (let i = 0; i < (node.childCount ?? 0); i++) {
78 const child = node.child(i);
79 if (!child) continue;
80 const inner = child.childForFieldName?.('name');
81 if (inner) return source.slice(inner.startIndex, inner.endIndex);
82 }
83 // lexical_declaration: `const X = ...` → variable_declarator → name
84 for (let i = 0; i < (node.childCount ?? 0); i++) {
85 const child = node.child(i);
86 if (child?.type === 'variable_declarator') {
87 const id = child.childForFieldName?.('name');
88 if (id) return source.slice(id.startIndex, id.endIndex);
89 }
90 }
91 return undefined;
92}
93
94function mkChunk(rel: string, lines: string[], start: number, end: number, symbol?: string): Chunk {
95 const text = lines.slice(start, end).join('\n');

Callers 1

collectFunction · 0.85

Calls 1

childMethod · 0.80

Tested by

no test coverage detected