diff options
| author | MeanderingProgrammer <meanderingprogrammer@gmail.com> | 2025-07-20 15:36:06 -0700 |
|---|---|---|
| committer | Christian Clason <ch.clason+github@icloud.com> | 2025-07-21 09:40:08 +0200 |
| commit | 3650b4ef6a0c2eff49d59db6d30b2549557447a4 (patch) | |
| tree | bb0b12d6e465a1c29cd4edf3940f4c84d87e315b /lua | |
| parent | fix(install): don't make "installed" status persistent (diff) | |
| download | nvim-treesitter-3650b4ef6a0c2eff49d59db6d30b2549557447a4.tar nvim-treesitter-3650b4ef6a0c2eff49d59db6d30b2549557447a4.tar.gz nvim-treesitter-3650b4ef6a0c2eff49d59db6d30b2549557447a4.tar.bz2 nvim-treesitter-3650b4ef6a0c2eff49d59db6d30b2549557447a4.tar.lz nvim-treesitter-3650b4ef6a0c2eff49d59db6d30b2549557447a4.tar.xz nvim-treesitter-3650b4ef6a0c2eff49d59db6d30b2549557447a4.tar.zst nvim-treesitter-3650b4ef6a0c2eff49d59db6d30b2549557447a4.zip | |
refactor(install): replace status enum with boolean
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 233ea83fe..6d672908a 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -439,13 +439,7 @@ local function try_install_lang(lang, cache_dir, install_dir, generate) logger:info('Language installed') end ----@alias InstallStatus ---- | 'installing' ---- | 'installed' ---- | 'failed' ---- | 'timeout' - -local install_status = {} ---@type table<string,InstallStatus?> +local installing = {} ---@type table<string,boolean?> ---@async ---@param lang string @@ -453,29 +447,21 @@ local install_status = {} ---@type table<string,InstallStatus?> ---@param install_dir string ---@param force? boolean ---@param generate? boolean ----@return InstallStatus status +---@return boolean success local function install_lang(lang, cache_dir, install_dir, force, generate) if not force and vim.list_contains(config.get_installed(), lang) then - return 'installed' - end - - if install_status[lang] then - if install_status[lang] == 'installing' then - vim.wait(INSTALL_TIMEOUT, function() - return install_status[lang] ~= 'installing' - end) - install_status[lang] = 'timeout' - end + return true + elseif installing[lang] then + local success = vim.wait(INSTALL_TIMEOUT, function() + return not installing[lang] + end) + return success else - install_status[lang] = 'installing' + installing[lang] = true local err = try_install_lang(lang, cache_dir, install_dir, generate) - install_status[lang] = err and 'failed' or 'installed' + installing[lang] = nil + return not err end - - local status = install_status[lang] - assert(status and status ~= 'installing') - install_status[lang] = nil - return status end --- Reload the parser table and user modifications in case of update @@ -511,8 +497,8 @@ local function install(languages, options) for _, lang in ipairs(languages) do tasks[#tasks + 1] = a.async(--[[@async]] function() a.schedule() - local status = install_lang(lang, cache_dir, install_dir, options.force, options.generate) - if status ~= 'failed' then + local success = install_lang(lang, cache_dir, install_dir, options.force, options.generate) + if success then done = done + 1 end end) |
