diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason-core/async/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/functional/init.lua | 21 | ||||
| -rw-r--r-- | lua/mason-core/installer/linker.lua | 5 | ||||
| -rw-r--r-- | lua/mason-core/installer/managers/pypi.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/installer/registry/init.lua | 6 | ||||
| -rw-r--r-- | lua/mason-core/installer/registry/link.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/installer/registry/providers/github.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/managers/cargo/init.lua | 8 | ||||
| -rw-r--r-- | lua/mason-core/managers/go/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/managers/pip3/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/managers/powershell/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/managers/std/init.lua | 8 | ||||
| -rw-r--r-- | lua/mason-core/spawn.lua | 4 | ||||
| -rw-r--r-- | lua/mason-registry/index/ltex-ls/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason-registry/init.lua | 8 | ||||
| -rw-r--r-- | lua/mason/api/command.lua | 4 | ||||
| -rw-r--r-- | lua/mason/health/init.lua | 8 |
17 files changed, 45 insertions, 59 deletions
diff --git a/lua/mason-core/async/init.lua b/lua/mason-core/async/init.lua index df7c996c..1b9b23a4 100644 --- a/lua/mason-core/async/init.lua +++ b/lua/mason-core/async/init.lua @@ -150,7 +150,9 @@ exports.sleep = function(ms) end exports.scheduler = function() - await(vim.schedule) + if vim.in_fast_event() then + await(vim.schedule) + end end ---@async diff --git a/lua/mason-core/functional/init.lua b/lua/mason-core/functional/init.lua index 5e0ac680..353c5cc1 100644 --- a/lua/mason-core/functional/init.lua +++ b/lua/mason-core/functional/init.lua @@ -153,4 +153,25 @@ _.lazy_when = function(condition, value) return condition and value() or nil end +---@param fn fun() +_.scheduler = function(fn) + if vim.in_fast_event() then + vim.schedule(fn) + else + fn() + end +end + +---@generic T : fun(...) +---@param fn T +---@return T +_.scheduler_wrap = function(fn) + return function(...) + local args = _.table_pack(...) + _.scheduler(function() + fn(unpack(args, 1, args.n + 1)) + end) + end +end + return _ diff --git a/lua/mason-core/installer/linker.lua b/lua/mason-core/installer/linker.lua index b97dfd3d..98d1d30f 100644 --- a/lua/mason-core/installer/linker.lua +++ b/lua/mason-core/installer/linker.lua @@ -63,10 +63,7 @@ local function link(context, link_context, link_fn) do -- 1. Ensure destination directory exists - if vim.in_fast_event() then - a.scheduler() - end - + a.scheduler() local dir = vim.fn.fnamemodify(dest_abs_path, ":h") if not fs.async.dir_exists(dir) then try(Result.pcall(fs.async.mkdirp, dir)) diff --git a/lua/mason-core/installer/managers/pypi.lua b/lua/mason-core/installer/managers/pypi.lua index 9f71cc19..bb148013 100644 --- a/lua/mason-core/installer/managers/pypi.lua +++ b/lua/mason-core/installer/managers/pypi.lua @@ -55,9 +55,7 @@ function M.init(opts) log.fmt_debug("pypi: init", opts) local ctx = installer.context() - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local executables = platform.is.win and _.list_not_nil( diff --git a/lua/mason-core/installer/registry/init.lua b/lua/mason-core/installer/registry/init.lua index f03f3e31..23b1a379 100644 --- a/lua/mason-core/installer/registry/init.lua +++ b/lua/mason-core/installer/registry/init.lua @@ -141,10 +141,8 @@ end function M.compile(spec, opts) log.debug("Compiling installer.", spec.name, opts) return Result.try(function(try) - if vim.in_fast_event() then - -- Parsers run synchronously and may access API functions, so we schedule before-hand. - a.scheduler() - end + -- Parsers run synchronously and may access API functions, so we schedule before-hand. + a.scheduler() local map_parse_err = _.cond { { diff --git a/lua/mason-core/installer/registry/link.lua b/lua/mason-core/installer/registry/link.lua index 7075163b..5d6a8f16 100644 --- a/lua/mason-core/installer/registry/link.lua +++ b/lua/mason-core/installer/registry/link.lua @@ -214,9 +214,7 @@ local function expand_file_spec(ctx, purl, source, file_spec_table) return Result.failure(("Cannot link file %q to dir %q."):format(source_path, dest)) end - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local glob = path.concat { cwd, source_path } .. "**/*" log.fmt_trace("Symlink glob for %s: %s", ctx.package, glob) diff --git a/lua/mason-core/installer/registry/providers/github.lua b/lua/mason-core/installer/registry/providers/github.lua index 90fcbbfa..06ac0b06 100644 --- a/lua/mason-core/installer/registry/providers/github.lua +++ b/lua/mason-core/installer/registry/providers/github.lua @@ -113,9 +113,7 @@ local release = { end)) for __, download in ipairs(source.downloads) do - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local out_dir = vim.fn.fnamemodify(download.out_file, ":h") local out_file = vim.fn.fnamemodify(download.out_file, ":t") if out_dir ~= "." then diff --git a/lua/mason-core/managers/cargo/init.lua b/lua/mason-core/managers/cargo/init.lua index e0eec3b6..49a5841a 100644 --- a/lua/mason-core/managers/cargo/init.lua +++ b/lua/mason-core/managers/cargo/init.lua @@ -144,9 +144,7 @@ end ---@param receipt InstallReceipt<InstallReceiptPackageSource> ---@param install_dir string function M.check_outdated_primary_package(receipt, install_dir) - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local crate_name = vim.fn.fnamemodify(receipt.primary_source.package, ":t") return get_installed_crates(install_dir) :ok() @@ -189,9 +187,7 @@ end ---@param receipt InstallReceipt<InstallReceiptPackageSource> ---@param install_dir string function M.get_installed_primary_package_version(receipt, install_dir) - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local crate_name = vim.fn.fnamemodify(receipt.primary_source.package, ":t") return get_installed_crates(install_dir) :ok() diff --git a/lua/mason-core/managers/go/init.lua b/lua/mason-core/managers/go/init.lua index 438e7785..0452400d 100644 --- a/lua/mason-core/managers/go/init.lua +++ b/lua/mason-core/managers/go/init.lua @@ -114,9 +114,7 @@ end ---@param receipt InstallReceipt<InstallReceiptPackageSource> ---@param install_dir string function M.get_installed_primary_package_version(receipt, install_dir) - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local normalized_pkg_name = trim_wildcard_suffix(receipt.primary_source.package) -- trims e.g. golang.org/x/tools/gopls to gopls local executable = vim.fn.fnamemodify(normalized_pkg_name, ":t") diff --git a/lua/mason-core/managers/pip3/init.lua b/lua/mason-core/managers/pip3/init.lua index 1b76e050..36ad6fc7 100644 --- a/lua/mason-core/managers/pip3/init.lua +++ b/lua/mason-core/managers/pip3/init.lua @@ -46,9 +46,7 @@ function M.install(packages) pkgs[1] = ("%s==%s"):format(pkgs[1], version) end) - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local executables = platform.is.win and _.list_not_nil(vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog), "python", "python3") diff --git a/lua/mason-core/managers/powershell/init.lua b/lua/mason-core/managers/powershell/init.lua index 4c0ec712..66045bc4 100644 --- a/lua/mason-core/managers/powershell/init.lua +++ b/lua/mason-core/managers/powershell/init.lua @@ -12,9 +12,7 @@ local PWSHOPT = { } local powershell = _.lazy(function() - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() if vim.fn.executable "pwsh" == 1 then return "pwsh" else diff --git a/lua/mason-core/managers/std/init.lua b/lua/mason-core/managers/std/init.lua index dda39bac..eb7db9bb 100644 --- a/lua/mason-core/managers/std/init.lua +++ b/lua/mason-core/managers/std/init.lua @@ -21,9 +21,7 @@ end function M.ensure_executable(executable, opts) local ctx = installer.context() opts = opts or {} - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() if vim.fn.executable(executable) ~= 1 then ctx.stdio_sink.stderr(("%s was not found in path.\n"):format(executable)) if opts.help_url then @@ -190,9 +188,7 @@ end ---@params opts function M.select(items, opts) assert(not platform.is_headless, "Tried to prompt for user input while in headless mode.") - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local async_select = a.promisify(vim.ui.select) return async_select(items, opts) end diff --git a/lua/mason-core/spawn.lua b/lua/mason-core/spawn.lua index 50c90a38..c6f06d81 100644 --- a/lua/mason-core/spawn.lua +++ b/lua/mason-core/spawn.lua @@ -34,9 +34,7 @@ local function Failure(err, cmd) end local is_executable = _.memoize(function(cmd) - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() return vim.fn.executable(cmd) == 1 end, _.identity) diff --git a/lua/mason-registry/index/ltex-ls/init.lua b/lua/mason-registry/index/ltex-ls/init.lua index 1cd10618..6cde2e51 100644 --- a/lua/mason-registry/index/ltex-ls/init.lua +++ b/lua/mason-registry/index/ltex-ls/init.lua @@ -61,9 +61,7 @@ return Pkg.new { ---@async ---@param ctx InstallContext install = function(ctx) - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() if vim.fn.executable "java" == 1 then download_platform_independent() else diff --git a/lua/mason-registry/init.lua b/lua/mason-registry/init.lua index 93472ef3..0f1805a4 100644 --- a/lua/mason-registry/init.lua +++ b/lua/mason-registry/init.lua @@ -176,15 +176,11 @@ function M.refresh(cb) ---@async local function refresh() - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local is_outdated = get_store_age(os.time()) > REGISTRY_STORE_TTL if is_outdated or not sources.is_installed() then if a.wait(M.update) then - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() update_store_timestamp(os.time()) end end diff --git a/lua/mason/api/command.lua b/lua/mason/api/command.lua index 8fba7ea0..ae889e6c 100644 --- a/lua/mason/api/command.lua +++ b/lua/mason/api/command.lua @@ -66,8 +66,8 @@ local function join_handles(handles) end, handles) if _.length(failed_packages) > 0 then - a.scheduler() -- wait for scheduler for logs to finalize - a.scheduler() -- logs have been written + a.wait(vim.schedule) -- wait for scheduler for logs to finalize + a.wait(vim.schedule) -- logs have been written vim.api.nvim_err_writeln "" vim.api.nvim_err_writeln( ("The following packages failed to install: %s"):format(_.join(", ", failed_packages)) diff --git a/lua/mason/health/init.lua b/lua/mason/health/init.lua index b4ff37a2..93fe295d 100644 --- a/lua/mason/health/init.lua +++ b/lua/mason/health/init.lua @@ -306,9 +306,7 @@ function M.check() :map( ---@param rate_limit GitHubRateLimitResponse function(rate_limit) - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() local remaining = rate_limit.resources.core.remaining local used = rate_limit.resources.core.used local limit = rate_limit.resources.core.limit @@ -327,9 +325,7 @@ function M.check() end ) :on_failure(function() - if vim.in_fast_event() then - a.scheduler() - end + a.scheduler() health.report_warn "Failed to check GitHub API rate limit status." end) end) |
