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

Function receiver_chain

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

1695/// RECEIVER_CHAIN_MAX_LINKS links. Mirrors rustReceiverChain in
1696/// TreeSitterExtractor (#2836): both emit the same bytes.
1697fn receiver_chain(node: Node<'_>, src: &str) -> Option<String> {
1698 let mut links: Vec<String> = Vec::new();
1699 let mut cur = node;
1700 while links.len() <= RECEIVER_CHAIN_MAX_LINKS {
1701 if cur.kind() == "self" || cur.kind() == "identifier" {
1702 let root = &src[cur.byte_range()];
1703 if links.is_empty() || !is_rust_ident(root) {
1704 return None;
1705 }
1706 links.reverse();
1707 let mut out = root.to_string();
1708 for link in &links {
1709 out.push('.');
1710 out.push_str(link);
1711 }
1712 return Some(out);
1713 }
1714 let call = cur.kind() == "call_expression";
1715 let field_of = if call {
1716 unwrap_generic_function(cur.child_by_field_name("function")?)
1717 } else {
1718 cur
1719 };
1720 if field_of.kind() != "field_expression" {
1721 return None;
1722 }
1723 let name = field_of.child_by_field_name("field").map(|f| &src[f.byte_range()]).unwrap_or("");
1724 let ok = if call {
1725 is_rust_ident(name)
1726 } else {
1727 is_rust_ident(name) || (!name.is_empty() && name.chars().all(|c| c.is_ascii_digit()))
1728 };
1729 if !ok {
1730 return None;
1731 }
1732 links.push(if call { format!("{name}()") } else { name.to_string() });
1733 cur = field_of.child_by_field_name("value")?;
1734 }
1735 None
1736}
1737
1738/// A callee path without its turbofish type arguments: `Vec::<u8>::new` →
1739/// `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