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

Method extract_call

codegraph-kernel/src/rustlang.rs:790–897  ·  view source on GitHub ↗

extractCall — the rust paths of the generic else-branch (4312+).

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

Source from the content-addressed store, hash-verified

788
789 /// extractCall — the rust paths of the generic else-branch (4312+).
790 fn extract_call(&mut self, node: Node<'t>) {
791 if self.stack.is_empty() {
792 return;
793 }
794 let func = node
795 .child_by_field_name("function")
796 .or_else(|| node.named_child(0));
797 let mut callee_name = String::new();
798
799 if let Some(func) = func {
800 if func.kind() == "field_expression" {
801 let property = func
802 .child_by_field_name("property")
803 .or_else(|| func.child_by_field_name("field"))
804 .or_else(|| func.named_child(1));
805 if let Some(property) = property {
806 let method_name = self.text(property);
807 let receiver = func
808 .child_by_field_name("object")
809 .or_else(|| func.child_by_field_name("operand"))
810 .or_else(|| func.child_by_field_name("argument"))
811 .or_else(|| func.named_child(0));
812 if let Some(r) = receiver {
813 if is_literal_receiver(r.kind()) {
814 return; // emit NOTHING (#1230)
815 }
816 }
817 if let Some(r) = receiver {
818 match r.kind() {
819 // rust `self` is node kind `self`, NOT `identifier` —
820 // it dodges this branch and falls to the bare-name
821 // fallthrough (same net effect as SKIP_RECEIVERS).
822 "identifier" | "simple_identifier" | "field_identifier" => {
823 let receiver_name = self.text(r);
824 if !matches!(receiver_name, "self" | "this" | "cls" | "super") {
825 callee_name = format!("{receiver_name}.{method_name}");
826 } else {
827 callee_name = method_name.to_string();
828 }
829 }
830 "call_expression" => {
831 // Chained-call re-encode: ONLY an associated-
832 // function chain (`Foo::new().bar()`, inner
833 // callee a scoped_identifier). Instance chains
834 // keep the bare method name.
835 let inner_fn = r.child_by_field_name("function");
836 let reencode =
837 inner_fn.map(|f| f.kind() == "scoped_identifier").unwrap_or(false);
838 if reencode {
839 let inner: String = self
840 .text(inner_fn.unwrap())
841 .replace("->", ".")
842 .chars()
843 .filter(|c| !c.is_whitespace())
844 .collect();
845 callee_name = format!("{inner}().{method_name}");
846 } else {
847 callee_name = method_name.to_string();

Callers 2

visit_nodeMethod · 0.45

Calls 7

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