Add APIs for retrieving tree cursor's depth and descendant index
This commit is contained in:
parent
9dd725b4e3
commit
a2119cb691
6 changed files with 47 additions and 28 deletions
|
|
@ -615,7 +615,12 @@ extern "C" {
|
|||
extern "C" {
|
||||
#[doc = " Get the index of the cursor's current node out of all of the"]
|
||||
#[doc = " descendants of the original node that the cursor was constructed with."]
|
||||
pub fn ts_tree_cursor_descendant_index(arg1: *mut TSTreeCursor) -> u32;
|
||||
pub fn ts_tree_cursor_current_descendant_index(arg1: *const TSTreeCursor) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Get the depth of the cursor's current node relative to the original"]
|
||||
#[doc = " node that the cursor was constructed with."]
|
||||
pub fn ts_tree_cursor_current_depth(arg1: *const TSTreeCursor) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Move the cursor to the first child of its current node that extends beyond"]
|
||||
|
|
|
|||
|
|
@ -1266,6 +1266,21 @@ impl<'a> TreeCursor<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the numerical field id of this tree cursor's current node.
|
||||
///
|
||||
/// See also [field_name](TreeCursor::field_name).
|
||||
#[doc(alias = "ts_tree_cursor_current_depth")]
|
||||
pub fn depth(&self) -> u32 {
|
||||
unsafe { ffi::ts_tree_cursor_current_depth(&self.0) }
|
||||
}
|
||||
|
||||
/// Get the index of the cursor's current node out of all of the
|
||||
/// descendants of the original node that the cursor was constructed with
|
||||
#[doc(alias = "ts_tree_cursor_current_descendant_index")]
|
||||
pub fn descendant_index(&self) -> usize {
|
||||
unsafe { ffi::ts_tree_cursor_current_descendant_index(&self.0) as usize }
|
||||
}
|
||||
|
||||
/// Move this cursor to the first child of its current node.
|
||||
///
|
||||
/// This returns `true` if the cursor successfully moved, and returns `false`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue