mirror of
https://github.com/neovim/neovim.git
synced 2026-08-31 03:13:48 +00:00
treesitter: default start and end row when omitted
Add support for default start and end row when omitted in the query:iter_captures and query:iter_matches functions. When the start and end row values are omitted, the values of the given node is used. The end row value is incremented by 1 to include the node end row in the match. Updated tests and docs accordingly.
This commit is contained in:
@@ -353,6 +353,12 @@ function Query:iter_captures(node, source, start, stop)
|
||||
if type(source) == "number" and source == 0 then
|
||||
source = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
if start == nil and stop == nil then
|
||||
start, _, stop, _ = node:range()
|
||||
stop = stop + 1 -- Make stop inclusive
|
||||
end
|
||||
|
||||
local raw_iter = node:_rawquery(self.query, true, start, stop)
|
||||
local function iter()
|
||||
local capture, captured_node, match = raw_iter()
|
||||
@@ -385,6 +391,12 @@ function Query:iter_matches(node, source, start, stop)
|
||||
if type(source) == "number" and source == 0 then
|
||||
source = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
if start == nil and stop == nil then
|
||||
start, _, stop, _ = node:range()
|
||||
stop = stop + 1 -- Make stop inclusive
|
||||
end
|
||||
|
||||
local raw_iter = node:_rawquery(self.query, false, start, stop)
|
||||
local function iter()
|
||||
local pattern, match = raw_iter()
|
||||
|
||||
Reference in New Issue
Block a user