From d5a69eb07648a515d03aa5c9e268aef852015ea9 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 22 Sep 2019 11:33:55 +0200 Subject: tree-sitter: handle node equality --- src/nvim/lua/treesitter.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/lua/treesitter.c') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index a71234d2c4..d2072402bb 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -48,6 +48,7 @@ static struct luaL_Reg tree_meta[] = { static struct luaL_Reg node_meta[] = { { "__tostring", node_tostring }, + { "__eq", node_eq }, { "__len", node_child_count }, { "range", node_range }, { "start", node_start }, @@ -431,6 +432,23 @@ static int node_tostring(lua_State *L) return 1; } +static int node_eq(lua_State *L) +{ + TSNode node; + if (!node_check(L, &node)) { + return 0; + } + // This should only be called if both x and y in "x == y" has the + // treesitter_node metatable. So it is ok to error out otherwise. + TSNode *ud = luaL_checkudata(L, 2, "treesitter_node"); + if (!ud) { + return 0; + } + TSNode node2 = *ud; + lua_pushboolean(L, ts_node_eq(node, node2)); + return 1; +} + static int node_range(lua_State *L) { TSNode node; -- cgit