Merge branch 'main' into main

This commit is contained in:
hoofcushion 2025-01-06 19:16:00 +08:00 committed by GitHub
commit 03b894ee5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1855 additions and 140 deletions

View file

@ -41,6 +41,10 @@ M.defaults = {
rate = 2,
duration = 5 * 1000, -- in ms
},
-- Time in seconds to wait before running fetch again for a plugin.
-- Repeated update/check operations will not run again until this
-- cooldown period has passed.
cooldown = 0,
},
pkg = {
enabled = true,
@ -63,7 +67,9 @@ M.defaults = {
hererocks = nil,
},
dev = {
---@type string | fun(plugin: LazyPlugin): string directory where you store your local plugin projects
-- Directory where you store your local plugin projects. If a function is used,
-- the plugin directory (e.g. `~/projects/plugin-name`) must be returned.
---@type string | fun(plugin: LazyPlugin): string
path = "~/projects",
---@type string[] plugins that match these patterns will use your local versions instead of being fetched from GitHub
patterns = {}, -- For example {"folke"}
@ -90,6 +96,7 @@ M.defaults = {
icons = {
cmd = "",
config = "",
debug = "",
event = "",
favorite = "",
ft = "",
@ -212,7 +219,7 @@ M.defaults = {
enabled = true,
root = vim.fn.stdpath("state") .. "/lazy/readme",
files = { "README.md", "lua/**/README.md" },
-- only generate markdown helptags for plugins that dont have docs
-- only generate markdown helptags for plugins that don't have docs
skip_if_doc_exists = true,
},
state = vim.fn.stdpath("state") .. "/lazy/state.json", -- state info for checker and other things
@ -235,7 +242,7 @@ function M.hererocks()
return M.options.rocks.hererocks
end
M.version = "11.13.5" -- x-release-please-version
M.version = "11.16.2" -- x-release-please-version
M.ns = vim.api.nvim_create_namespace("lazy")

View file

@ -350,7 +350,9 @@ function M._load(plugin, reason, opts)
Util.track({ plugin = plugin.name, start = reason.start })
Handler.disable(plugin)
M.add_to_rtp(plugin)
if not plugin.virtual then
M.add_to_rtp(plugin)
end
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
M.add_to_luapath(plugin)
@ -362,7 +364,9 @@ function M._load(plugin, reason, opts)
end, "Failed to load deps for " .. plugin.name)
end
M.packadd(plugin.dir)
if not plugin.virtual then
M.packadd(plugin.dir)
end
if plugin.config or plugin.opts then
M.config(plugin)
end
@ -502,8 +506,11 @@ function M.add_to_luapath(plugin)
local root = Config.options.rocks.root .. "/" .. plugin.name
local path = root .. "/share/lua/5.1"
local cpath = root .. "/lib/lua/5.1"
local cpath2 = root .. "/lib64/lua/5.1"
package.path = package.path .. ";" .. path .. "/?.lua;" .. path .. "/?/init.lua;"
package.cpath = package.cpath .. ";" .. cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
package.cpath = package.cpath .. ";" .. cpath2 .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
end
function M.source(path)

View file

@ -213,6 +213,8 @@ function M:_rebuild(name)
plugin.dir = super.dir
if plugin.dir then
plugin.dir = Util.norm(plugin.dir)
elseif super.virtual then
plugin.dir = Util.norm("/dev/null/" .. plugin.name)
else
if plugin.dev == nil and plugin.url then
for _, pattern in ipairs(Config.options.dev.patterns) do
@ -303,7 +305,11 @@ function M:fix_disabled()
for _, plugin in pairs(self.plugins) do
if plugin.enabled == false or (type(plugin.enabled) == "function" and not plugin.enabled()) then
changes = changes + 1
self:disable(plugin)
if plugin.optional then
self:del(plugin.name)
else
self:disable(plugin)
end
end
end
self:rebuild()

View file

@ -146,33 +146,43 @@ function Spec:import(spec)
local imported = 0
---@type (string|(fun():LazyPluginSpec))[]
---@type {modname: string, load: fun():(LazyPluginSpec?, string?)}[]
local modspecs = {}
if type(import) == "string" then
Util.lsmod(import, function(modname, modpath)
modspecs[#modspecs + 1] = modname
package.preload[modname] = function()
return loadfile(modpath)()
end
modspecs[#modspecs + 1] = {
modname = modname,
load = function()
local mod, err = loadfile(modpath)
if mod then
return mod()
else
return nil, err
end
end,
}
end)
table.sort(modspecs, function(a, b)
return a.modname < b.modname
end)
table.sort(modspecs)
else
modspecs = { spec.import }
modspecs = { { modname = import_name, load = spec.import } }
end
for _, modspec in ipairs(modspecs) do
imported = imported + 1
local modname = type(modspec) == "string" and modspec or import_name
local modname = modspec.modname
Util.track({ import = modname })
self.importing = modname
-- unload the module so we get a clean slate
---@diagnostic disable-next-line: no-unknown
package.loaded[modname] = nil
Util.try(function()
local mod = type(modspec) == "function" and modspec() or require(modspec)
if type(mod) ~= "table" then
self.importing = nil
local mod, err = modspec.load()
if err then
self:error("Failed to load `" .. modname .. "`:\n" .. err)
elseif type(mod) ~= "table" then
return self:error(
"Invalid spec module: `"
.. modname
@ -180,21 +190,20 @@ function Spec:import(spec)
.. type(mod)
.. "` was returned instead"
)
else
self:normalize(mod)
end
self:normalize(mod)
self.importing = nil
Util.track()
end, {
msg = "Failed to load `" .. modname .. "`",
on_error = function(msg)
self:error(msg)
self.importing = nil
Util.track()
end,
})
self.importing = nil
Util.track()
end
if imported == 0 then
self:error("No specs found for module " .. spec.import)
self:error("No specs found for module " .. vim.inspect(spec.import))
end
end
@ -228,12 +237,15 @@ function M.update_state()
or plugin.cmd
plugin.lazy = lazy and true or false
end
if plugin.dir:find(Config.options.root, 1, true) == 1 then
if plugin.virtual then
plugin._.is_local = true
plugin._.installed = true -- local plugins are managed by the user
elseif plugin.dir:find(Config.options.root, 1, true) == 1 then
plugin._.installed = installed[plugin.name] ~= nil
installed[plugin.name] = nil
else
plugin._.is_local = true
plugin._.installed = true -- local plugins are managed by the user
plugin._.installed = vim.fn.isdirectory(plugin.dir) == 1
end
end

View file

@ -270,7 +270,7 @@ function M.get_unloaded_rtp(modname, opts)
local Config = require("lazy.core.config")
if Config.spec then
for _, plugin in pairs(Config.spec.plugins) do
if not (plugin._.loaded or plugin.module == false) then
if not (plugin._.loaded or plugin.module == false or plugin.virtual) then
if norm == M.normname(plugin.name) then
table.insert(rtp, 1, plugin.dir)
else