mirror of https://github.com/folke/lazy.nvim.git
feat!: lazy now handles the full startup sequence (`vim.go.loadplugins=false`)
This commit is contained in:
parent
ad0b4caa64
commit
ec2f432a84
|
@ -11,27 +11,24 @@ M.defaults = {
|
||||||
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
-- version = "*", -- enable this to try installing the latest stable versions of plugins
|
||||||
},
|
},
|
||||||
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
|
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
|
||||||
concurrency = nil, -- set to a number to limit the maximum amount of concurrent tasks
|
concurrency = nil, ---@type number limit the maximum amount of concurrent tasks
|
||||||
git = {
|
git = {
|
||||||
-- defaults for `Lazy log`
|
-- defaults for the `Lazy log` command
|
||||||
-- log = { "-10" }, -- last 10 commits
|
-- log = { "-10" }, -- show the last 10 commits
|
||||||
log = { "--since=1 days ago" }, -- commits from the last 3 days
|
log = { "--since=1 days ago" }, -- show commits from the last 3 days
|
||||||
timeout = 120, -- processes taking over 2 minutes will be killed
|
timeout = 120, -- kill processes that take more than 2 minutes
|
||||||
url_format = "https://github.com/%s.git",
|
url_format = "https://github.com/%s.git",
|
||||||
},
|
},
|
||||||
-- Any plugin spec that contains one of the patterns will use your
|
|
||||||
-- local repo in the projects folder instead of fetchig it from github
|
|
||||||
-- Mostly useful for plugin developers.
|
|
||||||
dev = {
|
dev = {
|
||||||
path = vim.fn.expand("~/projects"), -- the path where you store your projects
|
-- directory where you store your local plugin projects
|
||||||
---@type string[]
|
path = vim.fn.expand("~/projects"),
|
||||||
|
---@type string[] plugins that match these patterns will use your local versions instead of being fetched from GitHub
|
||||||
patterns = {}, -- For example {"folke"}
|
patterns = {}, -- For example {"folke"}
|
||||||
},
|
},
|
||||||
install = {
|
install = {
|
||||||
-- install missing plugins on startup. This doesn't increase startup time.
|
-- install missing plugins on startup. This doesn't increase startup time.
|
||||||
missing = true,
|
missing = true,
|
||||||
-- try to load one of the colorschemes in this list when starting an install during startup
|
-- try to load one of these colorschemes when starting an installation during startup
|
||||||
-- the first colorscheme that is found will be loaded
|
|
||||||
colorscheme = { "habamax" },
|
colorscheme = { "habamax" },
|
||||||
},
|
},
|
||||||
ui = {
|
ui = {
|
||||||
|
@ -53,17 +50,30 @@ M.defaults = {
|
||||||
throttle = 20, -- how frequently should the ui process render events
|
throttle = 20, -- how frequently should the ui process render events
|
||||||
},
|
},
|
||||||
checker = {
|
checker = {
|
||||||
-- lazy can automatically check for updates
|
-- automcatilly check for plugin updates
|
||||||
enabled = false,
|
enabled = false,
|
||||||
concurrency = nil, ---@type number? set to 1 to very slowly check for updates
|
concurrency = nil, ---@type number? set to 1 to check for updates very slowly
|
||||||
notify = true, -- get a notification if new updates are found
|
notify = true, -- get a notification when new updates are found
|
||||||
frequency = 3600, -- every hour
|
frequency = 3600, -- check for updates every hour
|
||||||
},
|
},
|
||||||
performance = {
|
performance = {
|
||||||
---@type LazyCacheConfig
|
---@type LazyCacheConfig
|
||||||
cache = nil,
|
cache = nil,
|
||||||
reset_packpath = true, -- packpath will be reset to nothing. This will improver startup time.
|
reset_packpath = true, -- reset the package path to improve startup time
|
||||||
reset_rtp = true, -- the runtime path will be reset to $VIMRUNTIME and your config directory
|
rtp = {
|
||||||
|
reset = true, -- reset the runtime path to $VIMRUNTIME and your config directory
|
||||||
|
---@type string[] list any plugins you want to disable here
|
||||||
|
disabled_plugins = {
|
||||||
|
-- "gzip",
|
||||||
|
-- "matchit",
|
||||||
|
-- "matchparen",
|
||||||
|
-- "netrwPlugin",
|
||||||
|
-- "tarPlugin",
|
||||||
|
-- "tohtml",
|
||||||
|
-- "tutor",
|
||||||
|
-- "zipPlugin",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
debug = false,
|
debug = false,
|
||||||
}
|
}
|
||||||
|
@ -93,14 +103,13 @@ function M.setup(spec, opts)
|
||||||
if M.options.performance.reset_packpath then
|
if M.options.performance.reset_packpath then
|
||||||
vim.go.packpath = ""
|
vim.go.packpath = ""
|
||||||
end
|
end
|
||||||
if M.options.performance.reset_rtp then
|
if M.options.performance.rtp.reset then
|
||||||
local me = debug.getinfo(1, "S").source:sub(2)
|
local me = debug.getinfo(1, "S").source:sub(2)
|
||||||
me = vim.fn.fnamemodify(me, ":p:h:h:h:h")
|
me = vim.fn.fnamemodify(me, ":p:h:h:h:h")
|
||||||
vim.opt.rtp = {
|
vim.opt.rtp = {
|
||||||
"$VIMRUNTIME",
|
|
||||||
vim.fn.stdpath("config"),
|
|
||||||
me,
|
me,
|
||||||
vim.fn.stdpath("config") .. "/after",
|
vim.env.VIMRUNTIME,
|
||||||
|
vim.fn.stdpath("config"),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ end
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
---@param value string
|
---@param value string
|
||||||
function M:_add(plugin, value)
|
function M:_add(plugin, value)
|
||||||
Loader.ftdetect(plugin)
|
Loader.ftdetect(plugin.dir)
|
||||||
Event._add(self, plugin, value)
|
Event._add(self, plugin, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ local M = {}
|
||||||
---@type LazyPlugin[]
|
---@type LazyPlugin[]
|
||||||
M.loading = {}
|
M.loading = {}
|
||||||
M.init_done = false
|
M.init_done = false
|
||||||
|
---@type table<string,true>
|
||||||
|
M.disabled_rtp_plugins = {}
|
||||||
|
|
||||||
function M.setup()
|
function M.setup()
|
||||||
-- install missing plugins
|
-- install missing plugins
|
||||||
|
@ -31,11 +33,38 @@ function M.setup()
|
||||||
Handler.setup()
|
Handler.setup()
|
||||||
Util.track()
|
Util.track()
|
||||||
|
|
||||||
|
for _, file in ipairs(Config.options.performance.rtp.disabled_plugins) do
|
||||||
|
M.disabled_rtp_plugins[file] = true
|
||||||
|
end
|
||||||
|
|
||||||
-- autoload opt plugins
|
-- autoload opt plugins
|
||||||
table.insert(package.loaders, M.autoload)
|
table.insert(package.loaders, M.autoload)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.init_plugins()
|
-- Startup sequence
|
||||||
|
-- 1. load any start plugins and do init
|
||||||
|
function M.startup()
|
||||||
|
Util.track({ start = "startup" })
|
||||||
|
|
||||||
|
-- load plugins from rtp
|
||||||
|
Util.track({ start = "rtp plugins" })
|
||||||
|
for _, path in ipairs(vim.opt.rtp:get()) do
|
||||||
|
if not path:find("after/?$") then
|
||||||
|
M.source_runtime(path, "plugin")
|
||||||
|
M.ftdetect(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Util.track()
|
||||||
|
|
||||||
|
Util.track({ start = "start" })
|
||||||
|
for _, plugin in pairs(Config.plugins) do
|
||||||
|
-- load start plugin
|
||||||
|
if plugin.lazy == false then
|
||||||
|
M.load(plugin, { start = "start" })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Util.track()
|
||||||
|
|
||||||
Util.track({ start = "init" })
|
Util.track({ start = "init" })
|
||||||
for _, plugin in pairs(Config.plugins) do
|
for _, plugin in pairs(Config.plugins) do
|
||||||
-- run plugin init
|
-- run plugin init
|
||||||
|
@ -44,14 +73,22 @@ function M.init_plugins()
|
||||||
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
|
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
Util.track()
|
||||||
|
|
||||||
-- load start plugin
|
-- load after files
|
||||||
if plugin.lazy == false then
|
Util.track({ start = "after" })
|
||||||
M.load(plugin, { start = "startup" })
|
for _, path in ipairs(vim.opt.rtp:get()) do
|
||||||
|
if path:find("after/?$") then
|
||||||
|
M.source_runtime(path, "plugin")
|
||||||
|
else
|
||||||
|
M.source_runtime(path, "after/plugin")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Util.track()
|
Util.track()
|
||||||
|
|
||||||
M.init_done = true
|
M.init_done = true
|
||||||
|
Util.track()
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class Loader
|
---@class Loader
|
||||||
|
@ -84,21 +121,12 @@ function M.load(plugins, reason)
|
||||||
Handler.disable(plugin)
|
Handler.disable(plugin)
|
||||||
|
|
||||||
vim.opt.runtimepath:prepend(plugin.dir)
|
vim.opt.runtimepath:prepend(plugin.dir)
|
||||||
if not M.init_done then
|
|
||||||
local after = plugin.dir .. "/after"
|
|
||||||
-- only add the after directories during startup
|
|
||||||
-- afterwards we only source the runtime files in after
|
|
||||||
-- Check if it exists here, to prevent further rtp file checks during startup
|
|
||||||
if vim.loop.fs_stat(after) then
|
|
||||||
vim.opt.runtimepath:append(after)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if plugin.dependencies then
|
if plugin.dependencies then
|
||||||
M.load(plugin.dependencies, {})
|
M.load(plugin.dependencies, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
M.packadd(plugin)
|
M.packadd(plugin.dir)
|
||||||
if plugin.config then
|
if plugin.config then
|
||||||
Util.try(plugin.config, "Failed to run `config` for " .. plugin.name)
|
Util.try(plugin.config, "Failed to run `config` for " .. plugin.name)
|
||||||
end
|
end
|
||||||
|
@ -112,28 +140,29 @@ function M.load(plugins, reason)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param path string
|
||||||
function M.packadd(plugin)
|
function M.packadd(path)
|
||||||
|
M.source_runtime(path, "plugin")
|
||||||
|
M.ftdetect(path)
|
||||||
if M.init_done then
|
if M.init_done then
|
||||||
M.source_runtime(plugin.dir, "plugin")
|
M.source_runtime(path, "after/plugin")
|
||||||
M.ftdetect(plugin)
|
|
||||||
M.source_runtime(plugin.dir, "after/plugin")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param path string
|
||||||
function M.ftdetect(plugin)
|
function M.ftdetect(path)
|
||||||
vim.cmd("augroup filetypedetect")
|
vim.cmd("augroup filetypedetect")
|
||||||
M.source_runtime(plugin.dir, "ftdetect")
|
M.source_runtime(path, "ftdetect")
|
||||||
vim.cmd("augroup END")
|
vim.cmd("augroup END")
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param ... string
|
---@param ... string
|
||||||
function M.source_runtime(...)
|
function M.source_runtime(...)
|
||||||
local dir = table.concat({ ... }, "/")
|
local dir = table.concat({ ... }, "/")
|
||||||
Util.walk(dir, function(path, _, t)
|
Util.walk(dir, function(path, name, t)
|
||||||
local ext = path:sub(-3)
|
local ext = name:sub(-3)
|
||||||
if t == "file" and (ext == "lua" or ext == "vim") then
|
name = name:sub(1, -5)
|
||||||
|
if t == "file" and (ext == "lua" or ext == "vim") and not M.disabled_rtp_plugins[name] then
|
||||||
Util.track({ runtime = path })
|
Util.track({ runtime = path })
|
||||||
vim.cmd("silent source " .. path)
|
vim.cmd("silent source " .. path)
|
||||||
Util.track()
|
Util.track()
|
||||||
|
|
|
@ -7,6 +7,8 @@ function M.setup(spec, opts)
|
||||||
vim.notify("Re-sourcing your config is not supported with lazy.nvim", vim.log.levels.WARN, { title = "lazy.nvim" })
|
vim.notify("Re-sourcing your config is not supported with lazy.nvim", vim.log.levels.WARN, { title = "lazy.nvim" })
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
vim.go.loadplugins = false
|
||||||
|
|
||||||
vim.g.lazy_did_setup = true
|
vim.g.lazy_did_setup = true
|
||||||
local start = vim.loop.hrtime()
|
local start = vim.loop.hrtime()
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ function M.setup(spec, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- load plugins with lazy=false or Plugin.init
|
-- load plugins with lazy=false or Plugin.init
|
||||||
Loader.init_plugins()
|
Loader.startup()
|
||||||
|
|
||||||
-- all done!
|
-- all done!
|
||||||
vim.cmd("do User LazyDone")
|
vim.cmd("do User LazyDone")
|
||||||
|
|
Loading…
Reference in New Issue