diff options
author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-06-29 23:02:30 +0200 |
---|---|---|
committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-06-29 23:32:49 +0200 |
commit | 69816f5e134f0e965352367b5928835794da1698 (patch) | |
tree | 11a8a476b0d83907cd6d52e2f14aa953974e2096 /src | |
parent | 66af35fc85fb2e14fe8f91449289af06b9104dd4 (diff) | |
download | rneovim-69816f5e134f0e965352367b5928835794da1698.tar.gz rneovim-69816f5e134f0e965352367b5928835794da1698.tar.bz2 rneovim-69816f5e134f0e965352367b5928835794da1698.zip |
treesitter: use single nodes in set_ranges
fixup! treesitter: fix lint
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/lua/treesitter.c | 43 |
1 files changed, 7 insertions, 36 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 913be5afe8..ddf54720a7 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -411,50 +411,21 @@ static int parser_set_ranges(lua_State *L) for (size_t index = 0; index < tbl_len; index++) { lua_rawgeti(L, 2, index + 1); // [ parser, ranges, range ] - if (!lua_istable(L, -1)) { + TSNode node; + if (!node_check(L, -1, &node)) { xfree(ranges); return luaL_error( L, - "argument for parser:set_included_ranges() should be a table of tables."); - } - - if (lua_objlen(L, -1) != 2) { - xfree(ranges); - return luaL_error( - L, - "argument for parser:set_included_ranges() should be a table of ranges of 2 elements."); - } - - - lua_rawgeti(L, -1, 1); // [ parser, ranges, range, start_node ] - TSNode start_node; - if (!node_check(L, -1, &start_node)) { - xfree(ranges); - lua_pushstring( - L, - "ranges should be tables of nodes."); - return lua_error(L); - } - lua_pop(L, 1); // [ parser, ranges, range ] - - lua_rawgeti(L, -1, 1); // [ parser, ranges, range, stop_node ] - TSNode stop_node; - if (!node_check(L, -1, &stop_node)) { - xfree(ranges); - lua_pushstring( - L, "ranges should be tables of nodes."); - return lua_error(L); } - lua_pop(L, 1); // [ parser, ranges, range ] + lua_pop(L, 1); // [ parser, ranges ] ranges[index] = (TSRange) { - .start_point = ts_node_start_point(start_node), - .end_point = ts_node_end_point(stop_node), - .start_byte = ts_node_start_byte(start_node), - .end_byte = ts_node_end_byte(stop_node) + .start_point = ts_node_start_point(node), + .end_point = ts_node_end_point(node), + .start_byte = ts_node_start_byte(node), + .end_byte = ts_node_end_byte(node) }; - lua_pop(L, 1); // [ parser, ranges ] } // This memcpies ranges, thus we can free it afterwards |