summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/lib.lua
blob: 328e4a571120b0ddeee25cb9e90cbdf353f9a8fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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