diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-12-06 10:08:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-06 10:08:20 -0800 |
commit | ba7370a902abc1ca533f8ebf70f708e16a2a64c2 (patch) | |
tree | d9f08c1fdb16d8fbbf035ff507b9218309b0d4ba /test/functional/treesitter/testutil.lua | |
parent | e8e3b443f8040329bd833fcc945d5dbf3adb832c (diff) | |
parent | f0ea38a4bcb37aa6c68d498864c3c83f2867c4ad (diff) | |
download | rneovim-ba7370a902abc1ca533f8ebf70f708e16a2a64c2.tar.gz rneovim-ba7370a902abc1ca533f8ebf70f708e16a2a64c2.tar.bz2 rneovim-ba7370a902abc1ca533f8ebf70f708e16a2a64c2.zip |
Merge #30085 #trim! all whitespace
Diffstat (limited to 'test/functional/treesitter/testutil.lua')
-rw-r--r-- | test/functional/treesitter/testutil.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/functional/treesitter/testutil.lua b/test/functional/treesitter/testutil.lua new file mode 100644 index 0000000000..f8934f06c3 --- /dev/null +++ b/test/functional/treesitter/testutil.lua @@ -0,0 +1,25 @@ +local n = require('test.functional.testnvim')() + +local exec_lua = n.exec_lua + +local M = {} + +---@param language string +---@param query_string string +function M.run_query(language, query_string) + return exec_lua(function(lang, query_str) + local query = vim.treesitter.query.parse(lang, query_str) + local parser = vim.treesitter.get_parser() + local tree = parser:parse()[1] + local res = {} + for id, node, metadata in query:iter_captures(tree:root(), 0) do + table.insert( + res, + { query.captures[id], metadata[id] and metadata[id].range or { node:range() } } + ) + end + return res + end, language, query_string) +end + +return M |