extractCall — python `call` through the generic tail (attribute callees).
(&mut self, node: Node<'t>)
| 701 | |
| 702 | /// extractCall — python `call` through the generic tail (attribute callees). |
| 703 | fn extract_call(&mut self, node: Node<'t>) { |
| 704 | if self.stack.is_empty() { |
| 705 | return; |
| 706 | } |
| 707 | let func = node |
| 708 | .child_by_field_name("function") |
| 709 | .or_else(|| node.named_child(0)); |
| 710 | let mut callee_name = String::new(); |
| 711 | |
| 712 | if let Some(func) = func { |
| 713 | if func.kind() == "attribute" { |
| 714 | // `property` and `field` fields don't exist on attribute — |
| 715 | // the generic path falls back to namedChild(1) (the attr name). |
| 716 | let property = func |
| 717 | .child_by_field_name("property") |
| 718 | .or_else(|| func.child_by_field_name("field")) |
| 719 | .or_else(|| func.named_child(1)); |
| 720 | if let Some(property) = property { |
| 721 | let method_name = self.text(property); |
| 722 | let receiver = func |
| 723 | .child_by_field_name("object") |
| 724 | .or_else(|| func.child_by_field_name("operand")) |
| 725 | .or_else(|| func.child_by_field_name("argument")) |
| 726 | .or_else(|| func.named_child(0)); |
| 727 | if let Some(r) = receiver { |
| 728 | if is_literal_receiver(r.kind()) { |
| 729 | return; |
| 730 | } |
| 731 | } |
| 732 | let recv_ident = receiver.filter(|r| { |
| 733 | matches!(r.kind(), "identifier" | "simple_identifier" | "field_identifier") |
| 734 | }); |
| 735 | if let Some(r) = recv_ident { |
| 736 | let receiver_name = self.text(r); |
| 737 | if !matches!(receiver_name, "self" | "this" | "cls" | "super") { |
| 738 | callee_name = format!("{receiver_name}.{method_name}"); |
| 739 | } else { |
| 740 | callee_name = method_name.to_string(); |
| 741 | } |
| 742 | } else if let Some(r) = receiver.filter(|r| r.kind() == "call") { |
| 743 | // Call receiver — `d.setdefault(k, []).append(v)` (#1683): |
| 744 | // `<inner>().<method>`, or nothing when the inner callee |
| 745 | // is not a plain name / attribute chain. Mirrors |
| 746 | // TreeSitterExtractor.extractCall. |
| 747 | let Some(inner) = self.plain_inner_callee(r) else { return }; |
| 748 | callee_name = format!("{inner}().{method_name}"); |
| 749 | } else if let Some(r) = receiver { |
| 750 | // Any receiver shape the arms above do not claim — attribute |
| 751 | // chain (`self.data.append`) and subscript (`d[k].append`). |
| 752 | // The call-chain shape (`rows.setdefault(k, []).append(x)`) |
| 753 | // is taken by the `<inner>().<method>` arm above (#1748), |
| 754 | // which is matched first. |
| 755 | // These used to fall through to a BARE method_name. A bare name |
| 756 | // matching a common list/dict/str method (`append`, `get`, |
| 757 | // `update`, ...) exact-matches an unrelated top-level project |
| 758 | // function sharing that name, fabricating a call edge (#66, |
| 759 | // same class as #1230/#1276). Keep the receiver's source text |
| 760 | // as a qualifier so the ref can only resolve through |
no test coverage detected