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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

707 // --- fn refs (PYTHON_SPEC) ------------------------------------------------------
708
709 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
710 let (mode, field): (&str, &str) = match node.kind() {
711 "argument_list" => ("args", ""),
712 "assignment" => ("rhs", "right"),
713 "keyword_argument" => ("value", "value"),
714 "pair" => ("value", "value"),
715 "list" => ("list", ""),
716 // `return SomeClass` / `return handler` (#1478) — a single
717 // returned expression is a direct named child ('list' shape);
718 // tuple returns sit under expression_list and are not descended
719 // (mirrors PYTHON_SPEC).
720 "return_statement" => ("list", ""),
721 _ => return,
722 };
723 if self.stack.is_empty() {
724 return;
725 }
726 let from = self.top_row();
727
728 let mut values: Vec<Node> = Vec::new();
729 match mode {
730 "args" | "list" => {
731 for i in 0..node.named_child_count() {
732 if let Some(c) = node.named_child(i) {
733 values.push(c);
734 }
735 }
736 }
737 "rhs" => {
738 if let Some(rhs) = node.child_by_field_name(field) {
739 let lhs_text = node
740 .child_by_field_name("left")
741 .map(|l| self.text(l))
742 .unwrap_or("");
743 let lhs_last = util::lhs_last_name()
744 .captures(lhs_text)
745 .and_then(|c| c.get(1))
746 .map(|m| m.as_str());
747 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
748 values.push(rhs);
749 }
750 }
751 }
752 _ => {
753 if let Some(v) = node.child_by_field_name(field) {
754 values.push(v);
755 }
756 }
757 }
758
759 for v in values {
760 let (name, anchor) = match v.kind() {
761 "identifier" => (self.text(v).to_string(), v),
762 // `self.handle_click` — object EXACTLY `self`; BARE attr name.
763 "attribute" => {
764 let obj = v.child_by_field_name("object");
765 let attr = v.child_by_field_name("attribute");
766 match (obj, attr) {

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

is_stoplistedFunction · 0.70
getMethod · 0.65
top_rowMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected