aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/configs.lua7
-rw-r--r--lua/nvim-treesitter/query.lua35
2 files changed, 38 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index f79fed00c..f7b5ff2cf 100644
--- a/lua/nvim-treesitter/configs.lua
+++ b/lua/nvim-treesitter/configs.lua
@@ -203,6 +203,13 @@ parsers.nix = {
}
}
+parsers.regex = {
+ install_info = {
+ url = "https://github.com/tree-sitter/tree-sitter-regex",
+ files = { "src/parser.c" }
+ }
+}
+
-- @enable can be true or false
-- @disable is a list of languages, only relevant if enable is true
-- @keymaps list of user mappings for a given module if relevant
diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua
index 644c33933..788bfa126 100644
--- a/lua/nvim-treesitter/query.lua
+++ b/lua/nvim-treesitter/query.lua
@@ -3,14 +3,41 @@ local ts = vim.treesitter
local M = {}
-local function read_query_file(fname)
- return table.concat(vim.fn.readfile(fname), '\n')
+local function read_query_files(filenames)
+ local contents = {}
+
+ for _,filename in ipairs(filenames) do
+ vim.list_extend(contents, vim.fn.readfile(filename))
+ end
+
+ return table.concat(contents, '\n')
end
+-- Some treesitter grammars extend others.
+-- We can use that to import the queries of the base language
+M.base_language_map = {
+ cpp = {'c'},
+ typescript = {'javascript'},
+ tsx = {'typescript', 'javascript'},
+}
+
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)
+ local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), true)
+ local query_string = ''
+
if #query_files > 0 then
- return ts.parse_query(ft, read_query_file(query_files[1]))
+ query_string = read_query_files(query_files)..query_string
+ end
+
+ for _, base_lang in ipairs(M.base_language_map[ft] or {}) do
+ local base_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', base_lang, query_name), false)
+ if base_files and #base_files > 0 then
+ query_string = read_query_files(base_files)..query_string
+ end
+ end
+
+ if #query_string > 0 then
+ return ts.parse_query(ft, query_string)
end
end