diff options
| author | Nikolai Devolder <nikolai.devolder@yamabiko.eu> | 2024-10-07 11:46:28 +0200 |
|---|---|---|
| committer | Christian Clason <ch.clason+github@icloud.com> | 2024-10-14 16:45:21 +0200 |
| commit | 86728435273b63fe71fa64a66c2a6d49e94613a2 (patch) | |
| tree | 7b25486c6f63535fb343343ce927cac0506a63be /lua | |
| parent | fix(slang): adapt to parser changes (diff) | |
| download | nvim-treesitter-86728435273b63fe71fa64a66c2a6d49e94613a2.tar nvim-treesitter-86728435273b63fe71fa64a66c2a6d49e94613a2.tar.gz nvim-treesitter-86728435273b63fe71fa64a66c2a6d49e94613a2.tar.bz2 nvim-treesitter-86728435273b63fe71fa64a66c2a6d49e94613a2.tar.lz nvim-treesitter-86728435273b63fe71fa64a66c2a6d49e94613a2.tar.xz nvim-treesitter-86728435273b63fe71fa64a66c2a6d49e94613a2.tar.zst nvim-treesitter-86728435273b63fe71fa64a66c2a6d49e94613a2.zip | |
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.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 16 |
1 files changed, 10 insertions, 6 deletions
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 |
