37
37
38
38
function M .init_plugins ()
39
39
Util .track (" loader" )
40
+
40
41
Util .track ({ start = " init" })
41
42
for _ , plugin in pairs (Config .plugins ) do
43
+ -- run plugin init
42
44
if plugin .init then
43
45
Util .track ({ plugin = plugin .name , init = " init" })
44
46
Util .try (plugin .init , " Failed to run `init` for **" .. plugin .name .. " **" )
45
47
Util .track ()
46
48
end
49
+
50
+ -- load start plugin
47
51
if plugin .lazy == false then
48
52
M .load (plugin , { start = " startup" })
49
53
end
50
54
end
51
55
Util .track ()
56
+
52
57
Util .track ()
53
58
M .init_done = true
54
59
end
@@ -82,6 +87,15 @@ function M.load(plugins, reason)
82
87
Util .track ({ plugin = plugin .name , start = reason .start })
83
88
84
89
vim .opt .runtimepath :prepend (plugin .dir )
90
+ if not M .init_done then
91
+ local after = plugin .dir .. " /after"
92
+ -- only add the after directories during startup
93
+ -- afterwards we only source the runtime files in after
94
+ -- Check if it exists here, to prevent further rtp file checks during startup
95
+ if vim .loop .fs_stat (after ) then
96
+ vim .opt .runtimepath :append (after )
97
+ end
98
+ end
85
99
86
100
if plugin .dependencies then
87
101
M .load (plugin .dependencies , {})
@@ -102,24 +116,23 @@ function M.load(plugins, reason)
102
116
end
103
117
104
118
--- @param plugin LazyPlugin
105
- --- @param force ? boolean
106
- function M .packadd (plugin , force )
119
+ function M .packadd (plugin )
107
120
-- FIXME: investigate further what else is needed
108
121
-- vim.cmd.packadd(plugin.name)
109
122
-- M.source_runtime(plugin, "/after/plugin")
110
- if M .init_done or force then
111
- M .source_runtime (plugin , " /plugin" )
123
+ if M .init_done then
124
+ M .source_runtime (plugin . dir , " /plugin" )
112
125
if vim .g .did_load_filetypes == 1 then
113
- M .source_runtime (plugin , " /ftdetect" )
126
+ M .source_runtime (plugin . dir , " /ftdetect" )
114
127
end
115
- M .source_runtime (plugin , " /after/plugin" )
128
+ M .source_runtime (plugin . dir , " /after/plugin" )
116
129
end
117
130
end
118
131
119
- --- @param plugin LazyPlugin
120
- --- @param dir ? string
121
- function M . source_runtime ( plugin , dir )
122
- Util .walk (plugin . dir .. dir , function (path , _ , t )
132
+ --- @param ... string
133
+ function M . source_runtime (...)
134
+ local dir = table.concat ({ ... }, " / " )
135
+ Util .walk (dir , function (path , _ , t )
123
136
local ext = path :sub (- 3 )
124
137
if t == " file" and (ext == " lua" or ext == " vim" ) then
125
138
vim .cmd (" silent source " .. path )
0 commit comments