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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

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

Tested by

no test coverage detected