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

Function receiver_chain

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

1726/// RECEIVER_CHAIN_MAX_LINKS links. Mirrors rustReceiverChain in
1727/// TreeSitterExtractor (#2836): both emit the same bytes.
1728fn receiver_chain(node: Node<'_>, src: &str) -> Option<String> {
1729 let mut links: Vec<String> = Vec::new();
1730 let mut cur = node;
1731 while links.len() <= RECEIVER_CHAIN_MAX_LINKS {
1732 if cur.kind() == "self" || cur.kind() == "identifier" {
1733 let root = &src[cur.byte_range()];
1734 if links.is_empty() || !is_rust_ident(root) {
1735 return None;
1736 }
1737 links.reverse();
1738 let mut out = root.to_string();
1739 for link in &links {
1740 out.push('.');
1741 out.push_str(link);
1742 }
1743 return Some(out);
1744 }
1745 let call = cur.kind() == "call_expression";
1746 let field_of = if call {
1747 unwrap_generic_function(cur.child_by_field_name("function")?)
1748 } else {
1749 cur
1750 };
1751 if field_of.kind() != "field_expression" {
1752 return None;
1753 }
1754 let name = field_of.child_by_field_name("field").map(|f| &src[f.byte_range()]).unwrap_or("");
1755 let ok = if call {
1756 is_rust_ident(name)
1757 } else {
1758 is_rust_ident(name) || (!name.is_empty() && name.chars().all(|c| c.is_ascii_digit()))
1759 };
1760 if !ok {
1761 return None;
1762 }
1763 links.push(if call { format!("{name}()") } else { name.to_string() });
1764 cur = field_of.child_by_field_name("value")?;
1765 }
1766 None
1767}
1768
1769/// A callee path without its turbofish type arguments: `Vec::<u8>::new` →
1770/// `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