Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
StratusFearMe21 committed Oct 7, 2024
1 parent f55f1f8 commit 2c6fd1e
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 134 deletions.
186 changes: 98 additions & 88 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ package.helix-tui.opt-level = 2
package.helix-term.opt-level = 2

[workspace.dependencies]
tree-sitter = { version = "0.22" }
tree-sitter = { version = "0.24" }
nucleo = "0.5.0"
slotmap = "1.0.7"
thiserror = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion helix-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ unicode-segmentation = "1.12"
# width definitions in terminals, we need to replace it.
# For now lets lock the version to avoid rendering glitches
# when installing without `--locked`
unicode-width = "=0.1.12"
unicode-width = "=0.2.0"
unicode-general-category = "0.6"
slotmap.workspace = true
tree-sitter.workspace = true
Expand Down Expand Up @@ -58,6 +58,7 @@ textwrap = "0.16.1"
nucleo.workspace = true
parking_lot = "0.12"
globset = "0.4.15"
streaming-iterator = "0.1.9"

[dev-dependencies]
quickcheck = { version = "1", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion helix-core/src/indent.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{borrow::Cow, collections::HashMap};

use helix_stdx::rope::RopeSliceExt;
use streaming_iterator::StreamingIterator;
use tree_sitter::{Query, QueryCursor, QueryPredicateArg};

use crate::{
Expand Down Expand Up @@ -452,8 +453,9 @@ fn query_indents<'a>(
let mut extend_captures: HashMap<usize, Vec<ExtendCapture>> = HashMap::new();
cursor.set_byte_range(range);

let mut captures = cursor.matches(query, syntax.tree().root_node(), RopeProvider(text));
// Iterate over all captures from the query
for m in cursor.matches(query, syntax.tree().root_node(), RopeProvider(text)) {
while let Some(m) = captures.next() {
// Skip matches where not all custom predicates are fulfilled
if !query.general_predicates(m.pattern_index).iter().all(|pred| {
match pred.operator.as_ref() {
Expand Down
11 changes: 7 additions & 4 deletions helix-core/src/movement.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{cmp::Reverse, iter};

use ropey::iter::Chars;
use streaming_iterator::StreamingIterator;
use tree_sitter::{Node, QueryCursor};

use crate::{
Expand Down Expand Up @@ -588,15 +589,17 @@ pub fn goto_treesitter_object(
let node = match dir {
Direction::Forward => nodes
.filter(|n| n.start_byte() > byte_pos)
.min_by_key(|n| (n.start_byte(), Reverse(n.end_byte())))?,
.map_deref(|c| c.byte_range())
.min_by_key(|n| (n.start, Reverse(n.end)))?,
Direction::Backward => nodes
.filter(|n| n.end_byte() < byte_pos)
.max_by_key(|n| (n.end_byte(), Reverse(n.start_byte())))?,
.map_deref(|c| c.byte_range())
.max_by_key(|n| (n.end, Reverse(n.start)))?,
};

let len = slice.len_bytes();
let start_byte = node.start_byte();
let end_byte = node.end_byte();
let start_byte = node.start;
let end_byte = node.end;
if start_byte >= len || end_byte >= len {
return None;
}
Expand Down
64 changes: 29 additions & 35 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use globset::GlobSet;
use hashbrown::raw::RawTable;
use helix_stdx::rope::{self, RopeSliceExt};
use slotmap::{DefaultKey as LayerId, HopSlotMap};
use streaming_iterator::StreamingIterator;

use std::{
borrow::Cow,
Expand Down Expand Up @@ -679,7 +680,7 @@ impl TextObjectQuery {
node: Node<'a>,
slice: RopeSlice<'a>,
cursor: &'a mut QueryCursor,
) -> Option<impl Iterator<Item = CapturedNode<'a>>> {
) -> Option<impl StreamingIterator<Item = CapturedNode<'a>>> {
self.capture_nodes_any(&[capture_name], node, slice, cursor)
}

Expand All @@ -691,7 +692,7 @@ impl TextObjectQuery {
node: Node<'a>,
slice: RopeSlice<'a>,
cursor: &'a mut QueryCursor,
) -> Option<impl Iterator<Item = CapturedNode<'a>>> {
) -> Option<impl StreamingIterator<Item = CapturedNode<'a>>> {
let capture_idx = capture_names
.iter()
.find_map(|cap| self.query.capture_index_for_name(cap))?;
Expand Down Expand Up @@ -1288,7 +1289,7 @@ impl Syntax {
let layer = &self.layers[layer_id];

// Process injections.
let matches = cursor.matches(
let mut matches = cursor.matches(
&layer.config.injections_query,
layer.tree().root_node(),
RopeProvider(source_slice),
Expand All @@ -1299,10 +1300,10 @@ impl Syntax {
];
let mut injections = Vec::new();
let mut last_injection_end = 0;
for mat in matches {
while let Some(mat) = matches.next() {
let (injection_capture, content_node, included_children) = layer
.config
.injection_for_match(&layer.config.injections_query, &mat, source_slice);
.injection_for_match(&layer.config.injections_query, mat, source_slice);

// in case this is a combined injection save it for more processing later
if let Some(combined_injection_idx) = layer
Expand Down Expand Up @@ -1441,16 +1442,15 @@ impl Syntax {
cursor_ref.set_byte_range(range.clone().unwrap_or(0..usize::MAX));
cursor_ref.set_match_limit(TREE_SITTER_MATCH_LIMIT);

let mut captures = cursor_ref
.captures(
&layer.config.query,
layer.tree().root_node(),
RopeProvider(source),
)
.peekable();
let mut captures = cursor_ref.captures(
&layer.config.query,
layer.tree().root_node(),
RopeProvider(source),
);

// If there's no captures, skip the layer
captures.peek()?;
captures.advance();
captures.get()?;

Some(HighlightIterLayer {
highlight_end_stack: Vec::new(),
Expand Down Expand Up @@ -1740,7 +1740,7 @@ pub(crate) fn generate_edits(
}

use std::sync::atomic::{AtomicUsize, Ordering};
use std::{iter, mem, ops, str};
use std::{mem, ops, str};
use tree_sitter::{
Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
QueryMatch, Range, TextProvider, Tree,
Expand Down Expand Up @@ -1842,7 +1842,7 @@ impl<'a> TextProvider<&'a [u8]> for RopeProvider<'a> {
struct HighlightIterLayer<'a> {
_tree: Option<Tree>,
cursor: QueryCursor,
captures: RefCell<iter::Peekable<QueryCaptures<'a, 'a, RopeProvider<'a>, &'a [u8]>>>,
captures: RefCell<QueryCaptures<'a, 'a, RopeProvider<'a>, &'a [u8]>>,
config: &'a HighlightConfiguration,
highlight_end_stack: Vec<usize>,
scope_stack: Vec<LocalScope<'a>>,
Expand Down Expand Up @@ -2115,7 +2115,7 @@ impl<'a> HighlightIterLayer<'a> {
let next_start = self
.captures
.borrow_mut()
.peek()
.get()
.map(|(m, i)| m.captures[*i].node.start_byte());
let next_end = self.highlight_end_stack.last().cloned();
match (next_start, next_end) {
Expand Down Expand Up @@ -2340,7 +2340,7 @@ impl<'a> Iterator for HighlightIter<'a> {
let range;
let layer = &mut self.layers[0];
let captures = layer.captures.get_mut();
if let Some((next_match, capture_index)) = captures.peek() {
if let Some((next_match, capture_index)) = captures.get() {
let next_capture = next_match.captures[*capture_index];
range = next_capture.node.byte_range();

Expand All @@ -2363,7 +2363,7 @@ impl<'a> Iterator for HighlightIter<'a> {
return self.emit_event(self.source.len_bytes(), None);
};

let (mut match_, capture_index) = captures.next().unwrap();
let (mut match_, capture_index) = captures.get().map(|m| (&m.0, m.1)).unwrap();
let mut capture = match_.captures[capture_index];

// Remove from the local scope stack any local scopes that have already ended.
Expand Down Expand Up @@ -2439,11 +2439,11 @@ impl<'a> Iterator for HighlightIter<'a> {
}

// Continue processing any additional matches for the same node.
if let Some((next_match, next_capture_index)) = captures.peek() {
if let Some((next_match, next_capture_index)) = captures.get() {
let next_capture = next_match.captures[*next_capture_index];
if next_capture.node == capture.node {
capture = next_capture;
match_ = captures.next().unwrap().0;
match_ = &captures.next().unwrap().0;
continue;
}
}
Expand All @@ -2467,11 +2467,11 @@ impl<'a> Iterator for HighlightIter<'a> {
if definition_highlight.is_some() || reference_highlight.is_some() {
while layer.config.non_local_variable_patterns[match_.pattern_index] {
match_.remove();
if let Some((next_match, next_capture_index)) = captures.peek() {
if let Some((next_match, next_capture_index)) = captures.get() {
let next_capture = next_match.captures[*next_capture_index];
if next_capture.node == capture.node {
capture = next_capture;
match_ = captures.next().unwrap().0;
match_ = &captures.next().unwrap().0;
continue;
}
}
Expand All @@ -2486,10 +2486,10 @@ impl<'a> Iterator for HighlightIter<'a> {
// for a given node are ordered by pattern index, so these subsequent
// captures are guaranteed to be for highlighting, not injections or
// local variables.
while let Some((next_match, next_capture_index)) = captures.peek() {
while let Some((next_match, next_capture_index)) = captures.get() {
let next_capture = next_match.captures[*next_capture_index];
if next_capture.node == capture.node {
captures.next();
captures.advance();
} else {
break;
}
Expand Down Expand Up @@ -2763,18 +2763,12 @@ mod test {

let root = syntax.tree().root_node();
let mut test = |capture, range| {
let matches: Vec<_> = textobject
let captures = textobject
.capture_nodes(capture, root, source.slice(..), &mut cursor)
.unwrap()
.collect();

assert_eq!(
matches[0].byte_range(),
range,
"@{} expected {:?}",
capture,
range
)
.unwrap();
let matches: Vec<_> = captures.map_deref(|c| c.byte_range()).collect();

assert_eq!(matches[0], range, "@{} expected {:?}", capture, range)
};

test("quantified_nodes", 1..37);
Expand Down
8 changes: 5 additions & 3 deletions helix-core/src/textobject.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use ropey::RopeSlice;
use streaming_iterator::StreamingIterator;
use tree_sitter::{Node, QueryCursor};

use crate::chars::{categorize_char, char_is_whitespace, CharCategory};
Expand Down Expand Up @@ -273,11 +274,12 @@ pub fn textobject_treesitter(
.textobject_query()?
.capture_nodes(&capture_name, slice_tree, slice, &mut cursor)?
.filter(|node| node.byte_range().contains(&byte_pos))
.min_by_key(|node| node.byte_range().len())?;
.map_deref(|n| n.byte_range())
.min_by_key(|node_range| node_range.len())?;

let len = slice.len_bytes();
let start_byte = node.start_byte();
let end_byte = node.end_byte();
let start_byte = node.start;
let end_byte = node.end;
if start_byte >= len || end_byte >= len {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.74.0"
channel = "1.74.1"
components = ["rustfmt", "rust-src", "clippy"]

0 comments on commit 2c6fd1e

Please sign in to comment.