diff --git a/src/main.rs b/src/main.rs index d1d4c83..ff51686 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,9 +168,8 @@ fn handle_request(config: &Config, request: &Request) -> String { Some(kind) => { let kinds = filetype_config.resolve_alias(kind); for range in &ranges { - for node in tree::nodes_in_range(tree.root_node(), range) { - select_nodes(&node, &kinds, &mut new_ranges); - } + let node = tree::shrink_to_range(tree.root_node(), range); + select_nodes(&node, &kinds, &mut new_ranges); } } None => { diff --git a/src/tree.rs b/src/tree.rs index e7ffbc7..7bcf0c1 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -22,47 +22,6 @@ pub fn shrink_to_range<'a>(root_node: Node<'a>, range: &Range) -> Node<'a> { } } -pub fn nodes_in_range<'a>(root_node: Node<'a>, range: &Range) -> Vec> { - let mut nodes = Vec::new(); - let node = shrink_to_range(root_node, range); - if node.range().start_byte >= range.start_byte && range.end_byte >= node.range().end_byte { - nodes.push(node); - return nodes; - } - let mut cursor = node.walk(); - for child in node.children(&mut cursor) { - if child.range().start_byte <= range.start_byte && range.end_byte >= child.range().end_byte - { - nodes.extend(nodes_in_range( - child, - &Range { - start_byte: range.start_byte, - start_point: range.start_point, - end_byte: child.range().end_byte, - end_point: child.range().end_point, - }, - )); - } else if child.range().start_byte >= range.start_byte - && range.end_byte <= child.range().end_byte - { - nodes.extend(nodes_in_range( - child, - &Range { - start_byte: child.range().start_byte, - start_point: child.range().start_point, - end_byte: range.end_byte, - end_point: range.end_point, - }, - )); - } else if child.range().start_byte >= range.start_byte - && range.end_byte >= child.range().end_byte - { - nodes.push(child); - } - } - nodes -} - fn highest_node_of_same_range<'a>(current_node: Node<'a>) -> Node<'a> { let start_byte = current_node.start_byte(); let end_byte = current_node.end_byte();