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

Method visitFunctionBody

src/extraction/tree-sitter.ts:7597–7885  ·  view source on GitHub ↗
(body: SyntaxNode, _functionId: string)

Source from the content-addressed store, hash-verified

7595 }
7596
7597 private visitFunctionBody(body: SyntaxNode, _functionId: string): void {
7598 if (!this.extractor) return;
7599
7600 // `parent` is handed down by the walk (absent at the body's root): reading
7601 // `node.parent` walks down from the tree's root on every call.
7602 const visitForCallsAndStructure = (node: SyntaxNode, parent?: SyntaxNode): void => {
7603 const nodeType = node.type;
7604
7605 // A function-like macro defined inside a body is still a macro (#1838).
7606 if ((this.language === 'c' || this.language === 'cpp') && nodeType === 'preproc_function_def') {
7607 this.visitNode(node);
7608 return;
7609 }
7610
7611 // Function-as-value capture (#756) — function bodies are walked here,
7612 // not in visitNode, so the capture hook must fire in both walkers.
7613 this.maybeCaptureFnRefs(node, nodeType);
7614
7615 // A named object literal in a body — an IIFE's `const App = {…}`, a
7616 // handler map in a function — owns its function members as one at
7617 // module scope does, and so does `window.App = {…}` written in here
7618 // (#2300). Each handles its whole subtree.
7619 if (nodeType === 'variable_declarator' && this.extractLocalObjectOwner(node)) return;
7620 if (nodeType === 'assignment_expression' && this.extractAssignedObjectOwner(node, false)) return;
7621
7622 // Rocket route-registration macros (`routes![…]` / `catchers![…]`): the
7623 // handler paths live in a raw token tree the call walker can't see.
7624 if (nodeType === 'macro_invocation') this.extractRustRouteMacro(node);
7625
7626 // A CFML `include "x.cfm";` in a function body includes the template
7627 // there, as it does at component scope (#2651).
7628 if (nodeType === 'include_statement' && this.language === 'cfscript') this.extractImport(node);
7629
7630 if (this.extractor!.callTypes.includes(nodeType)) {
7631 this.extractCall(node);
7632 } else if (INSTANTIATION_KINDS.has(nodeType) || this.isVbnetConstructorShapedArrayCreation(node)) {
7633 // `new Foo()` inside a function body — emit an `instantiates`
7634 // reference. Without this branch the body walker only knew
7635 // about `call_expression`, so constructor invocations
7636 // produced no graph edges at all.
7637 this.extractInstantiation(node);
7638 // Anonymous class with body: `new T() { ... }` (Java/C#). Extract as
7639 // a class so interface-impl synthesis (Phase 5.5) can bridge T's
7640 // methods to the overrides — same rationale as in visitNode.
7641 const anonBody = this.findAnonymousClassBody(node);
7642 if (anonBody) {
7643 this.extractAnonymousClass(node, anonBody);
7644 return;
7645 }
7646 } else if (this.language === 'kotlin' && nodeType === 'infix_expression') {
7647 this.extractKotlinInfixCall(node);
7648 } else if (this.extractor!.extractBareCall) {
7649 const calleeName = this.extractor!.extractBareCall(node, this.source);
7650 if (calleeName && this.nodeStack.length > 0) {
7651 const callerId = this.nodeStack[this.nodeStack.length - 1];
7652 if (callerId) {
7653 this.unresolvedReferences.push({
7654 fromNodeId: callerId,

Callers 11

dispatchNodeMethod · 0.95
extractFunctionMethod · 0.95
visitPatternDefaultsMethod · 0.95
walkComponentWrapperMethod · 0.95
extractMethodMethod · 0.95
extractFieldMethod · 0.95
extractRtkEndpointsMethod · 0.95
extractVariableMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected