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

Method extract_call

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

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