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

Method extract_call

codegraph-kernel/src/python.rs:689–775  ·  view source on GitHub ↗

extractCall — python `call` through the generic tail (attribute callees).

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

687
688 /// extractCall — python `call` through the generic tail (attribute callees).
689 fn extract_call(&mut self, node: Node<'t>) {
690 if self.stack.is_empty() {
691 return;
692 }
693 let func = node
694 .child_by_field_name("function")
695 .or_else(|| node.named_child(0));
696 let mut callee_name = String::new();
697
698 if let Some(func) = func {
699 if func.kind() == "attribute" {
700 // `property` and `field` fields don't exist on attribute —
701 // the generic path falls back to namedChild(1) (the attr name).
702 let property = func
703 .child_by_field_name("property")
704 .or_else(|| func.child_by_field_name("field"))
705 .or_else(|| func.named_child(1));
706 if let Some(property) = property {
707 let method_name = self.text(property);
708 let receiver = func
709 .child_by_field_name("object")
710 .or_else(|| func.child_by_field_name("operand"))
711 .or_else(|| func.child_by_field_name("argument"))
712 .or_else(|| func.named_child(0));
713 if let Some(r) = receiver {
714 if is_literal_receiver(r.kind()) {
715 return;
716 }
717 }
718 let recv_ident = receiver.filter(|r| {
719 matches!(r.kind(), "identifier" | "simple_identifier" | "field_identifier")
720 });
721 if let Some(r) = recv_ident {
722 let receiver_name = self.text(r);
723 if !matches!(receiver_name, "self" | "this" | "cls" | "super") {
724 callee_name = format!("{receiver_name}.{method_name}");
725 } else {
726 callee_name = method_name.to_string();
727 }
728 } else if let Some(r) = receiver.filter(|r| r.kind() == "call") {
729 // Call receiver — `d.setdefault(k, []).append(v)` (#1683):
730 // `<inner>().<method>`, or nothing when the inner callee
731 // is not a plain name / attribute chain. Mirrors
732 // TreeSitterExtractor.extractCall.
733 let Some(inner) = self.plain_inner_callee(r) else { return };
734 callee_name = format!("{inner}().{method_name}");
735 } else if let Some(r) = receiver {
736 // Any receiver shape the arms above do not claim — attribute
737 // chain (`self.data.append`) and subscript (`d[k].append`).
738 // The call-chain shape (`rows.setdefault(k, []).append(x)`)
739 // is taken by the `<inner>().<method>` arm above (#1748),
740 // which is matched first.
741 // These used to fall through to a BARE method_name. A bare name
742 // matching a common list/dict/str method (`append`, `get`,
743 // `update`, ...) exact-matches an unrelated top-level project
744 // function sharing that name, fabricating a call edge (#66,
745 // same class as #1230/#1276). Keep the receiver's source text
746 // as a qualifier so the ref can only resolve through

Callers 2

visit_nodeMethod · 0.45

Calls 8

collapse_js_whitespaceFunction · 0.85
edge_kind_indexFunction · 0.85
is_literal_receiverFunction · 0.70
textMethod · 0.65
unwrapMethod · 0.60
plain_inner_calleeMethod · 0.45
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected