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.
This commit is contained in:
Nikolai Devolder 2024-10-07 11:46:28 +02:00 committed by Christian Clason
parent 2953b6ae78
commit 8672843527

View file

@ -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