Change select-children to not use nodes_in_range

This commit is contained in:
xenia 2023-11-12 22:17:04 +01:00
parent 05319779a3
commit 374910704d
2 changed files with 2 additions and 44 deletions

View File

@ -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 => {

View File

@ -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<Node<'a>> {
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();