@@ -7,6 +7,8 @@ local M = {}
7
7
--- @type LazyPlugin[]
8
8
M .loading = {}
9
9
M .init_done = false
10
+ --- @type table<string,true>
11
+ M .disabled_rtp_plugins = {}
10
12
11
13
function M .setup ()
12
14
-- install missing plugins
@@ -31,11 +33,38 @@ function M.setup()
31
33
Handler .setup ()
32
34
Util .track ()
33
35
36
+ for _ , file in ipairs (Config .options .performance .rtp .disabled_plugins ) do
37
+ M .disabled_rtp_plugins [file ] = true
38
+ end
39
+
34
40
-- autoload opt plugins
35
41
table.insert (package.loaders , M .autoload )
36
42
end
37
43
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
+
39
68
Util .track ({ start = " init" })
40
69
for _ , plugin in pairs (Config .plugins ) do
41
70
-- run plugin init
@@ -44,14 +73,22 @@ function M.init_plugins()
44
73
Util .try (plugin .init , " Failed to run `init` for **" .. plugin .name .. " **" )
45
74
Util .track ()
46
75
end
76
+ end
77
+ Util .track ()
47
78
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" )
51
86
end
52
87
end
53
88
Util .track ()
89
+
54
90
M .init_done = true
91
+ Util .track ()
55
92
end
56
93
57
94
--- @class Loader
@@ -84,21 +121,12 @@ function M.load(plugins, reason)
84
121
Handler .disable (plugin )
85
122
86
123
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
96
124
97
125
if plugin .dependencies then
98
126
M .load (plugin .dependencies , {})
99
127
end
100
128
101
- M .packadd (plugin )
129
+ M .packadd (plugin . dir )
102
130
if plugin .config then
103
131
Util .try (plugin .config , " Failed to run `config` for " .. plugin .name )
104
132
end
@@ -112,28 +140,29 @@ function M.load(plugins, reason)
112
140
end
113
141
end
114
142
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 )
117
147
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" )
121
149
end
122
150
end
123
151
124
- --- @param plugin LazyPlugin
125
- function M .ftdetect (plugin )
152
+ --- @param path string
153
+ function M .ftdetect (path )
126
154
vim .cmd (" augroup filetypedetect" )
127
- M .source_runtime (plugin . dir , " ftdetect" )
155
+ M .source_runtime (path , " ftdetect" )
128
156
vim .cmd (" augroup END" )
129
157
end
130
158
131
159
--- @param ... string
132
160
function M .source_runtime (...)
133
161
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
137
166
Util .track ({ runtime = path })
138
167
vim .cmd (" silent source " .. path )
139
168
Util .track ()
0 commit comments