mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17: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
|
||||
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 _ string
|
||||
---@param bufnr integer
|
||||
---@param pred string[]
|
||||
---@param metadata table
|
||||
---@return boolean|nil
|
||||
query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
||||
local text, key, value ---@type string|string[], string, string|integer
|
||||
|
||||
if #pred == 3 then
|
||||
-- (#downcase! @capture "key")
|
||||
key = pred[3]
|
||||
value = metadata[pred[2]][key]
|
||||
else
|
||||
-- (#downcase! "key")
|
||||
key = pred[2]
|
||||
value = metadata[key]
|
||||
local id = pred[2]
|
||||
local node = match[id]
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
|
||||
if type(value) == "string" then
|
||||
text = value
|
||||
else
|
||||
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)
|
||||
local text = vim.treesitter.get_node_text(node, bufnr, { metadata = metadata[id] }) or ""
|
||||
if not metadata[id] then
|
||||
metadata[id] = {}
|
||||
end
|
||||
metadata[id].text = string.lower(text)
|
||||
end, true)
|
||||
|
||||
-- Trim blank lines from end of the region
|
||||
|
|
|
|||
|
|
@ -3,10 +3,3 @@
|
|||
|
||||
((regex) @injection.content
|
||||
(#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_content) @injection.content
|
||||
(heredoc_end) @injection.language
|
||||
(#set! "language" @injection.language)
|
||||
(#downcase! "language"))
|
||||
(#downcase! @injection.language))
|
||||
|
||||
(regex
|
||||
(string_content) @injection.content
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue