mirror of
https://github.com/neovim/neovim.git
synced 2026-04-19 14:00:49 +00:00
feat(treesitter): allow capture text to be transformed
Co-authored-by: Lewis Russell <lewis6991@gmail.com>
This commit is contained in:
@@ -452,6 +452,21 @@ local directive_handlers = {
|
||||
metadata[capture_id].range = range
|
||||
end
|
||||
end,
|
||||
|
||||
-- Transform the content of the node
|
||||
-- Example: (#gsub! @_node ".*%.(.*)" "%1")
|
||||
['gsub!'] = function(match, _, bufnr, pred, metadata)
|
||||
assert(#pred == 4)
|
||||
|
||||
local id = pred[2]
|
||||
local node = match[id]
|
||||
local text = M.get_node_text(node, bufnr, { metadata = metadata[id] }) or ''
|
||||
|
||||
if not metadata[id] then
|
||||
metadata[id] = {}
|
||||
end
|
||||
metadata[id].text = text:gsub(pred[3], pred[4])
|
||||
end,
|
||||
}
|
||||
|
||||
--- Adds a new predicate to be used in queries
|
||||
|
||||
Reference in New Issue
Block a user