Extract the simple function name from the callee sub-node of a `call_expression`. Returns `None` for call targets we cannot name simply (closures, raw pointers, etc.).
(&self, func_node: &Node, source: &str)
| 541 | /// |
| 542 | /// Returns `None` for call targets we cannot name simply (closures, raw pointers, etc.). |
| 543 | fn extract_call_name(&self, func_node: &Node, source: &str) -> Option<String> { |
| 544 | match func_node.kind() { |
| 545 | "identifier" => { |
| 546 | let name = self.node_text(func_node, source); |
| 547 | if name.is_empty() { |
| 548 | None |
| 549 | } else { |
| 550 | Some(name) |
| 551 | } |
| 552 | } |
| 553 | "field_expression" => { |
| 554 | // self.method() or obj.method() — extract just "method" |
| 555 | func_node |
| 556 | .child_by_field_name("field") |
| 557 | .map(|f| self.node_text(&f, source)) |
| 558 | .filter(|s| !s.is_empty()) |
| 559 | } |
| 560 | "scoped_identifier" => { |
| 561 | // Module::func() — extract just "func" |
| 562 | func_node |
| 563 | .child_by_field_name("name") |
| 564 | .map(|n| self.node_text(&n, source)) |
| 565 | .filter(|s| !s.is_empty()) |
| 566 | } |
| 567 | "generic_function" => { |
| 568 | // func::<T>() — recurse into the inner function node |
| 569 | func_node |
| 570 | .child_by_field_name("function") |
| 571 | .as_ref() |
| 572 | .and_then(|f| self.extract_call_name(f, source)) |
| 573 | } |
| 574 | _ => None, |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | impl Default for RustParser { |
no test coverage detected