feat: switch from lazy to vim.pack
This commit is contained in:
@@ -4,84 +4,6 @@ local Util = {}
|
||||
|
||||
Util.os_name = vim.uv.os_uname().sysname
|
||||
|
||||
--- Check that an executable is available
|
||||
--- @param exe string Array to look for
|
||||
--- @return boolean
|
||||
function Util.is_executable(exe)
|
||||
return vim.fn.executable(exe) == 1
|
||||
end
|
||||
|
||||
--- Check that at least one executable is available
|
||||
--- @param exes table Array of exes
|
||||
--- @return boolean
|
||||
function Util.any_installed(exes)
|
||||
for _, e in ipairs(exes) do
|
||||
if Util.is_executable(e) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--- Asserts that an executable is available
|
||||
--- Raises error if missing.
|
||||
--- @param exe string Array to look for
|
||||
function Util.assert_installed(exe)
|
||||
assert(Util.is_executable(exe), "Missing executable '" .. exe .. "'.")
|
||||
end
|
||||
|
||||
--- Asserts that at least one executable is available
|
||||
--- Raises error if missing.
|
||||
--- @param exes table Array of exes
|
||||
function Util.assert_any_installed(exes)
|
||||
assert(
|
||||
Util.any_installed(exes),
|
||||
"At least one of the following is required:\n"
|
||||
.. table.concat(exes, ", ")
|
||||
)
|
||||
end
|
||||
|
||||
--- Asserts that a python module is installed
|
||||
---@param mod string The python module to check
|
||||
function Util.python3_module_is_installed(mod)
|
||||
if not Util.is_executable("python3") then
|
||||
return false
|
||||
end
|
||||
|
||||
local resp = vim.system({ "python3", "-c", "import " .. mod }):wait()
|
||||
return resp.code == 0
|
||||
end
|
||||
|
||||
--- Asserts that a python module is installed
|
||||
---@param mod string The python module to check
|
||||
function Util.assert_python3_module_installed(mod)
|
||||
if not Util.python3_module_is_installed(mod) then
|
||||
error("Python3 module " .. mod .. " not installed")
|
||||
end
|
||||
end
|
||||
|
||||
--- Attempts to load a module and logs errors on failure.
|
||||
---@param module string The module to attempt to load.
|
||||
---@return any module The loaded module if successful, otherwise nil.
|
||||
function Util.try_require(module)
|
||||
local has_module, resp = pcall(require, module)
|
||||
|
||||
if has_module then
|
||||
return resp
|
||||
end
|
||||
|
||||
log.error("Failed to load module %s:\n%s", module, resp)
|
||||
end
|
||||
|
||||
--- Checks if it is possible to require a module
|
||||
---@param module string
|
||||
---@return boolean
|
||||
function Util.has_module(module)
|
||||
local has_module, _ = pcall(require, module)
|
||||
return has_module
|
||||
end
|
||||
|
||||
---@alias OutputStream
|
||||
---| '"stdout"'
|
||||
---| '"stderr"'
|
||||
|
||||
Reference in New Issue
Block a user