Define multiple query for a language

Allows using another query file for a language, or use a query file
from another language
This commit is contained in:
kiyan42 2020-06-29 16:51:38 +02:00 committed by Thomas Vigouroux
parent 0611f432aa
commit 2bb6374c34

View file

@ -29,6 +29,11 @@ M.base_language_map = {
tsx = {'typescript', 'javascript'},
}
M.query_extensions = {
javascript = { 'jsx' },
tsx = {'javascript.jsx'}
}
M.has_locals = get_query_guard('locals')
M.has_highlights = get_query_guard('highlights')
@ -47,6 +52,20 @@ function M.get_query(lang, query_name)
end
end
local extensions = M.query_extensions[lang]
for _, ext in ipairs(extensions or {}) do
local l = lang
local e = ext
if e:match('%.') ~= nil then
l = e:match('.*%.'):sub(0, -2)
e = e:match('%..*'):sub(2, -1)
end
local ext_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', l, e), true)
if ext_files and #ext_files > 0 then
query_string = read_query_files(ext_files) .. "\n" .. query_string
end
end
if #query_string > 0 then
return ts.parse_query(lang, query_string)
end