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

Method extract_call

codegraph-kernel/src/rustlang.rs:880–1014  ·  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

878
879 /// extractCall — the rust paths of the generic else-branch (4312+).
880 fn extract_call(&mut self, node: Node<'t>) {
881 if self.stack.is_empty() {
882 return;
883 }
884 let func = node
885 .child_by_field_name("function")
886 .or_else(|| node.named_child(0));
887 // A turbofish — `s.get::<u32>()`, `helper::<u8>()`,
888 // `Store::with_capacity::<u8>(1)` — calls the function it wraps: its
889 // type arguments are no part of the callee's name. Mirrors
890 // TreeSitterExtractor.extractCall.
891 let func = func.map(unwrap_generic_function);
892 let mut callee_name = String::new();
893
894 if let Some(func) = func {
895 if func.kind() == "field_expression" {
896 let property = func
897 .child_by_field_name("property")
898 .or_else(|| func.child_by_field_name("field"))
899 .or_else(|| func.named_child(1));
900 if let Some(property) = property {
901 let method_name = self.text(property);
902 let receiver = func
903 .child_by_field_name("object")
904 .or_else(|| func.child_by_field_name("operand"))
905 .or_else(|| func.child_by_field_name("argument"))
906 .or_else(|| func.named_child(0));
907 if let Some(r) = receiver {
908 if is_literal_receiver(r.kind()) {
909 return; // emit NOTHING (#1230)
910 }
911 }
912 if let Some(r) = receiver {
913 match r.kind() {
914 // rust `self` is node kind `self`, NOT `identifier` —
915 // it dodges this branch and falls to the bare-name
916 // fallthrough (same net effect as SKIP_RECEIVERS).
917 "identifier" | "simple_identifier" | "field_identifier" => {
918 let receiver_name = self.text(r);
919 if !matches!(receiver_name, "self" | "this" | "cls" | "super") {
920 callee_name = format!("{receiver_name}.{method_name}");
921 } else {
922 callee_name = method_name.to_string();
923 }
924 }
925 "call_expression" => {
926 // Chained-call re-encode: an associated-
927 // function chain (`Foo::new().bar()`, inner
928 // callee a scoped_identifier). A chain of
929 // fields and method calls on `self` or a name
930 // (`self.store().put()`, #2836) keeps that
931 // chain; any other instance chain the bare
932 // method name.
933 let inner_fn = r.child_by_field_name("function").map(unwrap_generic_function);
934 let reencode =
935 inner_fn.map(|f| f.kind() == "scoped_identifier").unwrap_or(false);
936 if reencode {
937 let inner: String = self

Callers 2

visit_nodeMethod · 0.45

Calls 10

strip_turbofishFunction · 0.85
receiver_chainFunction · 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