Skip to content

Commit ec2f432

Browse files
committed
feat!: lazy now handles the full startup sequence (vim.go.loadplugins=false)
1 parent ad0b4ca commit ec2f432

File tree

4 files changed

+89
-49
lines changed

4 files changed

+89
-49
lines changed

lua/lazy/core/config.lua

+31-22
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,24 @@ M.defaults = {
1111
-- version = "*", -- enable this to try installing the latest stable versions of plugins
1212
},
1313
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
14-
concurrency = nil, -- set to a number to limit the maximum amount of concurrent tasks
14+
concurrency = nil, ---@type number limit the maximum amount of concurrent tasks
1515
git = {
16-
-- defaults for `Lazy log`
17-
-- log = { "-10" }, -- last 10 commits
18-
log = { "--since=1 days ago" }, -- commits from the last 3 days
19-
timeout = 120, -- processes taking over 2 minutes will be killed
16+
-- defaults for the `Lazy log` command
17+
-- log = { "-10" }, -- show the last 10 commits
18+
log = { "--since=1 days ago" }, -- show commits from the last 3 days
19+
timeout = 120, -- kill processes that take more than 2 minutes
2020
url_format = "https://github.com/%s.git",
2121
},
22-
-- Any plugin spec that contains one of the patterns will use your
23-
-- local repo in the projects folder instead of fetchig it from github
24-
-- Mostly useful for plugin developers.
2522
dev = {
26-
path = vim.fn.expand("~/projects"), -- the path where you store your projects
27-
---@type string[]
23+
-- directory where you store your local plugin projects
24+
path = vim.fn.expand("~/projects"),
25+
---@type string[] plugins that match these patterns will use your local versions instead of being fetched from GitHub
2826
patterns = {}, -- For example {"folke"}
2927
},
3028
install = {
3129
-- install missing plugins on startup. This doesn't increase startup time.
3230
missing = true,
33-
-- try to load one of the colorschemes in this list when starting an install during startup
34-
-- the first colorscheme that is found will be loaded
31+
-- try to load one of these colorschemes when starting an installation during startup
3532
colorscheme = { "habamax" },
3633
},
3734
ui = {
@@ -53,17 +50,30 @@ M.defaults = {
5350
throttle = 20, -- how frequently should the ui process render events
5451
},
5552
checker = {
56-
-- lazy can automatically check for updates
53+
-- automcatilly check for plugin updates
5754
enabled = false,
58-
concurrency = nil, ---@type number? set to 1 to very slowly check for updates
59-
notify = true, -- get a notification if new updates are found
60-
frequency = 3600, -- every hour
55+
concurrency = nil, ---@type number? set to 1 to check for updates very slowly
56+
notify = true, -- get a notification when new updates are found
57+
frequency = 3600, -- check for updates every hour
6158
},
6259
performance = {
6360
---@type LazyCacheConfig
6461
cache = nil,
65-
reset_packpath = true, -- packpath will be reset to nothing. This will improver startup time.
66-
reset_rtp = true, -- the runtime path will be reset to $VIMRUNTIME and your config directory
62+
reset_packpath = true, -- reset the package path to improve startup time
63+
rtp = {
64+
reset = true, -- reset the runtime path to $VIMRUNTIME and your config directory
65+
---@type string[] list any plugins you want to disable here
66+
disabled_plugins = {
67+
-- "gzip",
68+
-- "matchit",
69+
-- "matchparen",
70+
-- "netrwPlugin",
71+
-- "tarPlugin",
72+
-- "tohtml",
73+
-- "tutor",
74+
-- "zipPlugin",
75+
},
76+
},
6777
},
6878
debug = false,
6979
}
@@ -93,14 +103,13 @@ function M.setup(spec, opts)
93103
if M.options.performance.reset_packpath then
94104
vim.go.packpath = ""
95105
end
96-
if M.options.performance.reset_rtp then
106+
if M.options.performance.rtp.reset then
97107
local me = debug.getinfo(1, "S").source:sub(2)
98108
me = vim.fn.fnamemodify(me, ":p:h:h:h:h")
99109
vim.opt.rtp = {
100-
"$VIMRUNTIME",
101-
vim.fn.stdpath("config"),
102110
me,
103-
vim.fn.stdpath("config") .. "/after",
111+
vim.env.VIMRUNTIME,
112+
vim.fn.stdpath("config"),
104113
}
105114
end
106115

lua/lazy/core/handler/ft.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313
---@param plugin LazyPlugin
1414
---@param value string
1515
function M:_add(plugin, value)
16-
Loader.ftdetect(plugin)
16+
Loader.ftdetect(plugin.dir)
1717
Event._add(self, plugin, value)
1818
end
1919

lua/lazy/core/loader.lua

+54-25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ local M = {}
77
---@type LazyPlugin[]
88
M.loading = {}
99
M.init_done = false
10+
---@type table<string,true>
11+
M.disabled_rtp_plugins = {}
1012

1113
function M.setup()
1214
-- install missing plugins
@@ -31,11 +33,38 @@ function M.setup()
3133
Handler.setup()
3234
Util.track()
3335

36+
for _, file in ipairs(Config.options.performance.rtp.disabled_plugins) do
37+
M.disabled_rtp_plugins[file] = true
38+
end
39+
3440
-- autoload opt plugins
3541
table.insert(package.loaders, M.autoload)
3642
end
3743

38-
function M.init_plugins()
44+
-- Startup sequence
45+
-- 1. load any start plugins and do init
46+
function M.startup()
47+
Util.track({ start = "startup" })
48+
49+
-- load plugins from rtp
50+
Util.track({ start = "rtp plugins" })
51+
for _, path in ipairs(vim.opt.rtp:get()) do
52+
if not path:find("after/?$") then
53+
M.source_runtime(path, "plugin")
54+
M.ftdetect(path)
55+
end
56+
end
57+
Util.track()
58+
59+
Util.track({ start = "start" })
60+
for _, plugin in pairs(Config.plugins) do
61+
-- load start plugin
62+
if plugin.lazy == false then
63+
M.load(plugin, { start = "start" })
64+
end
65+
end
66+
Util.track()
67+
3968
Util.track({ start = "init" })
4069
for _, plugin in pairs(Config.plugins) do
4170
-- run plugin init
@@ -44,14 +73,22 @@ function M.init_plugins()
4473
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
4574
Util.track()
4675
end
76+
end
77+
Util.track()
4778

48-
-- load start plugin
49-
if plugin.lazy == false then
50-
M.load(plugin, { start = "startup" })
79+
-- load after files
80+
Util.track({ start = "after" })
81+
for _, path in ipairs(vim.opt.rtp:get()) do
82+
if path:find("after/?$") then
83+
M.source_runtime(path, "plugin")
84+
else
85+
M.source_runtime(path, "after/plugin")
5186
end
5287
end
5388
Util.track()
89+
5490
M.init_done = true
91+
Util.track()
5592
end
5693

5794
---@class Loader
@@ -84,21 +121,12 @@ function M.load(plugins, reason)
84121
Handler.disable(plugin)
85122

86123
vim.opt.runtimepath:prepend(plugin.dir)
87-
if not M.init_done then
88-
local after = plugin.dir .. "/after"
89-
-- only add the after directories during startup
90-
-- afterwards we only source the runtime files in after
91-
-- Check if it exists here, to prevent further rtp file checks during startup
92-
if vim.loop.fs_stat(after) then
93-
vim.opt.runtimepath:append(after)
94-
end
95-
end
96124

97125
if plugin.dependencies then
98126
M.load(plugin.dependencies, {})
99127
end
100128

101-
M.packadd(plugin)
129+
M.packadd(plugin.dir)
102130
if plugin.config then
103131
Util.try(plugin.config, "Failed to run `config` for " .. plugin.name)
104132
end
@@ -112,28 +140,29 @@ function M.load(plugins, reason)
112140
end
113141
end
114142

115-
---@param plugin LazyPlugin
116-
function M.packadd(plugin)
143+
---@param path string
144+
function M.packadd(path)
145+
M.source_runtime(path, "plugin")
146+
M.ftdetect(path)
117147
if M.init_done then
118-
M.source_runtime(plugin.dir, "plugin")
119-
M.ftdetect(plugin)
120-
M.source_runtime(plugin.dir, "after/plugin")
148+
M.source_runtime(path, "after/plugin")
121149
end
122150
end
123151

124-
---@param plugin LazyPlugin
125-
function M.ftdetect(plugin)
152+
---@param path string
153+
function M.ftdetect(path)
126154
vim.cmd("augroup filetypedetect")
127-
M.source_runtime(plugin.dir, "ftdetect")
155+
M.source_runtime(path, "ftdetect")
128156
vim.cmd("augroup END")
129157
end
130158

131159
---@param ... string
132160
function M.source_runtime(...)
133161
local dir = table.concat({ ... }, "/")
134-
Util.walk(dir, function(path, _, t)
135-
local ext = path:sub(-3)
136-
if t == "file" and (ext == "lua" or ext == "vim") then
162+
Util.walk(dir, function(path, name, t)
163+
local ext = name:sub(-3)
164+
name = name:sub(1, -5)
165+
if t == "file" and (ext == "lua" or ext == "vim") and not M.disabled_rtp_plugins[name] then
137166
Util.track({ runtime = path })
138167
vim.cmd("silent source " .. path)
139168
Util.track()

lua/lazy/init.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function M.setup(spec, opts)
77
vim.notify("Re-sourcing your config is not supported with lazy.nvim", vim.log.levels.WARN, { title = "lazy.nvim" })
88
return
99
end
10+
vim.go.loadplugins = false
11+
1012
vim.g.lazy_did_setup = true
1113
local start = vim.loop.hrtime()
1214

@@ -42,7 +44,7 @@ function M.setup(spec, opts)
4244
end
4345

4446
-- load plugins with lazy=false or Plugin.init
45-
Loader.init_plugins()
47+
Loader.startup()
4648

4749
-- all done!
4850
vim.cmd("do User LazyDone")

0 commit comments

Comments
 (0)