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

Function receiver_chain

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

The receiver chain a method call is written on, when it is fields and method calls on `self` or on a name: `self.services.store`, `self.store()`, `vis.map`, `self.0`, `x.get:: (1)` — each field by its name or index, each call as `name()`, its arguments and turbofish dropped. None for any other receiver (a path's call, a literal, parentheses, `?`, `.await`, an index, a macro), and past RECEIVER_

(node: Node<'_>, src: &str)

Source from the content-addressed store, hash-verified

1661/// RECEIVER_CHAIN_MAX_LINKS links. Mirrors rustReceiverChain in
1662/// TreeSitterExtractor (#2836): both emit the same bytes.
1663fn receiver_chain(node: Node<'_>, src: &str) -> Option<String> {
1664 let mut links: Vec<String> = Vec::new();
1665 let mut cur = node;
1666 while links.len() <= RECEIVER_CHAIN_MAX_LINKS {
1667 if cur.kind() == "self" || cur.kind() == "identifier" {
1668 let root = &src[cur.byte_range()];
1669 if links.is_empty() || !is_rust_ident(root) {
1670 return None;
1671 }
1672 links.reverse();
1673 let mut out = root.to_string();
1674 for link in &links {
1675 out.push('.');
1676 out.push_str(link);
1677 }
1678 return Some(out);
1679 }
1680 let call = cur.kind() == "call_expression";
1681 let field_of = if call {
1682 unwrap_generic_function(cur.child_by_field_name("function")?)
1683 } else {
1684 cur
1685 };
1686 if field_of.kind() != "field_expression" {
1687 return None;
1688 }
1689 let name = field_of.child_by_field_name("field").map(|f| &src[f.byte_range()]).unwrap_or("");
1690 let ok = if call {
1691 is_rust_ident(name)
1692 } else {
1693 is_rust_ident(name) || (!name.is_empty() && name.chars().all(|c| c.is_ascii_digit()))
1694 };
1695 if !ok {
1696 return None;
1697 }
1698 links.push(if call { format!("{name}()") } else { name.to_string() });
1699 cur = field_of.child_by_field_name("value")?;
1700 }
1701 None
1702}
1703
1704/// A callee path without its turbofish type arguments: `Vec::<u8>::new` →
1705/// `Vec::new`. The brackets nest (`::<Vec<u8>>`), and the `>` of a `->` is

Callers 1

extract_callMethod · 0.85

Calls 6

is_rust_identFunction · 0.85
unwrap_generic_functionFunction · 0.85
lenMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
allMethod · 0.65

Tested by

no test coverage detected