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

Method maybe_capture_fn_refs

codegraph-kernel/src/python.rs:891–969  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

889 // --- fn refs (PYTHON_SPEC) ------------------------------------------------------
890
891 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
892 let (mode, field): (&str, &str) = match node.kind() {
893 "argument_list" => ("args", ""),
894 "assignment" => ("rhs", "right"),
895 "keyword_argument" => ("value", "value"),
896 "pair" => ("value", "value"),
897 "list" => ("list", ""),
898 // `return SomeClass` / `return handler` (#1478) — a single
899 // returned expression is a direct named child ('list' shape);
900 // tuple returns sit under expression_list and are not descended
901 // (mirrors PYTHON_SPEC).
902 "return_statement" => ("list", ""),
903 _ => return,
904 };
905 if self.stack.is_empty() {
906 return;
907 }
908 let from = self.top_row();
909
910 let mut values: Vec<Node> = Vec::new();
911 match mode {
912 "args" | "list" => {
913 for i in 0..node.named_child_count() {
914 if let Some(c) = node.named_child(i) {
915 values.push(c);
916 }
917 }
918 }
919 "rhs" => {
920 if let Some(rhs) = node.child_by_field_name(field) {
921 let lhs_text = node
922 .child_by_field_name("left")
923 .map(|l| self.text(l))
924 .unwrap_or("");
925 let lhs_last = util::lhs_last_name()
926 .captures(lhs_text)
927 .and_then(|c| c.get(1))
928 .map(|m| m.as_str());
929 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
930 values.push(rhs);
931 }
932 }
933 }
934 _ => {
935 if let Some(v) = node.child_by_field_name(field) {
936 values.push(v);
937 }
938 }
939 }
940
941 for v in values {
942 let (name, anchor) = match v.kind() {
943 "identifier" => (self.text(v).to_string(), v),
944 // Preserve only statically named member chains, as on WASM.
945 "attribute" => {
946 let Some(attr) = v.child_by_field_name("attribute") else { continue };
947 let name = self.text(v);
948 if !name.split('.').all(|part| {

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 7

pushMethod · 0.80
mapMethod · 0.80
is_stoplistedFunction · 0.70
textMethod · 0.65
getMethod · 0.65
allMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected