Add ts_tree_root_node_with_offset API
This commit is contained in:
parent
a882d0b036
commit
477b667753
5 changed files with 71 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -366,6 +366,16 @@ void ts_tree_delete(TSTree *self);
|
|||
*/
|
||||
TSNode ts_tree_root_node(const TSTree *self);
|
||||
|
||||
/**
|
||||
* Get the root node of the syntax tree, but with its position
|
||||
* shifted forward by the given offset.
|
||||
*/
|
||||
TSNode ts_tree_root_node_with_offset(
|
||||
const TSTree *self,
|
||||
uint32_t offset_bytes,
|
||||
TSPoint offset_point
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the language that was used to parse the syntax tree.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "tree_sitter/api.h"
|
||||
#include "./array.h"
|
||||
#include "./get_changed_ranges.h"
|
||||
#include "./length.h"
|
||||
#include "./subtree.h"
|
||||
#include "./tree_cursor.h"
|
||||
#include "./tree.h"
|
||||
|
|
@ -37,6 +38,15 @@ TSNode ts_tree_root_node(const TSTree *self) {
|
|||
return ts_node_new(self, &self->root, ts_subtree_padding(self->root), 0);
|
||||
}
|
||||
|
||||
TSNode ts_tree_root_node_with_offset(
|
||||
const TSTree *self,
|
||||
uint32_t offset_bytes,
|
||||
TSPoint offset_extent
|
||||
) {
|
||||
Length offset = {offset_bytes, offset_extent};
|
||||
return ts_node_new(self, &self->root, length_add(offset, ts_subtree_padding(self->root)), 0);
|
||||
}
|
||||
|
||||
const TSLanguage *ts_tree_language(const TSTree *self) {
|
||||
return self->language;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue