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 /runtime/lua/vim/treesitter.lua | |
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 'runtime/lua/vim/treesitter.lua')
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index a5362202fb..c2df96d9b4 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -288,15 +288,19 @@ function M.get_captures_at_pos(bufnr, row, col) local iter = q:query():iter_captures(root, buf_highlighter.bufnr, row, row + 1) - for id, node, metadata in iter do + for id, node, metadata, match in iter do if M.is_in_node_range(node, row, col) then ---@diagnostic disable-next-line: invisible local capture = q._query.captures[id] -- name of the capture in the query if capture ~= nil then - table.insert( - matches, - { capture = capture, metadata = metadata, lang = tree:lang(), id = id } - ) + local _, pattern_id = match:info() + table.insert(matches, { + capture = capture, + metadata = metadata, + lang = tree:lang(), + id = id, + pattern_id = pattern_id, + }) end end end |