mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-20 21:36:45 +00:00
Merge branch 'main' into main
This commit is contained in:
commit
03b894ee5d
18 changed files with 1855 additions and 140 deletions
File diff suppressed because it is too large
Load diff
|
@ -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")
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -131,7 +131,8 @@ function M.colors(opts)
|
|||
{ "---", "---", "---" },
|
||||
}
|
||||
Util.foreach(require(opts.modname).colors, function(group, link)
|
||||
lines[#lines + 1] = { "**" .. opts.name .. group .. "**", "***" .. link .. "***", comments[group] or "" }
|
||||
link = type(link) == "table" and "`" .. vim.inspect(link):gsub("%s+", " ") .. "`" or "***" .. link .. "***"
|
||||
lines[#lines + 1] = { "**" .. opts.name .. group .. "**", link, comments[group] or "" }
|
||||
end)
|
||||
return { content = M.table(lines) }
|
||||
end
|
||||
|
|
|
@ -80,6 +80,7 @@ function M.install(opts)
|
|||
opts = M.opts(opts, { mode = "install" })
|
||||
return M.run({
|
||||
pipeline = {
|
||||
"plugin.exists",
|
||||
"git.clone",
|
||||
{ "git.checkout", lockfile = opts.lockfile },
|
||||
"plugin.docs",
|
||||
|
@ -108,6 +109,7 @@ function M.update(opts)
|
|||
opts = M.opts(opts, { mode = "update" })
|
||||
return M.run({
|
||||
pipeline = {
|
||||
"plugin.exists",
|
||||
"git.origin",
|
||||
"git.branch",
|
||||
"git.fetch",
|
||||
|
@ -147,6 +149,7 @@ function M.check(opts)
|
|||
opts = opts or {}
|
||||
return M.run({
|
||||
pipeline = {
|
||||
"plugin.exists",
|
||||
{ "git.origin", check = true },
|
||||
"git.fetch",
|
||||
"git.status",
|
||||
|
|
|
@ -40,6 +40,15 @@ function throttle.wait()
|
|||
end
|
||||
end
|
||||
|
||||
---@param plugin LazyPlugin
|
||||
local function cooldown(plugin)
|
||||
if not plugin._.last_check then
|
||||
return false
|
||||
end
|
||||
local delta = (vim.uv.now() - plugin._.last_check) / 1000
|
||||
return delta < Config.options.git.cooldown
|
||||
end
|
||||
|
||||
---@type table<string, LazyTaskDef>
|
||||
local M = {}
|
||||
|
||||
|
@ -266,7 +275,7 @@ M.status = {
|
|||
-- fetches all needed origin branches
|
||||
M.fetch = {
|
||||
skip = function(plugin)
|
||||
return not plugin._.installed or plugin._.is_local
|
||||
return not plugin._.installed or plugin._.is_local or cooldown(plugin)
|
||||
end,
|
||||
|
||||
---@async
|
||||
|
@ -287,6 +296,11 @@ M.fetch = {
|
|||
self:spawn("git", {
|
||||
args = args,
|
||||
cwd = self.plugin.dir,
|
||||
on_exit = function(ok)
|
||||
if ok then
|
||||
self.plugin._.last_check = vim.uv.now()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
@ -321,7 +335,7 @@ M.checkout = {
|
|||
end
|
||||
end
|
||||
|
||||
-- dont run checkout if target is already reached.
|
||||
-- don't run checkout if target is already reached.
|
||||
-- unless we just cloned, since then we won't have any data yet
|
||||
if Git.eq(info, target) and info.branch == target.branch then
|
||||
self.plugin._.updated = {
|
||||
|
|
|
@ -87,14 +87,25 @@ M.build = {
|
|||
|
||||
M.docs = {
|
||||
skip = function(plugin)
|
||||
return not plugin._.dirty
|
||||
return not plugin._.is_local and not plugin._.dirty
|
||||
end,
|
||||
run = function(self)
|
||||
local docs = self.plugin.dir .. "/doc/"
|
||||
local docs = self.plugin.dir .. "/doc"
|
||||
if Util.file_exists(docs) then
|
||||
self:log(vim.api.nvim_cmd({ cmd = "helptags", args = { docs } }, { output = true }))
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
M.exists = {
|
||||
skip = function(plugin)
|
||||
return not plugin._.is_local or plugin.virtual
|
||||
end,
|
||||
run = function(self)
|
||||
if not Util.file_exists(self.plugin.dir) then
|
||||
self:error("Local plugin does not exist at `" .. self.plugin.dir .. "`")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
||||
|
|
|
@ -172,7 +172,6 @@ function M.build(task)
|
|||
root,
|
||||
"--server",
|
||||
Config.options.rocks.server,
|
||||
"--dev",
|
||||
"--lua-version",
|
||||
"5.1",
|
||||
"install", -- use install so that we can make use of pre-built rocks
|
||||
|
@ -225,9 +224,10 @@ end
|
|||
---@return table?
|
||||
function M.parse(file)
|
||||
local ret = {}
|
||||
return pcall(function()
|
||||
loadfile(file, "t", ret)()
|
||||
local ok = pcall(function()
|
||||
loadfile(file, nil, ret)()
|
||||
end) and ret or nil
|
||||
return ok and ret or nil
|
||||
end
|
||||
|
||||
---@param plugin LazyPlugin
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
---@field tasks? LazyTask[]
|
||||
---@field updated? {from:string, to:string}
|
||||
---@field updates? {from:GitInfo, to:GitInfo}
|
||||
---@field last_check? number
|
||||
---@field working? boolean
|
||||
---@field pkg? LazyPkg
|
||||
|
||||
|
@ -59,6 +60,7 @@
|
|||
---@field priority? number Only useful for lazy=false plugins to force loading certain plugins first. Default priority is 50
|
||||
---@field dev? boolean If set, then link to the respective folder under your ~/projects
|
||||
---@field rocks? string[]
|
||||
---@field virtual? boolean virtual plugins won't be installed or added to the rtp.
|
||||
|
||||
---@class LazyPlugin: LazyPluginBase,LazyPluginHandlers,LazyPluginHooks,LazyPluginRef
|
||||
---@field dependencies? string[]
|
||||
|
@ -73,6 +75,8 @@
|
|||
---@field module? false
|
||||
|
||||
---@class LazyPluginSpec: LazyPluginBase,LazyPluginSpecHandlers,LazyPluginHooks,LazyPluginRef
|
||||
---@field name? string display name and name used for plugin config files
|
||||
---@field dir? string
|
||||
---@field dependencies? string|string[]|LazyPluginSpec[]
|
||||
---@field specs? string|string[]|LazyPluginSpec[]
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ end
|
|||
---@return string, string[]
|
||||
function M.parse(args)
|
||||
local parts = vim.split(vim.trim(args), "%s+")
|
||||
if parts[1]:find("Lazy") then
|
||||
if vim.startswith("Lazy", parts[1]) then
|
||||
table.remove(parts, 1)
|
||||
end
|
||||
if args:sub(-1) == " " then
|
||||
|
|
|
@ -144,8 +144,6 @@ function M:title()
|
|||
if mode.name == "home" then
|
||||
if self.view.state.mode == "home" then
|
||||
title = " lazy.nvim " .. Config.options.ui.icons.lazy
|
||||
else
|
||||
title = " lazy.nvim (H) "
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -761,7 +759,7 @@ function M:debug()
|
|||
---@type string[]
|
||||
plugins = vim.tbl_values(plugins)
|
||||
table.sort(plugins)
|
||||
self:append("● ", "LazySpecial", { indent = 2 })
|
||||
self:append(Config.options.ui.icons.debug, "LazySpecial", { indent = 2 })
|
||||
if handler_type == "keys" then
|
||||
for k, v in pairs(Config.plugins[plugins[1]]._.handlers.keys) do
|
||||
if k == value then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue