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