mirror of
https://github.com/neovim/neovim.git
synced 2026-04-21 14:55:33 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user