From 86728435273b63fe71fa64a66c2a6d49e94613a2 Mon Sep 17 00:00:00 2001 From: Nikolai Devolder Date: Mon, 7 Oct 2024 11:46:28 +0200 Subject: Fix(auto_install): Install parser if Filetype already known If setup function was called after `FileType` autocommand triggers the installation of parser was not done. This commit checks if filetype is already know before adding the autocommand. --- lua/nvim-treesitter/install.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index ec7d6245b..cd12dbb81 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -555,15 +555,19 @@ local function install(options) end function M.setup_auto_install() + local function try_install_curr_lang() + local lang = parsers.get_buf_lang() + if parsers.get_parser_configs()[lang] and not is_installed(lang) and not is_ignored_parser(lang) then + install() { lang } + end + end + + try_install_curr_lang() + vim.api.nvim_create_autocmd("FileType", { pattern = { "*" }, group = vim.api.nvim_create_augroup("NvimTreesitter-auto_install", { clear = true }), - callback = function() - local lang = parsers.get_buf_lang() - if parsers.get_parser_configs()[lang] and not is_installed(lang) and not is_ignored_parser(lang) then - install() { lang } - end - end, + callback = try_install_curr_lang, }) end -- cgit v1.2.3-70-g09d2