extractCall — the rust paths of the generic else-branch (4312+).
(&mut self, node: Node<'t>)
| 885 | |
| 886 | /// extractCall — the rust paths of the generic else-branch (4312+). |
| 887 | fn extract_call(&mut self, node: Node<'t>) { |
| 888 | if self.stack.is_empty() { |
| 889 | return; |
| 890 | } |
| 891 | let func = node |
| 892 | .child_by_field_name("function") |
| 893 | .or_else(|| node.named_child(0)); |
| 894 | // A turbofish — `s.get::<u32>()`, `helper::<u8>()`, |
| 895 | // `Store::with_capacity::<u8>(1)` — calls the function it wraps: its |
| 896 | // type arguments are no part of the callee's name. Mirrors |
| 897 | // TreeSitterExtractor.extractCall. |
| 898 | let func = func.map(unwrap_generic_function); |
| 899 | let mut callee_name = String::new(); |
| 900 | |
| 901 | if let Some(func) = func { |
| 902 | if func.kind() == "field_expression" { |
| 903 | let property = func |
| 904 | .child_by_field_name("property") |
| 905 | .or_else(|| func.child_by_field_name("field")) |
| 906 | .or_else(|| func.named_child(1)); |
| 907 | if let Some(property) = property { |
| 908 | let method_name = self.text(property); |
| 909 | let receiver = func |
| 910 | .child_by_field_name("object") |
| 911 | .or_else(|| func.child_by_field_name("operand")) |
| 912 | .or_else(|| func.child_by_field_name("argument")) |
| 913 | .or_else(|| func.named_child(0)); |
| 914 | if let Some(r) = receiver { |
| 915 | if is_literal_receiver(r.kind()) { |
| 916 | return; // emit NOTHING (#1230) |
| 917 | } |
| 918 | } |
| 919 | if let Some(r) = receiver { |
| 920 | match r.kind() { |
| 921 | // rust `self` is node kind `self`, NOT `identifier` — |
| 922 | // it dodges this branch and falls to the bare-name |
| 923 | // fallthrough (same net effect as SKIP_RECEIVERS). |
| 924 | "identifier" | "simple_identifier" | "field_identifier" => { |
| 925 | let receiver_name = self.text(r); |
| 926 | if !matches!(receiver_name, "self" | "this" | "cls" | "super") { |
| 927 | callee_name = format!("{receiver_name}.{method_name}"); |
| 928 | } else { |
| 929 | callee_name = method_name.to_string(); |
| 930 | } |
| 931 | } |
| 932 | "call_expression" => { |
| 933 | // Chained-call re-encode: an associated- |
| 934 | // function chain (`Foo::new().bar()`, inner |
| 935 | // callee a scoped_identifier). A chain of |
| 936 | // fields and method calls on `self` or a name |
| 937 | // (`self.store().put()`, #2836) keeps that |
| 938 | // chain; any other instance chain the bare |
| 939 | // method name. |
| 940 | let inner_fn = r.child_by_field_name("function").map(unwrap_generic_function); |
| 941 | let reencode = |
| 942 | inner_fn.map(|f| f.kind() == "scoped_identifier").unwrap_or(false); |
| 943 | if reencode { |
| 944 | let inner: String = self |
no test coverage detected