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

Method extract_call

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

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