2022-12-06 04:31:26 +08:00
|
|
|
local Config = require("lazy.core.config")
|
2024-04-22 16:33:32 +08:00
|
|
|
local uv = vim.uv or vim.loop
|
2022-12-06 04:31:26 +08:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
2023-04-16 20:07:41 +08:00
|
|
|
-- "report_" prefix has been deprecated, use the recommended replacements if they exist.
|
|
|
|
local start = vim.health.start or vim.health.report_start
|
|
|
|
local ok = vim.health.ok or vim.health.report_ok
|
|
|
|
local warn = vim.health.warn or vim.health.report_warn
|
|
|
|
local error = vim.health.error or vim.health.report_error
|
2024-06-25 19:23:25 +08:00
|
|
|
local info = vim.health.info or vim.health.report_info
|
2023-04-16 20:07:41 +08:00
|
|
|
|
2024-06-25 19:23:25 +08:00
|
|
|
---@class LazyHealth
|
|
|
|
---@field error? fun(msg:string)
|
|
|
|
---@field warn? fun(msg:string)
|
|
|
|
---@field ok? fun(msg:string)
|
2022-12-06 04:31:26 +08:00
|
|
|
|
2024-06-25 19:23:25 +08:00
|
|
|
---@class LazyHealthHave : LazyHealth
|
|
|
|
---@field version? string
|
|
|
|
---@field version_pattern? string
|
|
|
|
---@field optional? boolean
|
2024-06-24 23:50:27 +08:00
|
|
|
|
2024-06-25 19:23:25 +08:00
|
|
|
---@param cmd string|string[]
|
|
|
|
---@param opts? LazyHealthHave
|
|
|
|
function M.have(cmd, opts)
|
|
|
|
opts = vim.tbl_extend("force", {
|
|
|
|
error = error,
|
|
|
|
warn = warn,
|
|
|
|
ok = ok,
|
|
|
|
version = "--version",
|
|
|
|
}, opts or {})
|
|
|
|
|
|
|
|
cmd = type(cmd) == "table" and cmd or { cmd }
|
|
|
|
---@cast cmd string[]
|
|
|
|
---@type string?
|
|
|
|
local found
|
|
|
|
for _, c in ipairs(cmd) do
|
|
|
|
if vim.fn.executable(c) == 1 then
|
|
|
|
local version = vim.fn.system(c .. " " .. opts.version) or ""
|
|
|
|
version = vim.trim(vim.split(version, "\n")[1])
|
|
|
|
version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "")
|
|
|
|
if opts.version_pattern and not version:find(opts.version_pattern, 1, true) then
|
|
|
|
opts.warn(("`%s` version `%s` needed, but found `%s`"):format(c, opts.version_pattern, version))
|
|
|
|
else
|
|
|
|
found = ("{%s} `%s`"):format(c, version)
|
|
|
|
break
|
|
|
|
end
|
2024-06-25 02:03:00 +08:00
|
|
|
end
|
2023-01-24 15:48:14 +08:00
|
|
|
end
|
2024-06-25 19:23:25 +08:00
|
|
|
if found then
|
|
|
|
opts.ok(found)
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
(opts.optional and opts.warn or opts.error)(
|
|
|
|
("{%s} %snot installed"):format(
|
|
|
|
table.concat(cmd, "} or {"),
|
|
|
|
opts.version_pattern and "version `" .. opts.version_pattern .. "` " or ""
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.check()
|
|
|
|
start("lazy.nvim")
|
2024-06-27 16:44:35 +08:00
|
|
|
info("{lazy.nvim} version `" .. Config.version .. "`")
|
2024-06-25 19:23:25 +08:00
|
|
|
|
|
|
|
M.have("git")
|
2023-01-24 15:48:14 +08:00
|
|
|
|
2023-01-04 06:48:00 +08:00
|
|
|
local sites = vim.opt.packpath:get()
|
|
|
|
local default_site = vim.fn.stdpath("data") .. "/site"
|
|
|
|
if not vim.tbl_contains(sites, default_site) then
|
|
|
|
sites[#sites + 1] = default_site
|
|
|
|
end
|
|
|
|
|
2022-12-06 04:31:26 +08:00
|
|
|
local existing = false
|
2023-01-04 06:48:00 +08:00
|
|
|
for _, site in pairs(sites) do
|
|
|
|
for _, packs in ipairs(vim.fn.expand(site .. "/pack/*", false, true)) do
|
2024-04-22 16:33:32 +08:00
|
|
|
if not packs:find("[/\\]dist$") and uv.fs_stat(packs) then
|
2023-01-04 06:48:00 +08:00
|
|
|
existing = true
|
2023-04-16 20:07:41 +08:00
|
|
|
warn("found existing packages at `" .. packs .. "`")
|
2023-01-04 06:48:00 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-12-06 04:31:26 +08:00
|
|
|
if not existing then
|
2023-04-16 20:07:41 +08:00
|
|
|
ok("no existing packages found by other package managers")
|
2022-12-06 04:31:26 +08:00
|
|
|
end
|
|
|
|
|
2024-06-25 19:23:25 +08:00
|
|
|
for _, name in ipairs({ "packer", "plugged", "paq", "pckr", "mini.deps" }) do
|
2023-02-28 03:38:05 +08:00
|
|
|
for _, path in ipairs(vim.opt.rtp:get()) do
|
|
|
|
if path:find(name, 1, true) then
|
2023-04-16 20:07:41 +08:00
|
|
|
error("Found paths on the rtp from another plugin manager `" .. name .. "`")
|
2023-02-28 03:38:05 +08:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-06 04:31:26 +08:00
|
|
|
local packer_compiled = vim.fn.stdpath("config") .. "/plugin/packer_compiled.lua"
|
2024-04-22 16:33:32 +08:00
|
|
|
if uv.fs_stat(packer_compiled) then
|
2023-04-16 20:07:41 +08:00
|
|
|
error("please remove the file `" .. packer_compiled .. "`")
|
2022-12-06 04:31:26 +08:00
|
|
|
else
|
2023-04-16 20:07:41 +08:00
|
|
|
ok("packer_compiled.lua not found")
|
2022-12-06 04:31:26 +08:00
|
|
|
end
|
|
|
|
|
2023-01-02 16:44:09 +08:00
|
|
|
local spec = Config.spec
|
2023-04-28 00:21:02 +08:00
|
|
|
if spec == nil then
|
2023-10-09 17:25:42 +08:00
|
|
|
error('No plugins loaded. Did you forget to run `require("lazy").setup()`?')
|
2023-04-28 00:21:02 +08:00
|
|
|
else
|
|
|
|
for _, plugin in pairs(spec.plugins) do
|
|
|
|
M.check_valid(plugin)
|
|
|
|
end
|
|
|
|
if #spec.notifs > 0 then
|
|
|
|
error("Issues were reported when loading your specs:")
|
|
|
|
for _, notif in ipairs(spec.notifs) do
|
|
|
|
local lines = vim.split(notif.msg, "\n")
|
|
|
|
for _, line in ipairs(lines) do
|
|
|
|
if notif.level == vim.log.levels.ERROR then
|
|
|
|
error(line)
|
|
|
|
else
|
|
|
|
warn(line)
|
|
|
|
end
|
2023-01-02 16:44:09 +08:00
|
|
|
end
|
2022-12-30 18:52:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-06-25 19:23:25 +08:00
|
|
|
|
|
|
|
start("luarocks")
|
|
|
|
if Config.options.rocks.enabled then
|
|
|
|
if Config.options.rocks.hererocks then
|
|
|
|
info("checking `hererocks` installation")
|
|
|
|
else
|
|
|
|
info("checking `luarocks` installation")
|
|
|
|
end
|
2024-06-26 03:15:50 +08:00
|
|
|
local need_luarocks = {}
|
|
|
|
for _, plugin in pairs(spec.plugins) do
|
|
|
|
if plugin.build == "rockspec" then
|
|
|
|
table.insert(need_luarocks, plugin.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #need_luarocks == 0 then
|
|
|
|
ok("no plugins require `luarocks`, so you can ignore any warnings below")
|
|
|
|
else
|
|
|
|
local lines = vim.tbl_map(function(name)
|
|
|
|
return " * `" .. name .. "`"
|
|
|
|
end, need_luarocks)
|
|
|
|
|
|
|
|
info("you have some plugins that require `luarocks`:\n" .. table.concat(lines, "\n"))
|
|
|
|
end
|
2024-06-27 18:31:58 +08:00
|
|
|
local ok = require("lazy.pkg.rockspec").check({
|
2024-06-26 03:15:50 +08:00
|
|
|
error = #need_luarocks > 0 and error or warn,
|
|
|
|
warn = warn,
|
|
|
|
ok = ok,
|
|
|
|
})
|
2024-06-27 18:31:58 +08:00
|
|
|
if not ok then
|
|
|
|
warn(table.concat({
|
|
|
|
"Lazy won't be able to install plugins that require `luarocks`.",
|
|
|
|
"Here's what you can do:",
|
|
|
|
" - fix your `luarocks` installation",
|
|
|
|
Config.options.rocks.hererocks and " - disable *hererocks* with `opts.rocks.hererocks = false`"
|
|
|
|
or " - enable `hererocks` with `opts.rocks.hererocks = true`",
|
|
|
|
" - disable `luarocks` support completely with `opts.rocks.enabled = false`",
|
|
|
|
}, "\n"))
|
|
|
|
end
|
2024-06-25 19:23:25 +08:00
|
|
|
else
|
|
|
|
ok("luarocks disabled")
|
|
|
|
end
|
2022-12-06 04:31:26 +08:00
|
|
|
end
|
|
|
|
|
2023-01-04 16:35:00 +08:00
|
|
|
---@param plugin LazyPlugin
|
|
|
|
function M.check_valid(plugin)
|
|
|
|
for key in pairs(plugin) do
|
|
|
|
if not vim.tbl_contains(M.valid, key) then
|
|
|
|
if key ~= "module" or type(plugin.module) ~= "boolean" then
|
2023-04-16 20:07:41 +08:00
|
|
|
warn("{" .. plugin.name .. "}: unknown key <" .. key .. ">")
|
2023-01-04 16:35:00 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
M.valid = {
|
|
|
|
1,
|
2023-01-08 22:01:49 +08:00
|
|
|
"_",
|
2023-01-04 16:35:00 +08:00
|
|
|
"branch",
|
2023-01-08 22:01:49 +08:00
|
|
|
"build",
|
2023-01-04 16:35:00 +08:00
|
|
|
"cmd",
|
2023-01-08 22:01:49 +08:00
|
|
|
"commit",
|
|
|
|
"cond",
|
|
|
|
"config",
|
2023-02-27 20:42:52 +08:00
|
|
|
"deactivate",
|
2023-01-08 22:01:49 +08:00
|
|
|
"dependencies",
|
|
|
|
"dev",
|
|
|
|
"dir",
|
|
|
|
"enabled",
|
2023-01-04 16:35:00 +08:00
|
|
|
"event",
|
|
|
|
"ft",
|
2023-01-08 22:01:49 +08:00
|
|
|
"import",
|
|
|
|
"init",
|
|
|
|
"keys",
|
|
|
|
"lazy",
|
2023-03-20 15:02:24 +08:00
|
|
|
"main",
|
2023-01-08 22:01:49 +08:00
|
|
|
"module",
|
|
|
|
"name",
|
2023-06-26 13:54:12 +08:00
|
|
|
"optional",
|
2023-01-08 22:01:49 +08:00
|
|
|
"opts",
|
|
|
|
"pin",
|
2023-01-04 16:35:00 +08:00
|
|
|
"priority",
|
2024-01-20 21:49:47 +08:00
|
|
|
"submodules",
|
2023-01-08 22:01:49 +08:00
|
|
|
"tag",
|
|
|
|
"url",
|
|
|
|
"version",
|
2023-01-04 16:35:00 +08:00
|
|
|
}
|
|
|
|
|
2022-12-06 04:31:26 +08:00
|
|
|
return M
|