Add tree included ranges getter
Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
fb5fbdd787
commit
1848d0bc36
4 changed files with 21 additions and 0 deletions
|
|
@ -345,6 +345,9 @@ extern "C" {
|
|||
#[doc = " Get the language that was used to parse the syntax tree."]
|
||||
pub fn ts_tree_language(arg1: *const TSTree) -> *const TSLanguage;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_included_ranges(arg1: *const TSTree, length: *mut u32) -> *mut TSRange;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Edit the syntax tree to keep it in sync with source code that has been"]
|
||||
#[doc = " edited."]
|
||||
|
|
|
|||
|
|
@ -763,6 +763,15 @@ impl Tree {
|
|||
util::CBufferIter::new(ptr, count as usize).map(|r| r.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn included_ranges(&self) -> Vec<Range> {
|
||||
let mut count = 0u32;
|
||||
unsafe {
|
||||
let ptr = ffi::ts_tree_included_ranges(self.0.as_ptr(), &mut count as *mut u32);
|
||||
let ranges = Vec::from_raw_parts(ptr, count as usize, count as usize);
|
||||
ranges.into_iter().map(|range| range.into()).collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Tree {
|
||||
|
|
|
|||
|
|
@ -381,6 +381,8 @@ TSNode ts_tree_root_node_with_offset(
|
|||
*/
|
||||
const TSLanguage *ts_tree_language(const TSTree *);
|
||||
|
||||
TSRange *ts_tree_included_ranges(const TSTree *, uint32_t *length);
|
||||
|
||||
/**
|
||||
* Edit the syntax tree to keep it in sync with source code that has been
|
||||
* edited.
|
||||
|
|
|
|||
|
|
@ -85,6 +85,13 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
|
|||
ts_subtree_pool_delete(&pool);
|
||||
}
|
||||
|
||||
TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length) {
|
||||
*length = self->included_range_count;
|
||||
TSRange *ranges = ts_calloc(self->included_range_count, sizeof(TSRange));
|
||||
memcpy(ranges, self->included_ranges, self->included_range_count * sizeof(TSRange));
|
||||
return ranges;
|
||||
}
|
||||
|
||||
TSRange *ts_tree_get_changed_ranges(const TSTree *self, const TSTree *other, uint32_t *count) {
|
||||
TreeCursor cursor1 = {NULL, array_new()};
|
||||
TreeCursor cursor2 = {NULL, array_new()};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue