From 374910704dfe50ab9ed17cfd90d65c6d89b6bed3 Mon Sep 17 00:00:00 2001 From: xenia Date: Sun, 12 Nov 2023 22:17:04 +0100 Subject: [PATCH] Change select-children to not use nodes_in_range --- src/main.rs | 5 ++--- src/tree.rs | 41 ----------------------------------------- 2 files changed, 2 insertions(+), 44 deletions(-) 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();