mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-08 14:30:05 -04:00
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:
parent
0611f432aa
commit
2bb6374c34
1 changed files with 19 additions and 0 deletions
|
|
@ -29,6 +29,11 @@ M.base_language_map = {
|
||||||
tsx = {'typescript', 'javascript'},
|
tsx = {'typescript', 'javascript'},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
M.query_extensions = {
|
||||||
|
javascript = { 'jsx' },
|
||||||
|
tsx = {'javascript.jsx'}
|
||||||
|
}
|
||||||
|
|
||||||
M.has_locals = get_query_guard('locals')
|
M.has_locals = get_query_guard('locals')
|
||||||
M.has_highlights = get_query_guard('highlights')
|
M.has_highlights = get_query_guard('highlights')
|
||||||
|
|
||||||
|
|
@ -47,6 +52,20 @@ function M.get_query(lang, query_name)
|
||||||
end
|
end
|
||||||
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
|
if #query_string > 0 then
|
||||||
return ts.parse_query(lang, query_string)
|
return ts.parse_query(lang, query_string)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue