aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorderekstride <derek.stride@shopify.com>2021-04-15 15:48:48 -0230
committerThomas Vigouroux <tomvig38@gmail.com>2021-06-04 07:47:21 +0200
commite98e2eafa29958a414e5785f58a9cbda117c1bf1 (patch)
tree78f625a1d949f82cca5f08928fcca49be361a772 /lua
parentFix 1359: nil check for version in health-check (diff)
downloadnvim-treesitter-e98e2eafa29958a414e5785f58a9cbda117c1bf1.tar
nvim-treesitter-e98e2eafa29958a414e5785f58a9cbda117c1bf1.tar.gz
nvim-treesitter-e98e2eafa29958a414e5785f58a9cbda117c1bf1.tar.bz2
nvim-treesitter-e98e2eafa29958a414e5785f58a9cbda117c1bf1.tar.lz
nvim-treesitter-e98e2eafa29958a414e5785f58a9cbda117c1bf1.tar.xz
nvim-treesitter-e98e2eafa29958a414e5785f58a9cbda117c1bf1.tar.zst
nvim-treesitter-e98e2eafa29958a414e5785f58a9cbda117c1bf1.zip
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")`
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/query_predicates.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/query_predicates.lua b/lua/nvim-treesitter/query_predicates.lua
index a41ad287b..1748250e5 100644
--- a/lua/nvim-treesitter/query_predicates.lua
+++ b/lua/nvim-treesitter/query_predicates.lua
@@ -87,3 +87,30 @@ end)
-- Just avoid some anoying warnings for this directive
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)