mirror of
https://github.com/neovim/neovim.git
synced 2026-04-04 14:49:31 +00:00
fix(treesitter): allow optional directive captures (#28664)
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user