aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/treesitter.c
diff options
context:
space:
mode:
authorQuentin Rasmont <qrasmont@gmail.com>2022-05-01 21:13:47 +0200
committerbfredl <bjorn.linse@gmail.com>2022-08-25 18:01:14 +0200
commitf57341a4b69398ff0c58686e66c2f4138be164aa (patch)
tree4a017d046bab5680933b9499f9c831dfd42cebd6 /src/nvim/lua/treesitter.c
parentbaba43681e792db30318bdedc3e73e4fe12482a6 (diff)
downloadrneovim-f57341a4b69398ff0c58686e66c2f4138be164aa.tar.gz
rneovim-f57341a4b69398ff0c58686e66c2f4138be164aa.tar.bz2
rneovim-f57341a4b69398ff0c58686e66c2f4138be164aa.zip
feat(treesitter): upstream node_length() as a node method
Util from the nvim-treesitter project.
Diffstat (limited to 'src/nvim/lua/treesitter.c')
-rw-r--r--src/nvim/lua/treesitter.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index 083042ad98..8803fd452c 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -90,6 +90,7 @@ static struct luaL_Reg node_meta[] = {
{ "prev_named_sibling", node_prev_named_sibling },
{ "named_children", node_named_children },
{ "root", node_root },
+ { "byte_length", node_byte_length },
{ NULL, NULL }
};
@@ -1111,6 +1112,20 @@ static int node_root(lua_State *L)
return 1;
}
+static int node_byte_length(lua_State *L)
+{
+ TSNode node;
+ if (!node_check(L, 1, &node)) {
+ return 0;
+ }
+
+ uint32_t start_byte = ts_node_start_byte(node);
+ uint32_t end_byte = ts_node_end_byte(node);
+
+ lua_pushnumber(L, end_byte - start_byte);
+ return 1;
+}
+
/// assumes the match table being on top of the stack
static void set_match(lua_State *L, TSQueryMatch *match, int nodeidx)
{