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

Method extract_call

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

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

Tested by

no test coverage detected