fn _match_ancestor()

in src/models/filter.rs [412:434]


  fn _match_ancestor(
    &self, rule_store: &mut RuleStore, node: Node, ts_query: &CGPattern,
  ) -> Option<Node> {
    let mut current_node = node;
    // This ensures that the below while loop considers the current node too when checking for filters.
    if current_node.child_count() > 0 {
      current_node = current_node.child(0).unwrap();
    }

    while let Some(parent) = current_node.parent() {
      let pattern = rule_store.query(ts_query);
      if let Some(p_match) = pattern.get_match(&parent, self.code(), false) {
        let matched_ancestor = get_node_for_range(
          self.root_node(),
          *p_match.range().start_byte(),
          *p_match.range().end_byte(),
        );
        return Some(matched_ancestor);
      }
      current_node = parent;
    }
    None
  }