mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-20 12:20:02 -04:00
fix(directive): make downcase work on captures
This commit is contained in:
parent
71532e7776
commit
b223402ba9
3 changed files with 11 additions and 31 deletions
|
|
@ -178,37 +178,25 @@ end, true)
|
||||||
-- Just avoid some annoying warnings for this directive
|
-- Just avoid some annoying warnings for this directive
|
||||||
query.add_directive("make-range!", function() end, true)
|
query.add_directive("make-range!", function() end, true)
|
||||||
|
|
||||||
|
--- transform node text to lower case (e.g., to make @injection.language case insensitive)
|
||||||
|
---
|
||||||
---@param match (TSNode|nil)[]
|
---@param match (TSNode|nil)[]
|
||||||
---@param _ string
|
---@param _ string
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param pred string[]
|
---@param pred string[]
|
||||||
---@param metadata table
|
|
||||||
---@return boolean|nil
|
---@return boolean|nil
|
||||||
query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
||||||
local text, key, value ---@type string|string[], string, string|integer
|
local id = pred[2]
|
||||||
|
local node = match[id]
|
||||||
if #pred == 3 then
|
if not node then
|
||||||
-- (#downcase! @capture "key")
|
return
|
||||||
key = pred[3]
|
|
||||||
value = metadata[pred[2]][key]
|
|
||||||
else
|
|
||||||
-- (#downcase! "key")
|
|
||||||
key = pred[2]
|
|
||||||
value = metadata[key]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(value) == "string" then
|
local text = vim.treesitter.get_node_text(node, bufnr, { metadata = metadata[id] }) or ""
|
||||||
text = value
|
if not metadata[id] then
|
||||||
else
|
metadata[id] = {}
|
||||||
local node = match[value]
|
|
||||||
text = vim.treesitter.get_node_text(node, bufnr) or ""
|
|
||||||
end
|
|
||||||
|
|
||||||
if #pred == 3 then
|
|
||||||
metadata[pred[2]][key] = string.lower(text)
|
|
||||||
else
|
|
||||||
metadata[key] = string.lower(text)
|
|
||||||
end
|
end
|
||||||
|
metadata[id].text = string.lower(text)
|
||||||
end, true)
|
end, true)
|
||||||
|
|
||||||
-- Trim blank lines from end of the region
|
-- Trim blank lines from end of the region
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,3 @@
|
||||||
|
|
||||||
((regex) @injection.content
|
((regex) @injection.content
|
||||||
(#set! injection.language "regex"))
|
(#set! injection.language "regex"))
|
||||||
|
|
||||||
((redirected_statement
|
|
||||||
(heredoc_redirect
|
|
||||||
(heredoc_start) @injection.language))
|
|
||||||
(heredoc_body) @injection.content
|
|
||||||
(#offset! @injection.content 0 0 -1 0)
|
|
||||||
(#downcase! @injection.language))
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@
|
||||||
(heredoc_body
|
(heredoc_body
|
||||||
(heredoc_content) @injection.content
|
(heredoc_content) @injection.content
|
||||||
(heredoc_end) @injection.language
|
(heredoc_end) @injection.language
|
||||||
(#set! "language" @injection.language)
|
(#downcase! @injection.language))
|
||||||
(#downcase! "language"))
|
|
||||||
|
|
||||||
(regex
|
(regex
|
||||||
(string_content) @injection.content
|
(string_content) @injection.content
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue