MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / extractName

Function extractName

src/core/tree-sitter.ts:139–163  ·  view source on GitHub ↗
(node: TSNode, _kind: string)

Source from the content-addressed store, hash-verified

137}
138
139function extractName(node: TSNode, _kind: string): string {
140 const nameNode = node.childForFieldName("name")
141 ?? node.childForFieldName("declarator")
142 ?? node.namedChildren?.find((c: TSNode) =>
143 c.type === "identifier" || c.type === "type_identifier"
144 || c.type === "property_identifier" || c.type === "simple_identifier"
145 );
146
147 if (nameNode) {
148 if (nameNode.type === "function_declarator" || nameNode.type === "pointer_declarator") {
149 const inner = nameNode.childForFieldName("declarator") ?? nameNode.namedChildren?.[0];
150 if (inner) return inner.text;
151 }
152 return nameNode.text;
153 }
154
155 for (const child of node.namedChildren ?? []) {
156 if (child.type === "variable_declarator" || child.type === "const_declaration") {
157 const inner = child.childForFieldName("name");
158 if (inner) return inner.text;
159 }
160 }
161
162 return node.text.split(/[\s({]/)[0]?.trim() ?? "anonymous";
163}
164
165function extractSignature(node: TSNode): string {
166 const lines = node.text.split("\n");

Callers 1

visitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected