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

Method extract_call

codegraph-kernel/src/python.rs:572–627  ·  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

570
571 /// extractCall — python `call` through the generic tail (attribute callees).
572 fn extract_call(&mut self, node: Node<'t>) {
573 if self.stack.is_empty() {
574 return;
575 }
576 let func = node
577 .child_by_field_name("function")
578 .or_else(|| node.named_child(0));
579 let mut callee_name = String::new();
580
581 if let Some(func) = func {
582 if func.kind() == "attribute" {
583 // `property` and `field` fields don't exist on attribute —
584 // the generic path falls back to namedChild(1) (the attr name).
585 let property = func
586 .child_by_field_name("property")
587 .or_else(|| func.child_by_field_name("field"))
588 .or_else(|| func.named_child(1));
589 if let Some(property) = property {
590 let method_name = self.text(property);
591 let receiver = func
592 .child_by_field_name("object")
593 .or_else(|| func.child_by_field_name("operand"))
594 .or_else(|| func.child_by_field_name("argument"))
595 .or_else(|| func.named_child(0));
596 if let Some(r) = receiver {
597 if is_literal_receiver(r.kind()) {
598 return;
599 }
600 }
601 let recv_ident = receiver.filter(|r| {
602 matches!(r.kind(), "identifier" | "simple_identifier" | "field_identifier")
603 });
604 if let Some(r) = recv_ident {
605 let receiver_name = self.text(r);
606 if !matches!(receiver_name, "self" | "this" | "cls" | "super") {
607 callee_name = format!("{receiver_name}.{method_name}");
608 } else {
609 callee_name = method_name.to_string();
610 }
611 } else {
612 callee_name = method_name.to_string();
613 }
614 }
615 } else {
616 callee_name = self.text(func).to_string();
617 }
618 }
619
620 if !callee_name.is_empty() {
621 if let Some(c) = util::paren_conversion().captures(&callee_name) {
622 callee_name = c[1].to_string();
623 }
624 let from = self.top_row();
625 self.push_ref_at(from, &callee_name.clone(), edge_kind_index("calls").unwrap(), node);
626 }
627 }
628
629 /// extractDecoratorsFor — python decorators are PRECEDING SIBLINGS inside

Callers 2

visit_nodeMethod · 0.45

Calls 6

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

Tested by

no test coverage detected