Return the leftmost identifier-like child of a call node, treating `field_expression` / `member_expression` as a chain (returns the rightmost field of the leftmost chain — i.e. the called method).
(node: Node<'_>, source: &[u8])
| 288 | /// `field_expression` / `member_expression` as a chain (returns the |
| 289 | /// rightmost field of the leftmost chain — i.e. the called method). |
| 290 | fn leftmost_callable_name(node: Node<'_>, source: &[u8]) -> Option<String> { |
| 291 | let mut cursor = node.walk(); |
| 292 | if !cursor.goto_first_child() { |
| 293 | return None; |
| 294 | } |
| 295 | loop { |
| 296 | let child = cursor.node(); |
| 297 | let kind = child.kind(); |
| 298 | if kind == "identifier" |
| 299 | || kind == "field_identifier" |
| 300 | || kind == "property_identifier" |
| 301 | || kind == "scoped_identifier" |
| 302 | { |
| 303 | return child.utf8_text(source).ok().map(str::to_string); |
| 304 | } |
| 305 | if kind.contains("field_expression") |
| 306 | || kind.contains("member_expression") |
| 307 | || kind.contains("scoped") |
| 308 | { |
| 309 | let mut inner = child.walk(); |
| 310 | if inner.goto_first_child() { |
| 311 | let mut last_id: Option<String> = None; |
| 312 | loop { |
| 313 | let ic = inner.node(); |
| 314 | let ik = ic.kind(); |
| 315 | if ik.contains("identifier") { |
| 316 | if let Ok(t) = ic.utf8_text(source) { |
| 317 | last_id = Some(t.to_string()); |
| 318 | } |
| 319 | } |
| 320 | if !inner.goto_next_sibling() { |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | if last_id.is_some() { |
| 325 | return last_id; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | if !cursor.goto_next_sibling() { |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | None |
| 334 | } |
| 335 | |
| 336 | // --------------------------------------------------------------------------- |
| 337 | // Shingles + Jaccard |
no test coverage detected