mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-15 18:00:07 -04:00
downcase! directive to use with ruby injections
``` (#downcase! "language") ``` downcase! will ensure the metadata value for the specified key will be downcased. If the value is a node, it will downcase the text specified by the node. ``` (#downcase! @node "key") ``` You can also namespace the key with a specific capture, similar to how you can call `(#set! @node "key" "value")`
This commit is contained in:
parent
ee2266993b
commit
e98e2eafa2
2 changed files with 33 additions and 0 deletions
|
|
@ -87,3 +87,30 @@ end)
|
||||||
|
|
||||||
-- Just avoid some anoying warnings for this directive
|
-- Just avoid some anoying warnings for this directive
|
||||||
query.add_directive('make-range!', function() end)
|
query.add_directive('make-range!', function() end)
|
||||||
|
|
||||||
|
query.add_directive('downcase!', function(match, _, bufnr, pred, metadata)
|
||||||
|
local text, key, value
|
||||||
|
|
||||||
|
if #pred == 3 then
|
||||||
|
-- (#downcase! @capture "key")
|
||||||
|
key = pred[3]
|
||||||
|
value = metadata[pred[2]][key]
|
||||||
|
else
|
||||||
|
-- (#downcase! "key")
|
||||||
|
key = pred[2]
|
||||||
|
value = metadata[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(value) == "string" then
|
||||||
|
text = value
|
||||||
|
else
|
||||||
|
local node = match[value]
|
||||||
|
text = query.get_node_text(node, bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
if #pred == 3 then
|
||||||
|
metadata[pred[2]][key] = string.lower(text)
|
||||||
|
else
|
||||||
|
metadata[key] = string.lower(text)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
|
||||||
|
|
@ -1 +1,7 @@
|
||||||
(comment) @comment
|
(comment) @comment
|
||||||
|
|
||||||
|
(heredoc_body
|
||||||
|
(heredoc_content) @content
|
||||||
|
(heredoc_end) @language
|
||||||
|
(#set! "language" @language)
|
||||||
|
(#downcase! "language"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue