Partially revert d4d5e29

This commit is contained in:
Samuel Moelius 2023-05-19 19:02:30 -04:00 committed by Andrew Hlynskyi
parent 144c096a27
commit 41ec8b4166
4 changed files with 22 additions and 17 deletions

View file

@ -4577,19 +4577,22 @@ fn test_query_max_start_depth() {
#[rustfmt::skip]
let rows = &[
Row {
description: "depth 0: match all",
description: "depth 0: match translation unit",
depth: 0,
pattern: r#"
(translation_unit) @capture
"#,
matches: &[
(0, &[("capture", "if (a1 && a2) {\n if (b1 && b2) { }\n if (c) { }\n}\nif (d) {\n if (e1 && e2) { }\n if (f) { }\n}\n")]),
]
},
Row {
description: "depth 0: match none",
depth: 0,
pattern: r#"
(if_statement) @capture
"#,
matches: &[
(0, &[("capture", "if (a1 && a2) {\n if (b1 && b2) { }\n if (c) { }\n}")]),
(0, &[("capture", "if (b1 && b2) { }")]),
(0, &[("capture", "if (c) { }")]),
(0, &[("capture", "if (d) {\n if (e1 && e2) { }\n if (f) { }\n}")]),
(0, &[("capture", "if (e1 && e2) { }")]),
(0, &[("capture", "if (f) { }")]),
]
matches: &[]
},
Row {
description: "depth 1: match 2 if statements at the top level",

View file

@ -639,7 +639,7 @@ extern "C" {
) -> bool;
}
extern "C" {
#[doc = " Set the maximum start depth for a cursor.\n\n This prevents cursors from exploring children nodes at a certain depth.\n Note if a pattern includes many children, then they will still be checked.\n\n Set to `0` to remove the maximum start depth."]
#[doc = " Set the maximum start depth for a query cursor.\n\n This prevents cursors from exploring children nodes at a certain depth.\n Note if a pattern includes many children, then they will still be checked.\n\n The zero max start depth value can be used as a special behavior and\n it helps to destructure a subtree by staying on a node and using captures\n for interested parts. Note that the zero max start depth only limit a search\n depth for a pattern's root node but other nodes that are parts of the pattern\n may be searched at any depth what defined by the pattern structure.\n\n Set to `UINT32_MAX` to remove the maximum start depth."]
pub fn ts_query_cursor_set_max_start_depth(arg1: *mut TSQueryCursor, arg2: u32);
}
extern "C" {

View file

@ -984,12 +984,18 @@ bool ts_query_cursor_next_capture(
);
/**
* Set the maximum start depth for a cursor.
* 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.
*
* Set to `0` to remove the maximum start depth.
* 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 `UINT32_MAX` to remove the maximum start depth.
*/
void ts_query_cursor_set_max_start_depth(TSQueryCursor *, uint32_t);

View file

@ -4124,11 +4124,7 @@ void ts_query_cursor_set_max_start_depth(
TSQueryCursor *self,
uint32_t max_start_depth
) {
if (max_start_depth == 0) {
self->max_start_depth = UINT32_MAX;
} else {
self->max_start_depth = max_start_depth;
}
self->max_start_depth = max_start_depth;
}
#undef LOG