From d49bbcf92e5dc1e96bd09fca62fcf7152c459ba8 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 28 Sep 2026 11:24:21 +0100 Subject: feat(treesitter): add get_captures() for positions and ranges Problem: get_captures_at_pos() only returns captures at one position. It cannot query a whole line or range. It can also miss captures from injected languages outside the visible area. Solution: Add vim.treesitter.get_captures() with a required start and an optional exclusive stop. Accept row numbers or {row, col} positions. Without a stop, query one position or a whole line. Parse the requested range and return capture coordinates. Deprecate get_captures_at_pos() with a compatibility wrapper and migrate its internal callers. Keep get_captures_at_cursor() for capture names at a window's cursor. AI-assisted --- test/functional/plugin/matchparen_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional/plugin/matchparen_spec.lua') diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 04a099a36d..30d5b8e62e 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -41,4 +41,22 @@ describe('matchparen', function() {1:-- INSERT --} | ]]) end) + + it('skips treesitter strings in another window', function() + api.nvim_buf_set_lines(0, 0, -1, false, { 'print(")")' }) + n.exec_lua(function() + vim.treesitter.start(0, 'lua') + end) + api.nvim_win_set_cursor(0, { 1, 5 }) + local win = api.nvim_get_current_win() + command('new') + eq( + { { 1, 6, 1 }, { 1, 10, 1 } }, + n.exec_lua(function(target_win) + require('nvim.matchparen').highlight_matching_pair(target_win) + local match = vim.fn.getmatches(target_win)[1] + return { match.pos1, match.pos2 } + end, win) + ) + end) end) -- cgit