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

Method extract_call

codegraph-kernel/src/go.rs:813–931  ·  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

811
812 /// extractCall — Go's generic-tail paths (selector_expression callees).
813 fn extract_call(&mut self, node: Node<'t>) {
814 if self.stack.is_empty() {
815 return;
816 }
817 let func = node
818 .child_by_field_name("function")
819 .or_else(|| node.named_child(0));
820 let mut callee_name = String::new();
821
822 if let Some(func) = func {
823 if func.kind() == "selector_expression" {
824 let property = func
825 .child_by_field_name("property")
826 .or_else(|| func.child_by_field_name("field"));
827 if let Some(property) = property {
828 let method_name = self.text(property);
829 let receiver = func
830 .child_by_field_name("object")
831 .or_else(|| func.child_by_field_name("operand"))
832 .or_else(|| func.child_by_field_name("argument"))
833 .or_else(|| func.named_child(0));
834 if let Some(r) = receiver {
835 if is_literal_receiver(r.kind()) {
836 return;
837 }
838 }
839 if let Some(r) = receiver {
840 match r.kind() {
841 "identifier" | "simple_identifier" | "field_identifier" => {
842 let receiver_name = self.text(r);
843 if !matches!(receiver_name, "self" | "this" | "cls" | "super") {
844 callee_name = format!("{receiver_name}.{method_name}");
845 } else {
846 callee_name = method_name.to_string();
847 }
848 }
849 "call_expression" => {
850 // Bare package-level factory chain `New().Method()`
851 // re-encodes; instance chains keep the bare name.
852 let inner_fn = r.child_by_field_name("function");
853 let builtin = inner_fn
854 .filter(|f| f.kind() == "identifier")
855 .map(|f| self.text(f))
856 .filter(|t| matches!(*t, "new" | "make" | "append"));
857 if let Some(builtin) = builtin {
858 // A call on what a builtin hands back (#3237):
859 // `new` and `make` keep the named type they
860 // write (`new(Route).Host`); any other keeps the
861 // bare name, read at the call by the resolver.
862 // Mirrors goBuiltinNamedType (tree-sitter.ts).
863 let written = if builtin == "append" {
864 None
865 } else {
866 r.child_by_field_name("arguments")
867 .and_then(|a| a.named_child(0))
868 .filter(|t| {
869 matches!(
870 t.kind(),

Callers 2

visit_nodeMethod · 0.45

Calls 9

go_two_hop_reFunction · 0.85
edge_kind_indexFunction · 0.85
mapMethod · 0.80
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