2022-11-25 21:48:17 +00:00
|
|
|
local Config = require("lazy.core.config")
|
2024-06-22 21:18:26 +01:00
|
|
|
local Meta = require("lazy.core.meta")
|
2024-06-18 20:54:54 +01:00
|
|
|
local Pkg = require("lazy.pkg")
|
2023-10-09 10:25:42 +01:00
|
|
|
local Util = require("lazy.core.util")
|
2022-11-25 21:48:17 +00:00
|
|
|
|
2022-12-28 16:57:59 +00:00
|
|
|
---@class LazyCorePlugin
|
2022-11-25 21:48:17 +00:00
|
|
|
local M = {}
|
2023-01-11 22:07:58 +00:00
|
|
|
M.loading = false
|
2022-11-25 21:48:17 +00:00
|
|
|
|
2022-11-28 06:36:32 +00:00
|
|
|
---@class LazySpecLoader
|
2024-06-22 21:18:26 +01:00
|
|
|
---@field meta LazyMeta
|
2022-11-25 21:48:17 +00:00
|
|
|
---@field plugins table<string, LazyPlugin>
|
2023-01-03 09:34:53 +00:00
|
|
|
---@field disabled table<string, LazyPlugin>
|
2023-09-29 15:11:56 +01:00
|
|
|
---@field ignore_installed table<string, true>
|
2023-01-01 20:07:05 +00:00
|
|
|
---@field modules string[]
|
2023-01-02 08:44:09 +00:00
|
|
|
---@field notifs {msg:string, level:number, file?:string}[]
|
|
|
|
---@field importing? string
|
2023-05-23 07:57:53 +01:00
|
|
|
---@field optional? boolean
|
2024-06-18 20:54:54 +01:00
|
|
|
---@field pkgs table<string, boolean>
|
2022-11-25 21:48:17 +00:00
|
|
|
local Spec = {}
|
2022-11-29 13:27:58 +00:00
|
|
|
M.Spec = Spec
|
2024-05-26 15:43:52 +01:00
|
|
|
M.LOCAL_SPEC = ".lazy.lua"
|
2022-11-29 13:27:58 +00:00
|
|
|
|
|
|
|
---@param spec? LazySpec
|
2023-05-23 07:57:53 +01:00
|
|
|
---@param opts? {optional?:boolean}
|
|
|
|
function Spec.new(spec, opts)
|
2024-06-22 21:18:26 +01:00
|
|
|
local self = setmetatable({}, Spec)
|
|
|
|
self.meta = Meta.new(self)
|
2023-01-03 09:34:53 +00:00
|
|
|
self.disabled = {}
|
2023-01-01 20:07:05 +00:00
|
|
|
self.modules = {}
|
2023-01-02 08:44:09 +00:00
|
|
|
self.notifs = {}
|
2023-09-29 15:11:56 +01:00
|
|
|
self.ignore_installed = {}
|
2024-06-18 20:54:54 +01:00
|
|
|
self.pkgs = {}
|
2023-05-23 07:57:53 +01:00
|
|
|
self.optional = opts and opts.optional
|
2022-11-29 13:27:58 +00:00
|
|
|
if spec then
|
2023-01-12 12:07:51 +00:00
|
|
|
self:parse(spec)
|
2022-11-29 13:27:58 +00:00
|
|
|
end
|
|
|
|
return self
|
|
|
|
end
|
2022-11-25 21:48:17 +00:00
|
|
|
|
2024-06-22 21:18:26 +01:00
|
|
|
function Spec:__index(key)
|
|
|
|
if Spec[key] then
|
|
|
|
return Spec[key]
|
|
|
|
end
|
|
|
|
if key == "plugins" then
|
|
|
|
self.meta:rebuild()
|
|
|
|
return self.meta.plugins
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-12 12:07:51 +00:00
|
|
|
function Spec:parse(spec)
|
|
|
|
self:normalize(spec)
|
2024-06-22 21:30:20 +01:00
|
|
|
self.meta:resolve()
|
2023-01-12 12:07:51 +00:00
|
|
|
end
|
|
|
|
|
2022-12-13 09:09:33 +00:00
|
|
|
-- PERF: optimized code to get package name without using lua patterns
|
2024-06-18 18:40:58 +01:00
|
|
|
---@return string
|
2022-12-13 09:09:33 +00:00
|
|
|
function Spec.get_name(pkg)
|
|
|
|
local name = pkg:sub(-4) == ".git" and pkg:sub(1, -5) or pkg
|
2023-05-25 07:10:08 +01:00
|
|
|
name = name:sub(-1) == "/" and name:sub(1, -2) or name
|
2022-12-13 09:09:33 +00:00
|
|
|
local slash = name:reverse():find("/", 1, true) --[[@as number?]]
|
|
|
|
return slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_")
|
|
|
|
end
|
|
|
|
|
2024-06-22 21:18:26 +01:00
|
|
|
---@param plugin LazyPluginSpec
|
|
|
|
function Spec:add(plugin)
|
|
|
|
self.meta:add(plugin)
|
2023-01-16 16:03:43 +00:00
|
|
|
|
2024-06-22 21:18:26 +01:00
|
|
|
---@diagnostic disable-next-line: cast-type-mismatch
|
|
|
|
---@cast plugin LazyPlugin
|
2022-11-29 18:51:37 +00:00
|
|
|
|
2024-06-18 18:40:58 +01:00
|
|
|
-- import the plugin's spec
|
2024-06-18 20:54:54 +01:00
|
|
|
if Config.options.pkg.enabled and plugin.dir and not self.pkgs[plugin.dir] then
|
|
|
|
self.pkgs[plugin.dir] = true
|
|
|
|
local pkg = Pkg.get_spec(plugin)
|
|
|
|
if pkg then
|
2024-06-22 21:18:26 +01:00
|
|
|
self:normalize(pkg)
|
2024-06-18 18:40:58 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-04 16:50:57 +00:00
|
|
|
return plugin
|
2022-11-25 21:48:17 +00:00
|
|
|
end
|
|
|
|
|
2023-01-02 08:44:09 +00:00
|
|
|
function Spec:error(msg)
|
2023-01-02 09:08:45 +00:00
|
|
|
self:log(msg, vim.log.levels.ERROR)
|
2023-01-02 08:44:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Spec:warn(msg)
|
2023-01-02 09:08:45 +00:00
|
|
|
self:log(msg, vim.log.levels.WARN)
|
2023-01-02 08:44:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---@param msg string
|
|
|
|
---@param level number
|
2023-01-02 09:08:45 +00:00
|
|
|
function Spec:log(msg, level)
|
2023-01-02 08:44:09 +00:00
|
|
|
self.notifs[#self.notifs + 1] = { msg = msg, level = level, file = self.importing }
|
2023-01-02 09:08:45 +00:00
|
|
|
end
|
|
|
|
|
2023-01-02 11:53:35 +00:00
|
|
|
function Spec:report(level)
|
|
|
|
level = level or vim.log.levels.ERROR
|
2023-10-15 07:36:15 +01:00
|
|
|
local count = 0
|
2023-01-02 09:08:45 +00:00
|
|
|
for _, notif in ipairs(self.notifs) do
|
2023-01-02 11:53:35 +00:00
|
|
|
if notif.level >= level then
|
2023-01-10 07:42:20 +00:00
|
|
|
Util.notify(notif.msg, { level = notif.level })
|
2023-10-15 07:36:15 +01:00
|
|
|
count = count + 1
|
2023-01-02 11:53:35 +00:00
|
|
|
end
|
2023-01-02 09:08:45 +00:00
|
|
|
end
|
2023-10-15 07:36:15 +01:00
|
|
|
return count
|
2022-12-22 15:36:07 +00:00
|
|
|
end
|
|
|
|
|
2023-01-01 20:07:05 +00:00
|
|
|
---@param spec LazySpec|LazySpecImport
|
2024-06-22 21:18:26 +01:00
|
|
|
function Spec:normalize(spec)
|
2022-11-25 21:48:17 +00:00
|
|
|
if type(spec) == "string" then
|
2024-06-22 21:18:26 +01:00
|
|
|
self:add({ spec })
|
2022-11-25 21:48:17 +00:00
|
|
|
elseif #spec > 1 or Util.is_list(spec) then
|
2022-11-28 06:36:32 +00:00
|
|
|
---@cast spec LazySpec[]
|
2022-11-25 21:48:17 +00:00
|
|
|
for _, s in ipairs(spec) do
|
2024-06-22 21:18:26 +01:00
|
|
|
self:normalize(s)
|
2022-11-25 21:48:17 +00:00
|
|
|
end
|
2023-01-04 16:50:57 +00:00
|
|
|
elseif spec[1] or spec.dir or spec.url then
|
2024-06-22 21:18:26 +01:00
|
|
|
---@cast spec LazyPluginSpec
|
|
|
|
local plugin = self:add(spec)
|
2023-01-04 16:50:57 +00:00
|
|
|
---@diagnostic disable-next-line: cast-type-mismatch
|
|
|
|
---@cast plugin LazySpecImport
|
|
|
|
if plugin and plugin.import then
|
|
|
|
self:import(plugin)
|
|
|
|
end
|
2023-01-01 20:07:05 +00:00
|
|
|
elseif spec.import then
|
|
|
|
---@cast spec LazySpecImport
|
|
|
|
self:import(spec)
|
|
|
|
else
|
2023-01-04 16:50:57 +00:00
|
|
|
self:error("Invalid plugin spec " .. vim.inspect(spec))
|
2022-11-25 21:48:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-01 20:07:05 +00:00
|
|
|
---@param spec LazySpecImport
|
|
|
|
function Spec:import(spec)
|
2023-01-03 21:49:04 +00:00
|
|
|
if spec.import == "lazy" then
|
|
|
|
return self:error("You can't name your plugins module `lazy`.")
|
|
|
|
end
|
2024-06-16 06:09:33 +01:00
|
|
|
if type(spec.import) == "function" then
|
|
|
|
if not spec.name then
|
|
|
|
return self:error("Invalid import spec. Missing name: " .. vim.inspect(spec))
|
|
|
|
end
|
|
|
|
elseif type(spec.import) ~= "string" then
|
2023-05-25 07:25:34 +01:00
|
|
|
return self:error("Invalid import spec. `import` should be a string: " .. vim.inspect(spec))
|
|
|
|
end
|
2024-06-16 06:09:33 +01:00
|
|
|
|
|
|
|
local import_name = spec.name or spec.import
|
|
|
|
---@cast import_name string
|
|
|
|
|
|
|
|
if vim.tbl_contains(self.modules, import_name) then
|
2023-01-10 08:20:39 +00:00
|
|
|
return
|
|
|
|
end
|
2023-10-06 14:46:46 +01:00
|
|
|
if spec.cond == false or (type(spec.cond) == "function" and not spec.cond()) then
|
|
|
|
return
|
|
|
|
end
|
2023-01-01 20:07:05 +00:00
|
|
|
if spec.enabled == false or (type(spec.enabled) == "function" and not spec.enabled()) then
|
|
|
|
return
|
|
|
|
end
|
2023-01-02 08:44:09 +00:00
|
|
|
|
2024-06-16 06:09:33 +01:00
|
|
|
self.modules[#self.modules + 1] = import_name
|
|
|
|
|
|
|
|
local import = spec.import
|
2023-01-02 08:44:09 +00:00
|
|
|
|
|
|
|
local imported = 0
|
2023-02-17 12:58:16 +00:00
|
|
|
|
2024-06-16 06:09:33 +01:00
|
|
|
---@type (string|(fun():LazyPluginSpec))[]
|
|
|
|
local modspecs = {}
|
2024-05-26 15:43:52 +01:00
|
|
|
|
2024-06-16 06:09:33 +01:00
|
|
|
if type(import) == "string" then
|
|
|
|
Util.lsmod(import, function(modname)
|
|
|
|
modspecs[#modspecs + 1] = modname
|
2024-05-26 15:43:52 +01:00
|
|
|
end)
|
2024-06-16 06:09:33 +01:00
|
|
|
table.sort(modspecs)
|
|
|
|
else
|
|
|
|
modspecs = { spec.import }
|
2024-05-26 15:43:52 +01:00
|
|
|
end
|
2023-02-17 12:58:16 +00:00
|
|
|
|
2024-06-16 06:09:33 +01:00
|
|
|
for _, modspec in ipairs(modspecs) do
|
2023-01-02 08:44:09 +00:00
|
|
|
imported = imported + 1
|
2024-06-16 06:09:33 +01:00
|
|
|
local modname = type(modspec) == "string" and modspec or import_name
|
|
|
|
Util.track({ import = modname })
|
2023-01-02 08:44:09 +00:00
|
|
|
self.importing = modname
|
2023-01-01 20:07:05 +00:00
|
|
|
-- unload the module so we get a clean slate
|
|
|
|
---@diagnostic disable-next-line: no-unknown
|
|
|
|
package.loaded[modname] = nil
|
|
|
|
Util.try(function()
|
2024-06-16 06:09:33 +01:00
|
|
|
local mod = type(modspec) == "function" and modspec() or require(modspec)
|
2023-04-22 13:10:06 +01:00
|
|
|
if type(mod) ~= "table" then
|
|
|
|
self.importing = nil
|
|
|
|
return self:error(
|
|
|
|
"Invalid spec module: `"
|
|
|
|
.. modname
|
|
|
|
.. "`\nExpected a `table` of specs, but a `"
|
|
|
|
.. type(mod)
|
|
|
|
.. "` was returned instead"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
self:normalize(mod)
|
2023-01-02 08:44:09 +00:00
|
|
|
self.importing = nil
|
|
|
|
Util.track()
|
2023-01-01 20:07:05 +00:00
|
|
|
end, {
|
|
|
|
msg = "Failed to load `" .. modname .. "`",
|
|
|
|
on_error = function(msg)
|
|
|
|
self:error(msg)
|
2023-01-02 08:44:09 +00:00
|
|
|
self.importing = nil
|
|
|
|
Util.track()
|
2023-01-01 20:07:05 +00:00
|
|
|
end,
|
|
|
|
})
|
2023-02-17 12:58:16 +00:00
|
|
|
end
|
2023-01-02 08:44:09 +00:00
|
|
|
if imported == 0 then
|
|
|
|
self:error("No specs found for module " .. spec.import)
|
|
|
|
end
|
2023-01-01 20:07:05 +00:00
|
|
|
end
|
|
|
|
|
2022-11-29 23:18:59 +00:00
|
|
|
function M.update_state()
|
2023-02-28 10:51:16 +00:00
|
|
|
---@type string[]
|
|
|
|
local cloning = {}
|
|
|
|
|
2022-12-01 10:06:44 +00:00
|
|
|
---@type table<string,FileType>
|
|
|
|
local installed = {}
|
2022-12-03 14:48:06 +00:00
|
|
|
Util.ls(Config.options.root, function(_, name, type)
|
2022-12-20 06:19:55 +00:00
|
|
|
if type == "directory" and name ~= "readme" then
|
2022-12-01 10:06:44 +00:00
|
|
|
installed[name] = type
|
2023-02-28 10:51:16 +00:00
|
|
|
elseif type == "file" and name:sub(-8) == ".cloning" then
|
|
|
|
name = name:sub(1, -9)
|
|
|
|
cloning[#cloning + 1] = name
|
2022-12-01 10:06:44 +00:00
|
|
|
end
|
|
|
|
end)
|
2022-11-25 21:48:17 +00:00
|
|
|
|
2023-02-28 10:51:16 +00:00
|
|
|
for _, failed in ipairs(cloning) do
|
|
|
|
installed[failed] = nil
|
|
|
|
end
|
|
|
|
|
2022-11-29 23:18:59 +00:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2022-11-28 10:19:50 +00:00
|
|
|
plugin._ = plugin._ or {}
|
2022-12-01 10:06:44 +00:00
|
|
|
if plugin.lazy == nil then
|
2022-12-02 16:09:40 +00:00
|
|
|
local lazy = plugin._.dep
|
|
|
|
or Config.options.defaults.lazy
|
|
|
|
or plugin.event
|
|
|
|
or plugin.keys
|
|
|
|
or plugin.ft
|
|
|
|
or plugin.cmd
|
2022-12-01 10:06:44 +00:00
|
|
|
plugin.lazy = lazy and true or false
|
2022-11-28 21:03:44 +00:00
|
|
|
end
|
2022-12-20 06:15:26 +00:00
|
|
|
if plugin.dir:find(Config.options.root, 1, true) == 1 then
|
2022-12-03 14:31:21 +00:00
|
|
|
plugin._.installed = installed[plugin.name] ~= nil
|
2022-12-01 10:06:44 +00:00
|
|
|
installed[plugin.name] = nil
|
2022-12-13 09:09:33 +00:00
|
|
|
else
|
|
|
|
plugin._.is_local = true
|
|
|
|
plugin._.installed = true -- local plugins are managed by the user
|
2022-11-28 12:18:31 +00:00
|
|
|
end
|
2022-11-25 21:48:17 +00:00
|
|
|
end
|
|
|
|
|
2023-09-29 15:11:56 +01:00
|
|
|
for name in pairs(Config.spec.ignore_installed) do
|
|
|
|
installed[name] = nil
|
2023-07-06 14:30:01 +01:00
|
|
|
end
|
|
|
|
|
2024-06-18 18:39:47 +01:00
|
|
|
require("lazy.manage.rocks").update_state()
|
|
|
|
|
2022-11-29 23:18:59 +00:00
|
|
|
Config.to_clean = {}
|
2022-12-01 10:06:44 +00:00
|
|
|
for pack, dir_type in pairs(installed) do
|
|
|
|
table.insert(Config.to_clean, {
|
|
|
|
name = pack,
|
2022-12-03 14:48:06 +00:00
|
|
|
dir = Config.options.root .. "/" .. pack,
|
2022-12-01 10:06:44 +00:00
|
|
|
_ = {
|
2022-12-25 20:07:30 +00:00
|
|
|
kind = "clean",
|
2022-12-01 10:06:44 +00:00
|
|
|
installed = true,
|
|
|
|
is_symlink = dir_type == "link",
|
|
|
|
is_local = dir_type == "link",
|
|
|
|
},
|
|
|
|
})
|
2022-11-25 21:48:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-15 08:28:56 +01:00
|
|
|
---@param path string
|
|
|
|
function M.local_spec(path)
|
|
|
|
local file = vim.secure.read(path)
|
2024-05-26 15:43:52 +01:00
|
|
|
if file then
|
|
|
|
return loadstring(file)()
|
|
|
|
end
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
2024-06-16 06:09:33 +01:00
|
|
|
---@return LazySpecImport?
|
2024-06-15 08:28:56 +01:00
|
|
|
function M.find_local_spec()
|
|
|
|
if not Config.options.local_spec then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local path = vim.uv.cwd()
|
|
|
|
while path ~= "" do
|
|
|
|
local file = path .. "/" .. M.LOCAL_SPEC
|
|
|
|
if vim.fn.filereadable(file) == 1 then
|
2024-06-16 06:09:33 +01:00
|
|
|
return {
|
|
|
|
name = vim.fn.fnamemodify(file, ":~:."),
|
|
|
|
import = function()
|
|
|
|
local data = vim.secure.read(file)
|
|
|
|
if data then
|
|
|
|
return loadstring(data)()
|
|
|
|
end
|
|
|
|
return {}
|
|
|
|
end,
|
|
|
|
}
|
2024-06-15 08:28:56 +01:00
|
|
|
end
|
|
|
|
local p = vim.fn.fnamemodify(path, ":h")
|
|
|
|
if p == path then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
path = p
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-25 21:48:17 +00:00
|
|
|
function M.load()
|
2023-01-11 22:07:58 +00:00
|
|
|
M.loading = true
|
2022-11-25 21:48:17 +00:00
|
|
|
-- load specs
|
2022-11-29 23:18:59 +00:00
|
|
|
Util.track("spec")
|
2023-01-02 08:44:09 +00:00
|
|
|
Config.spec = Spec.new()
|
2024-06-15 08:28:56 +01:00
|
|
|
|
2024-06-16 06:09:33 +01:00
|
|
|
local specs = {
|
2024-06-22 21:18:26 +01:00
|
|
|
---@diagnostic disable-next-line: param-type-mismatch
|
2024-05-26 15:43:52 +01:00
|
|
|
vim.deepcopy(Config.options.spec),
|
2024-06-16 06:09:33 +01:00
|
|
|
}
|
|
|
|
specs[#specs + 1] = M.find_local_spec()
|
|
|
|
specs[#specs + 1] = { "folke/lazy.nvim" }
|
|
|
|
|
|
|
|
Config.spec:parse(specs)
|
2022-12-01 15:28:25 +00:00
|
|
|
|
2022-12-28 23:49:38 +00:00
|
|
|
-- override some lazy props
|
2023-01-02 08:44:09 +00:00
|
|
|
local lazy = Config.spec.plugins["lazy.nvim"]
|
2023-01-03 09:34:53 +00:00
|
|
|
if lazy then
|
|
|
|
lazy.lazy = true
|
|
|
|
lazy.dir = Config.me
|
|
|
|
lazy.config = function()
|
|
|
|
error("lazy config should not be called")
|
|
|
|
end
|
|
|
|
lazy._.loaded = {}
|
2022-12-28 23:49:38 +00:00
|
|
|
end
|
2022-12-01 15:28:25 +00:00
|
|
|
|
2022-12-02 16:02:25 +00:00
|
|
|
local existing = Config.plugins
|
2023-01-02 08:44:09 +00:00
|
|
|
Config.plugins = Config.spec.plugins
|
2022-12-02 16:02:25 +00:00
|
|
|
-- copy state. This wont do anything during startup
|
|
|
|
for name, plugin in pairs(existing) do
|
|
|
|
if Config.plugins[name] then
|
2023-01-17 12:55:04 +00:00
|
|
|
local dep = Config.plugins[name]._.dep
|
2024-06-22 21:18:26 +01:00
|
|
|
local frags = Config.plugins[name]._.frags
|
2022-12-02 16:02:25 +00:00
|
|
|
Config.plugins[name]._ = plugin._
|
2023-01-17 12:55:04 +00:00
|
|
|
Config.plugins[name]._.dep = dep
|
2024-06-22 21:18:26 +01:00
|
|
|
Config.plugins[name]._.frags = frags
|
2022-12-02 16:02:25 +00:00
|
|
|
end
|
|
|
|
end
|
2022-11-29 23:18:59 +00:00
|
|
|
Util.track()
|
2022-11-25 21:48:17 +00:00
|
|
|
|
|
|
|
Util.track("state")
|
|
|
|
M.update_state()
|
|
|
|
Util.track()
|
2023-01-11 22:07:58 +00:00
|
|
|
M.loading = false
|
2023-05-25 07:09:19 +01:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazyPlugins", modeline = false })
|
2022-11-25 21:48:17 +00:00
|
|
|
end
|
|
|
|
|
2022-12-02 08:22:15 +00:00
|
|
|
-- Finds the plugin that has this path
|
|
|
|
---@param path string
|
|
|
|
function M.find(path)
|
2023-01-02 13:35:36 +00:00
|
|
|
if not Config.spec then
|
|
|
|
return
|
|
|
|
end
|
2022-12-26 22:41:19 +00:00
|
|
|
local lua = path:find("/lua/", 1, true)
|
2022-12-16 12:06:30 +00:00
|
|
|
if lua then
|
|
|
|
local name = path:sub(1, lua - 1)
|
|
|
|
local slash = name:reverse():find("/", 1, true)
|
|
|
|
if slash then
|
|
|
|
name = name:sub(#name - slash + 2)
|
2023-01-02 14:27:01 +00:00
|
|
|
return name and Config.plugins[name] or Config.spec.plugins[name] or nil
|
2022-12-16 12:06:30 +00:00
|
|
|
end
|
|
|
|
end
|
2022-12-02 08:22:15 +00:00
|
|
|
end
|
|
|
|
|
2023-01-03 21:50:14 +00:00
|
|
|
---@param plugin LazyPlugin
|
|
|
|
function M.has_errors(plugin)
|
|
|
|
for _, task in ipairs(plugin._.tasks or {}) do
|
|
|
|
if task.error then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2023-10-16 22:04:57 +01:00
|
|
|
-- Merges super values or runs the values function to override values or return new ones.
|
|
|
|
-- Values are cached for performance.
|
2023-01-12 12:07:51 +00:00
|
|
|
-- Used for opts, cmd, event, ft and keys
|
|
|
|
---@param plugin LazyPlugin
|
|
|
|
---@param prop string
|
|
|
|
---@param is_list? boolean
|
|
|
|
function M.values(plugin, prop, is_list)
|
2023-10-16 14:05:16 +01:00
|
|
|
if not plugin[prop] then
|
|
|
|
return {}
|
|
|
|
end
|
2023-10-16 21:34:44 +01:00
|
|
|
plugin._.cache = plugin._.cache or {}
|
2023-10-16 14:05:16 +01:00
|
|
|
local key = prop .. (is_list and "_list" or "")
|
2023-10-16 21:34:44 +01:00
|
|
|
if plugin._.cache[key] == nil then
|
|
|
|
plugin._.cache[key] = M._values(plugin, plugin, prop, is_list)
|
2023-10-16 14:05:16 +01:00
|
|
|
end
|
2023-10-16 21:34:44 +01:00
|
|
|
return plugin._.cache[key]
|
2023-10-16 14:05:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Merges super values or runs the values function to override values or return new ones
|
|
|
|
-- Used for opts, cmd, event, ft and keys
|
2023-10-16 21:34:44 +01:00
|
|
|
---@param root LazyPlugin
|
2023-10-16 14:05:16 +01:00
|
|
|
---@param plugin LazyPlugin
|
|
|
|
---@param prop string
|
|
|
|
---@param is_list? boolean
|
2023-10-16 21:34:44 +01:00
|
|
|
function M._values(root, plugin, prop, is_list)
|
|
|
|
if not plugin[prop] then
|
|
|
|
return {}
|
|
|
|
end
|
2024-06-22 21:18:26 +01:00
|
|
|
local super = getmetatable(plugin)
|
2023-01-12 12:07:51 +00:00
|
|
|
---@type table
|
2024-06-22 21:18:26 +01:00
|
|
|
local ret = super and M._values(root, super.__index, prop, is_list) or {}
|
2023-01-12 12:07:51 +00:00
|
|
|
local values = rawget(plugin, prop)
|
|
|
|
|
|
|
|
if not values then
|
|
|
|
return ret
|
|
|
|
elseif type(values) == "function" then
|
2023-10-16 21:34:44 +01:00
|
|
|
ret = values(root, ret) or ret
|
2023-01-12 12:07:51 +00:00
|
|
|
return type(ret) == "table" and ret or { ret }
|
|
|
|
end
|
|
|
|
|
|
|
|
values = type(values) == "table" and values or { values }
|
2024-06-07 08:02:52 +01:00
|
|
|
if is_list then
|
|
|
|
return Util.extend(ret, values)
|
|
|
|
else
|
|
|
|
---@type {path:string[], list:any[]}[]
|
|
|
|
local lists = {}
|
2024-06-22 21:18:26 +01:00
|
|
|
---@diagnostic disable-next-line: no-unknown
|
2024-06-07 08:02:52 +01:00
|
|
|
for _, key in ipairs(plugin[prop .. "_extend"] or {}) do
|
|
|
|
local path = vim.split(key, ".", { plain = true })
|
|
|
|
local r = Util.key_get(ret, path)
|
|
|
|
local v = Util.key_get(values, path)
|
|
|
|
if type(r) == "table" and type(v) == "table" then
|
|
|
|
lists[key] = { path = path, list = {} }
|
|
|
|
vim.list_extend(lists[key].list, r)
|
|
|
|
vim.list_extend(lists[key].list, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local t = Util.merge(ret, values)
|
|
|
|
for _, list in pairs(lists) do
|
|
|
|
Util.key_set(t, list.path, list.list)
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
2023-01-12 12:07:51 +00:00
|
|
|
end
|
|
|
|
|
2022-11-25 21:48:17 +00:00
|
|
|
return M
|