Preserve matches that contain the QueryCursor's start byte

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Max Brunsfeld 2021-05-25 13:06:24 -07:00
parent a61f25bc58
commit f597cc6a75
5 changed files with 214 additions and 171 deletions

View file

@ -737,18 +737,8 @@ extern "C" {
pub fn ts_query_cursor_did_exceed_match_limit(arg1: *const TSQueryCursor) -> bool;
}
extern "C" {
#[doc = " Get or set the range of bytes or (row, column) positions in which the query"]
#[doc = " Set the range of bytes or (row, column) positions in which the query"]
#[doc = " will be executed."]
pub fn ts_query_cursor_byte_range(arg1: *const TSQueryCursor, arg2: *mut u32, arg3: *mut u32);
}
extern "C" {
pub fn ts_query_cursor_point_range(
arg1: *const TSQueryCursor,
arg2: *mut TSPoint,
arg3: *mut TSPoint,
);
}
extern "C" {
pub fn ts_query_cursor_set_byte_range(arg1: *mut TSQueryCursor, arg2: u32, arg3: u32);
}
extern "C" {
@ -764,6 +754,9 @@ extern "C" {
extern "C" {
pub fn ts_query_cursor_remove_match(arg1: *mut TSQueryCursor, id: u32);
}
extern "C" {
pub fn ts_query_cursor_advance_to_byte(arg1: *mut TSQueryCursor, offset: u32);
}
extern "C" {
#[doc = " Advance to the next capture of the currently running query."]
#[doc = ""]

View file

@ -1812,27 +1812,7 @@ impl<'a, 'tree, T: TextProvider<'a>> Iterator for QueryMatches<'a, 'tree, T> {
impl<'a, 'tree, T: TextProvider<'a>> QueryCaptures<'a, 'tree, T> {
pub fn advance_to_byte(&mut self, offset: usize) {
unsafe {
let mut current_start = 0u32;
let mut current_end = 0u32;
ffi::ts_query_cursor_byte_range(
self.ptr,
&mut current_start as *mut u32,
&mut current_end as *mut u32,
);
ffi::ts_query_cursor_set_byte_range(self.ptr, offset as u32, current_end);
}
}
pub fn advance_to_point(&mut self, point: Point) {
unsafe {
let mut current_start = ffi::TSPoint { row: 0, column: 0 };
let mut current_end = current_start;
ffi::ts_query_cursor_point_range(
self.ptr,
&mut current_start as *mut _,
&mut current_end as *mut _,
);
ffi::ts_query_cursor_set_point_range(self.ptr, point.into(), current_end);
ffi::ts_query_cursor_advance_to_byte(self.ptr, offset as u32);
}
}
}