mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
refactor(treesitter): delegate region calculation to treesitter (#22576)
This commit is contained in:
@@ -64,6 +64,7 @@ static struct luaL_Reg tree_meta[] = {
|
||||
{ "__tostring", tree_tostring },
|
||||
{ "root", tree_root },
|
||||
{ "edit", tree_edit },
|
||||
{ "included_ranges", tree_get_ranges },
|
||||
{ "copy", tree_copy },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
@@ -512,6 +513,24 @@ static int tree_edit(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tree_get_ranges(lua_State *L)
|
||||
{
|
||||
TSTree **tree = tree_check(L, 1);
|
||||
if (!(*tree)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2);
|
||||
|
||||
uint32_t len;
|
||||
TSRange *ranges = ts_tree_included_ranges(*tree, &len);
|
||||
|
||||
push_ranges(L, ranges, len, include_bytes);
|
||||
|
||||
xfree(ranges);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Use the top of the stack (without popping it) to create a TSRange, it can be
|
||||
// either a lua table or a TSNode
|
||||
static void range_from_lua(lua_State *L, TSRange *range)
|
||||
|
Reference in New Issue
Block a user