mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 02:40:09 -04:00
perf: cache parser file list for performance
This commit is contained in:
parent
8f3b601bcc
commit
ba3167a1a4
2 changed files with 17 additions and 1 deletions
|
|
@ -59,6 +59,8 @@ local function iter_cmd_sync(cmd_list)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run_install(cache_folder, package_path, lang, repo, with_sync)
|
local function run_install(cache_folder, package_path, lang, repo, with_sync)
|
||||||
|
parsers.reset_cache()
|
||||||
|
|
||||||
local project_name = 'tree-sitter-'..lang
|
local project_name = 'tree-sitter-'..lang
|
||||||
local project_repo = cache_folder..'/'..project_name
|
local project_repo = cache_folder..'/'..project_name
|
||||||
-- compile_location only needed for typescript installs.
|
-- compile_location only needed for typescript installs.
|
||||||
|
|
|
||||||
|
|
@ -284,11 +284,25 @@ function M.get_parser_configs()
|
||||||
return M.list
|
return M.list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local parser_files
|
||||||
|
|
||||||
|
function M.reset_cache()
|
||||||
|
parser_files = setmetatable({}, {
|
||||||
|
__index = function(tbl, key)
|
||||||
|
rawset(tbl, key, api.nvim_get_runtime_file('parser/' .. key .. '.*', false))
|
||||||
|
return rawget(tbl, key)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
M.reset_cache()
|
||||||
|
|
||||||
function M.has_parser(lang)
|
function M.has_parser(lang)
|
||||||
local buf = api.nvim_get_current_buf()
|
local buf = api.nvim_get_current_buf()
|
||||||
local lang = lang or M.get_buf_lang(buf)
|
local lang = lang or M.get_buf_lang(buf)
|
||||||
|
|
||||||
if not lang or #lang == 0 then return false end
|
if not lang or #lang == 0 then return false end
|
||||||
return #api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) > 0
|
return #parser_files[lang] > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_parser(bufnr, lang)
|
function M.get_parser(bufnr, lang)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue