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

Function receiver_chain

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

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