aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2025-02-15 13:33:38 -0800
committerLewis Russell <me@lewisr.dev>2025-02-21 09:47:02 +0000
commit55b165ac15a7528a3c679d928b1edf9d701f850b (patch)
tree17c86f717b79a42e87cd9c58a031b0aff0a755f2 /src
parent3e39250a79ef1a74bd64e283daf825208ca3875b (diff)
downloadrneovim-55b165ac15a7528a3c679d928b1edf9d701f850b.tar.gz
rneovim-55b165ac15a7528a3c679d928b1edf9d701f850b.tar.bz2
rneovim-55b165ac15a7528a3c679d928b1edf9d701f850b.zip
fix(treesitter): `TSNode:field()` returns all children with the given field
Diffstat (limited to 'src')
-rw-r--r--src/nvim/lua/treesitter.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index 3e33fcd142..259f2d4739 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -998,16 +998,21 @@ static int node_symbol(lua_State *L)
static int node_field(lua_State *L)
{
TSNode node = node_check(L, 1);
+ uint32_t count = ts_node_child_count(node);
+ int curr_index = 0;
size_t name_len;
const char *field_name = luaL_checklstring(L, 2, &name_len);
- lua_newtable(L); // [table]
+ lua_newtable(L);
- TSNode field = ts_node_child_by_field_name(node, field_name, (uint32_t)name_len);
- if (!ts_node_is_null(field)) {
- push_node(L, field, 1); // [table, node]
- lua_rawseti(L, -2, 1);
+ for (uint32_t i = 0; i < count; i++) {
+ const char *child_field_name = ts_node_field_name_for_child(node, i);
+ if (strequal(field_name, child_field_name)) {
+ TSNode child = ts_node_child(node, i);
+ push_node(L, child, 1);
+ lua_rawseti(L, -2, ++curr_index);
+ }
}
return 1;