aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/treesitter.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-05-11 11:13:32 +0100
committerGitHub <noreply@github.com>2023-05-11 11:13:32 +0100
commitaf040c3a079f6e25db0ad6b908aa1327f67deb82 (patch)
treee5d90fd09f0c0cfcb99afb6ca7b564ba98fd31f0 /src/nvim/lua/treesitter.c
parente90b506903babc84f8c5b796c3b25c7f20e183d2 (diff)
downloadrneovim-af040c3a079f6e25db0ad6b908aa1327f67deb82.tar.gz
rneovim-af040c3a079f6e25db0ad6b908aa1327f67deb82.tar.bz2
rneovim-af040c3a079f6e25db0ad6b908aa1327f67deb82.zip
feat(treesitter): add support for setting query depths
Diffstat (limited to 'src/nvim/lua/treesitter.c')
-rw-r--r--src/nvim/lua/treesitter.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index da64685a40..0c4700ccab 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -1360,6 +1360,29 @@ static int node_rawquery(lua_State *L)
ts_query_cursor_set_point_range(cursor, (TSPoint){ start, 0 }, (TSPoint){ end, 0 });
}
+ if (lua_gettop(L) >= 6 && !lua_isnil(L, 6)) {
+ if (!lua_istable(L, 6)) {
+ return luaL_error(L, "table expected");
+ }
+ lua_pushnil(L);
+ // stack: [dict, ..., nil]
+ while (lua_next(L, 6)) {
+ // stack: [dict, ..., key, value]
+ if (lua_type(L, -2) == LUA_TSTRING) {
+ char *k = (char *)lua_tostring(L, -2);
+ if (strequal("max_start_depth", k)) {
+ // TODO(lewis6991): remove ifdef when min TS version is 0.20.9
+#ifdef NVIM_TS_HAS_SET_MAX_START_DEPTH
+ uint32_t max_start_depth = (uint32_t)lua_tointeger(L, -1);
+ ts_query_cursor_set_max_start_depth(cursor, max_start_depth);
+#endif
+ }
+ }
+ lua_pop(L, 1); // pop the value; lua_next will pop the key.
+ // stack: [dict, ..., key]
+ }
+ }
+
TSLua_cursor *ud = lua_newuserdata(L, sizeof(*ud)); // [udata]
ud->cursor = cursor;
ud->predicated_match = -1;