binding_rust: set_max_start_depth accepts optional to reset limit
This commit is contained in:
parent
7b01d8ee05
commit
485d192880
2 changed files with 19 additions and 4 deletions
|
|
@ -4648,7 +4648,7 @@ fn test_query_max_start_depth() {
|
|||
eprintln!(" query example: {:?}", row.description);
|
||||
|
||||
let query = Query::new(language, row.pattern).unwrap();
|
||||
cursor.set_max_start_depth(row.depth);
|
||||
cursor.set_max_start_depth(Some(row.depth));
|
||||
|
||||
let matches = cursor.matches(&query, tree.root_node(), source.as_bytes());
|
||||
let expected = row
|
||||
|
|
@ -4782,7 +4782,7 @@ fn test_query_max_start_depth_more() {
|
|||
for row in rows.iter() {
|
||||
eprintln!(" depth: {}", row.depth);
|
||||
|
||||
cursor.set_max_start_depth(row.depth);
|
||||
cursor.set_max_start_depth(Some(row.depth));
|
||||
|
||||
let matches = cursor.matches(&query, node, source.as_bytes());
|
||||
let expected = row
|
||||
|
|
|
|||
|
|
@ -2174,10 +2174,25 @@ impl QueryCursor {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set the maximum start depth for a query cursor.
|
||||
///
|
||||
/// This prevents cursors from exploring children nodes at a certain depth.
|
||||
/// Note if a pattern includes many children, then they will still be checked.
|
||||
///
|
||||
/// The zero max start depth value can be used as a special behavior and
|
||||
/// it helps to destructure a subtree by staying on a node and using captures
|
||||
/// for interested parts. Note that the zero max start depth only limit a search
|
||||
/// depth for a pattern's root node but other nodes that are parts of the pattern
|
||||
/// may be searched at any depth what defined by the pattern structure.
|
||||
///
|
||||
/// Set to `None` to remove the maximum start depth.
|
||||
#[doc(alias = "ts_query_cursor_set_max_start_depth")]
|
||||
pub fn set_max_start_depth(&mut self, max_start_depth: u32) -> &mut Self {
|
||||
pub fn set_max_start_depth(&mut self, max_start_depth: Option<u32>) -> &mut Self {
|
||||
unsafe {
|
||||
ffi::ts_query_cursor_set_max_start_depth(self.ptr.as_ptr(), max_start_depth);
|
||||
ffi::ts_query_cursor_set_max_start_depth(
|
||||
self.ptr.as_ptr(),
|
||||
max_start_depth.unwrap_or(u32::MAX),
|
||||
);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue