diff options
author | Ian Chamberlain <ian-h-chamberlain@users.noreply.github.com> | 2025-03-11 09:45:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-11 14:45:01 +0100 |
commit | 8b5a0a00c8cfe776c4227862c3fb32a07d154663 (patch) | |
tree | 447d3f2bed0bb30786c7faef373f7f40ab08613b /src | |
parent | 0829e7575d63d51f0e33df81be2a45099aedea97 (diff) | |
download | rneovim-8b5a0a00c8cfe776c4227862c3fb32a07d154663.tar.gz rneovim-8b5a0a00c8cfe776c4227862c3fb32a07d154663.tar.bz2 rneovim-8b5a0a00c8cfe776c4227862c3fb32a07d154663.zip |
feat(treesitter): allow disabling captures and patterns on TSQuery (#32790)
Problem: Cannot disable individual captures and patterns in treesitter queries.
Solution:
* Expose the corresponding tree-sitter API functions for `TSQuery` object.
* Add documentation for `TSQuery`.
* Return the pattern ID from `get_captures_at_pos()` (and hence `:Inspect!`).
Diffstat (limited to 'src')
-rwxr-xr-x | src/gen/gen_vimdoc.lua | 2 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/gen/gen_vimdoc.lua b/src/gen/gen_vimdoc.lua index 2fe7224ea5..68912cf0b5 100755 --- a/src/gen/gen_vimdoc.lua +++ b/src/gen/gen_vimdoc.lua @@ -328,10 +328,12 @@ local config = { 'treesitter.lua', 'language.lua', 'query.lua', + 'tsquery.lua', 'highlighter.lua', 'languagetree.lua', 'dev.lua', }, + append_only = { 'tsquery.lua' }, files = { 'runtime/lua/vim/treesitter/_meta/', 'runtime/lua/vim/treesitter.lua', diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index fa5cf1118d..a346bf5963 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -1491,6 +1491,8 @@ static struct luaL_Reg query_meta[] = { { "__gc", query_gc }, { "__tostring", query_tostring }, { "inspect", query_inspect }, + { "disable_capture", query_disable_capture }, + { "disable_pattern", query_disable_pattern }, { NULL, NULL } }; @@ -1689,6 +1691,23 @@ static int query_inspect(lua_State *L) return 1; } +static int query_disable_capture(lua_State *L) +{ + TSQuery *query = query_check(L, 1); + size_t name_len; + const char *name = luaL_checklstring(L, 2, &name_len); + ts_query_disable_capture(query, name, (uint32_t)name_len); + return 0; +} + +static int query_disable_pattern(lua_State *L) +{ + TSQuery *query = query_check(L, 1); + const uint32_t pattern_index = (uint32_t)luaL_checkinteger(L, 2); + ts_query_disable_pattern(query, pattern_index - 1); + return 0; +} + // Library init static void build_meta(lua_State *L, const char *tname, const luaL_Reg *meta) |