aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/query.lua22
1 files changed, 21 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua
index b914e5d7d..788bfa126 100644
--- a/lua/nvim-treesitter/query.lua
+++ b/lua/nvim-treesitter/query.lua
@@ -13,11 +13,31 @@ local function read_query_files(filenames)
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), true)
+ local query_string = ''
if #query_files > 0 then
- return ts.parse_query(ft, read_query_files(query_files))
+ 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