Add ts_tree_root_node_with_offset API

This commit is contained in:
Max Brunsfeld 2022-08-18 13:48:47 -07:00
parent a882d0b036
commit 477b667753
5 changed files with 71 additions and 0 deletions

View file

@ -332,6 +332,15 @@ extern "C" {
#[doc = " Get the root node of the syntax tree."]
pub fn ts_tree_root_node(self_: *const TSTree) -> TSNode;
}
extern "C" {
#[doc = " Get the root node of the syntax tree, but with its position"]
#[doc = " shifted forward by the given offset."]
pub fn ts_tree_root_node_with_offset(
self_: *const TSTree,
offset_bytes: u32,
offset_point: TSPoint,
) -> TSNode;
}
extern "C" {
#[doc = " Get the language that was used to parse the syntax tree."]
pub fn ts_tree_language(arg1: *const TSTree) -> *const TSLanguage;

View file

@ -708,6 +708,20 @@ impl Tree {
Node::new(unsafe { ffi::ts_tree_root_node(self.0.as_ptr()) }).unwrap()
}
/// Get the root node of the syntax tree, but with its position shifted
/// forward by the given offset.
#[doc(alias = "ts_tree_root_node_with_offset")]
pub fn root_node_with_offset(&self, offset_bytes: usize, offset_extent: Point) -> Node {
Node::new(unsafe {
ffi::ts_tree_root_node_with_offset(
self.0.as_ptr(),
offset_bytes as u32,
offset_extent.into(),
)
})
.unwrap()
}
/// Get the language that was used to parse the syntax tree.
#[doc(alias = "ts_tree_language")]
pub fn language(&self) -> Language {