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

Method extract_call

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

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