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

Method extract_call

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

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