The visitNode hook (scala.ts:131-198). Returns true when consumed.
(&mut self, node: Node<'t>)
| 601 | |
| 602 | /// The visitNode hook (scala.ts:131-198). Returns true when consumed. |
| 603 | fn hook(&mut self, node: Node<'t>) -> bool { |
| 604 | stack_guard!(); |
| 605 | match node.kind() { |
| 606 | "val_definition" | "var_definition" => { |
| 607 | let is_val = node.kind() == "val_definition"; |
| 608 | let name = match self.val_var_name(node) { |
| 609 | Some(n) => n.to_string(), |
| 610 | None => return false, |
| 611 | }; |
| 612 | // Enclosing-definition NODE-TYPE walk (scala.ts:146-156). |
| 613 | let mut enclosing: Option<&'static str> = None; |
| 614 | let mut p = node.parent(); |
| 615 | while let Some(parent) = p { |
| 616 | match parent.kind() { |
| 617 | "class_definition" => { |
| 618 | enclosing = Some("class_definition"); |
| 619 | break; |
| 620 | } |
| 621 | "trait_definition" => { |
| 622 | enclosing = Some("trait_definition"); |
| 623 | break; |
| 624 | } |
| 625 | "enum_definition" => { |
| 626 | enclosing = Some("enum_definition"); |
| 627 | break; |
| 628 | } |
| 629 | "given_definition" => { |
| 630 | enclosing = Some("given_definition"); |
| 631 | break; |
| 632 | } |
| 633 | "object_definition" => { |
| 634 | enclosing = Some("object_definition"); |
| 635 | break; |
| 636 | } |
| 637 | _ => p = parent.parent(), |
| 638 | } |
| 639 | } |
| 640 | let is_instance_field = matches!( |
| 641 | enclosing, |
| 642 | Some("class_definition") | Some("trait_definition") | Some("enum_definition") |
| 643 | | Some("given_definition") |
| 644 | ); |
| 645 | let kind: &'static str = if is_instance_field { |
| 646 | "field" |
| 647 | } else if is_val { |
| 648 | "constant" |
| 649 | } else { |
| 650 | "variable" |
| 651 | }; |
| 652 | let type_node = node.child_by_field_name("type"); |
| 653 | let signature = type_node.map(|t| { |
| 654 | format!("{} {}: {}", if is_val { "val" } else { "var" }, name, self.text(t)) |
| 655 | }); |
| 656 | let visibility = self.visibility_of(node); |
| 657 | let created = self.create_node( |
| 658 | kind, |
| 659 | &name, |
| 660 | node, |
no test coverage detected