aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2020-08-11 14:36:13 +0200
committerThomas Vigouroux <39092278+vigoux@users.noreply.github.com>2020-08-11 20:21:22 +0200
commitba3167a1a4fdc9028eb1f088e823ac1dceb202f4 (patch)
tree9beeb06dde0aba0871d9c393a4ee7d0649d966b9 /lua
parentRST: update textobjects (diff)
downloadnvim-treesitter-ba3167a1a4fdc9028eb1f088e823ac1dceb202f4.tar
nvim-treesitter-ba3167a1a4fdc9028eb1f088e823ac1dceb202f4.tar.gz
nvim-treesitter-ba3167a1a4fdc9028eb1f088e823ac1dceb202f4.tar.bz2
nvim-treesitter-ba3167a1a4fdc9028eb1f088e823ac1dceb202f4.tar.lz
nvim-treesitter-ba3167a1a4fdc9028eb1f088e823ac1dceb202f4.tar.xz
nvim-treesitter-ba3167a1a4fdc9028eb1f088e823ac1dceb202f4.tar.zst
nvim-treesitter-ba3167a1a4fdc9028eb1f088e823ac1dceb202f4.zip
perf: cache parser file list for performance
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/install.lua2
-rw-r--r--lua/nvim-treesitter/parsers.lua16
2 files changed, 17 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index e8c6cf86b..eac4af7e0 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -59,6 +59,8 @@ local function iter_cmd_sync(cmd_list)
end
local function run_install(cache_folder, package_path, lang, repo, with_sync)
+ parsers.reset_cache()
+
local project_name = 'tree-sitter-'..lang
local project_repo = cache_folder..'/'..project_name
-- compile_location only needed for typescript installs.
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 491edcb66..c1b48a00d 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -284,11 +284,25 @@ function M.get_parser_configs()
return M.list
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)
local buf = api.nvim_get_current_buf()
local lang = lang or M.get_buf_lang(buf)
+
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
function M.get_parser(bufnr, lang)