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!`).
This commit is contained in:
Ian Chamberlain
2025-03-11 09:45:01 -04:00
committed by GitHub
parent 0829e7575d
commit 8b5a0a00c8
10 changed files with 212 additions and 15 deletions

View File

@@ -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