@@ -7,6 +7,7 @@ function _G.dump(...)
77end
88
99local uv = vim .uv or vim .loop
10+ local memoize = vim .func and vim .func ._memoize
1011
1112local M = {}
1213
@@ -1467,17 +1468,20 @@ end
14671468
14681469--- Checks if treesitter parser for language is installed
14691470--- @param lang string
1471+ --- @param query_name string
14701472--- @return boolean
1471- function M .has_ts_parser (lang )
1472- if M .__HAS_NVIM_011 then
1473- return vim .treesitter .language .add (lang )
1474- -- ensure the language has a highlights parser or we get
1475- -- no highlights for langugaes like json/jsonc/toml/etc
1476- and # vim .treesitter .query .get_files (lang , " highlights" ) > 0
1477- or false
1478- else
1479- return (pcall (vim .treesitter .language .add , lang ))
1480- end
1473+ function M .has_ts_parser (lang , query_name )
1474+ -- ensure the language has a highlights parser or we get
1475+ -- no highlights for langugaes like json/jsonc/toml/etc
1476+ return (M .__HAS_NVIM_011 and vim .treesitter .language .add (lang )
1477+ or (pcall (vim .treesitter .language .add , lang )))
1478+ and # vim .treesitter .query .get_files (lang , query_name ) > 0 or false
1479+ end
1480+
1481+ -- query.get_files, which looks expensive recursively check modeline
1482+ -- also call nvim_get_runtime_file -> shell scripts
1483+ if memoize then
1484+ M .has_ts_parser = memoize (" concat-2" , M .has_ts_parser , false )
14811485end
14821486
14831487--- Wrapper around vim.lsp.jump_to_location which was deprecated in v0.11
0 commit comments