diff options
author | Riley Bruins <ribru17@hotmail.com> | 2024-05-14 07:14:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-14 09:14:43 -0500 |
commit | 6a264e08974bcb1b91f891eb65ef374f350d2827 (patch) | |
tree | a205375bf1d1aba5ccedd0003707097e25f6c0ee /runtime/lua/vim/treesitter/query.lua | |
parent | 6818ba271cb43b1430f019b832d7e26671e0f5f4 (diff) | |
download | rneovim-6a264e08974bcb1b91f891eb65ef374f350d2827.tar.gz rneovim-6a264e08974bcb1b91f891eb65ef374f350d2827.tar.bz2 rneovim-6a264e08974bcb1b91f891eb65ef374f350d2827.zip |
fix(treesitter): allow optional directive captures (#28664)
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index e68acac929..36c78b7f1d 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -529,6 +529,9 @@ local directive_handlers = { ['offset!'] = function(match, _, _, pred, metadata) local capture_id = pred[2] --[[@as integer]] local nodes = match[capture_id] + if not nodes or #nodes == 0 then + return + end assert(#nodes == 1, '#offset! does not support captures on multiple nodes') local node = nodes[1] @@ -562,6 +565,9 @@ local directive_handlers = { assert(type(id) == 'number') local nodes = match[id] + if not nodes or #nodes == 0 then + return + end assert(#nodes == 1, '#gsub! does not support captures on multiple nodes') local node = nodes[1] local text = vim.treesitter.get_node_text(node, bufnr, { metadata = metadata[id] }) or '' @@ -584,6 +590,9 @@ local directive_handlers = { assert(type(capture_id) == 'number') local nodes = match[capture_id] + if not nodes or #nodes == 0 then + return + end assert(#nodes == 1, '#trim! does not support captures on multiple nodes') local node = nodes[1] |