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

Method extract_call

codegraph-kernel/src/go.rs:728–816  ·  view source on GitHub ↗

extractCall — Go's generic-tail paths (selector_expression callees).

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

Source from the content-addressed store, hash-verified

726
727 /// extractCall — Go's generic-tail paths (selector_expression callees).
728 fn extract_call(&mut self, node: Node<'t>) {
729 if self.stack.is_empty() {
730 return;
731 }
732 let func = node
733 .child_by_field_name("function")
734 .or_else(|| node.named_child(0));
735 let mut callee_name = String::new();
736
737 if let Some(func) = func {
738 if func.kind() == "selector_expression" {
739 let property = func
740 .child_by_field_name("property")
741 .or_else(|| func.child_by_field_name("field"));
742 if let Some(property) = property {
743 let method_name = self.text(property);
744 let receiver = func
745 .child_by_field_name("object")
746 .or_else(|| func.child_by_field_name("operand"))
747 .or_else(|| func.child_by_field_name("argument"))
748 .or_else(|| func.named_child(0));
749 if let Some(r) = receiver {
750 if is_literal_receiver(r.kind()) {
751 return;
752 }
753 }
754 if let Some(r) = receiver {
755 match r.kind() {
756 "identifier" | "simple_identifier" | "field_identifier" => {
757 let receiver_name = self.text(r);
758 if !matches!(receiver_name, "self" | "this" | "cls" | "super") {
759 callee_name = format!("{receiver_name}.{method_name}");
760 } else {
761 callee_name = method_name.to_string();
762 }
763 }
764 "call_expression" => {
765 // Bare package-level factory chain `New().Method()`
766 // re-encodes; instance chains keep the bare name.
767 let inner_fn = r.child_by_field_name("function");
768 let reencode =
769 inner_fn.map(|f| f.kind() == "identifier").unwrap_or(false);
770 if reencode {
771 let inner: String = self
772 .text(inner_fn.unwrap())
773 .replace("->", ".")
774 .chars()
775 .filter(|c| !c.is_whitespace())
776 .collect();
777 callee_name = format!("{inner}().{method_name}");
778 } else {
779 callee_name = method_name.to_string();
780 }
781 }
782 "selector_expression" => {
783 // 2-hop field chain `t.conn.Exec` (#1276).
784 let chain: String = self
785 .text(r)

Callers 2

visit_nodeMethod · 0.45

Calls 8

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

Tested by

no test coverage detected