From e51b25dce209f0d560785c841fd3e4c667b12b9e Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Sat, 18 Apr 2020 17:40:26 +0200 Subject: feat: add some utils to read queries --- lua/nvim-treesitter/lib.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lua/nvim-treesitter/lib.lua (limited to 'lua/nvim-treesitter/lib.lua') diff --git a/lua/nvim-treesitter/lib.lua b/lua/nvim-treesitter/lib.lua new file mode 100644 index 00000000..328e4a57 --- /dev/null +++ b/lua/nvim-treesitter/lib.lua @@ -0,0 +1,19 @@ +-- Treesitter utils + +local api = vim.api +local ts = vim.treesitter + +local M = {} + +local function read_query_file(fname) + return table.concat(vim.fn.readfile(fname), '\n') +end + +function M.get_query(ft, query_name) + local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), false) + if #query_files > 0 then + return ts.parse_query(ft, read_query_file(query_files[1])) + end +end + +return M -- cgit v1.2.3