mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
feat: add some utils to read queries
This commit is contained in:
parent
e647356210
commit
e51b25dce2
1 changed files with 19 additions and 0 deletions
19
lua/nvim-treesitter/lib.lua
Normal file
19
lua/nvim-treesitter/lib.lua
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue