From 3dfb9e6f60d9ca27ff140a9300cc1a43e38aa2ee Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Wed, 11 Dec 2024 04:34:24 -0800 Subject: feat(treesitter): include capture id in return value of `get_captures_at_pos()` #30559 **Problem:** Currently, it is difficult to get node(s)-level metadata for a capture returned by `get_captures_at_pos()`. This is because it is stored in `metadata[id]` and we do not have access to the value of `id`, so to get this value we have to iterate over the keys of `metadata`. See [this commit](https://github.com/neovim/neovim/commit/d63622930001b39b12f14112fc3abb55b760c447#diff-8bd4742121c2f359d0345f3c6c253a58220f1a28670cc4e1c957992232059a6cR16). Things would be much simpler if we were given the `id` of the capture so we could use it to just index `metadata` directly. **Solution:** Include `id` in the data returned by `get_captures_at_pos()` --- test/functional/treesitter/highlight_spec.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/functional/treesitter/highlight_spec.lua') diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 028c01f14a..7f0a3cb342 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -12,6 +12,7 @@ local fn = n.fn local eq = t.eq local hl_query_c = [[ + ; query (ERROR) @error "if" @keyword @@ -639,8 +640,8 @@ describe('treesitter highlighting (C)', function() } eq({ - { capture = 'constant', metadata = { priority = '101' }, lang = 'c' }, - { capture = 'type', metadata = {}, lang = 'c' }, + { capture = 'constant', metadata = { priority = '101' }, lang = 'c', id = 14 }, + { capture = 'type', metadata = {}, lang = 'c', id = 3 }, }, exec_lua [[ return vim.treesitter.get_captures_at_pos(0, 0, 2) ]]) end) -- cgit