39
39
40
40
--- @param plugin LazyPlugin
41
41
function M .disable (plugin )
42
- if not plugin ._ .handlers_enabled then
43
- return
44
- end
45
- plugin ._ .handlers_enabled = false
46
- for type , handler in pairs (M .handlers ) do
47
- if plugin [type ] then
48
- handler :del (plugin )
49
- end
42
+ for type in pairs (plugin ._ .handlers or {}) do
43
+ M .handlers [type ]:del (plugin )
50
44
end
51
45
end
52
46
53
47
--- @param plugin LazyPlugin
54
48
function M .enable (plugin )
55
49
if not plugin ._ .loaded then
56
- if plugin ._ .handlers_enabled then
57
- return
50
+ if not plugin ._ .handlers then
51
+ M . load ( plugin )
58
52
end
59
- for type , handler in pairs (M .handlers ) do
60
- if plugin [type ] then
61
- handler :add (plugin )
62
- end
53
+ for type in pairs (plugin ._ .handlers or {}) do
54
+ M .handlers [type ]:add (plugin )
63
55
end
64
- plugin ._ .handlers_enabled = true
65
56
end
66
57
end
67
58
@@ -86,21 +77,40 @@ function M:_add(_value) end
86
77
--- @protected
87
78
function M :_del (_value ) end
88
79
80
+ --- @param value any
81
+ --- @param _plugin LazyPlugin
82
+ --- @return string |{ id : string }
83
+ function M :_parse (value , _plugin )
84
+ assert (type (value ) == " string" , " Expected string, got " .. vim .inspect (value ))
85
+ return value
86
+ end
87
+
88
+ --- @param values any[]
89
89
--- @param plugin LazyPlugin
90
- function M :values (plugin )
91
- local Plugin = require (" lazy.core.plugin" )
90
+ function M :_values (values , plugin )
92
91
--- @type table<string,any>
93
- local values = {}
94
- --- @diagnostic disable-next-line : no-unknown
95
- for _ , value in ipairs (Plugin .values (plugin , self .type , true )) do
96
- values [value ] = value
92
+ local ret = {}
93
+ for _ , value in ipairs (values ) do
94
+ local parsed = self :_parse (value , plugin )
95
+ ret [type (parsed ) == " string" and parsed or parsed .id ] = parsed
96
+ end
97
+ return ret
98
+ end
99
+
100
+ --- @param plugin LazyPlugin
101
+ function M .load (plugin )
102
+ local Plugin = require (" lazy.core.plugin" )
103
+ plugin ._ .handlers = {}
104
+ for type , handler in pairs (M .handlers ) do
105
+ if plugin [type ] then
106
+ plugin ._ .handlers [type ] = handler :_values (Plugin .values (plugin , type , true ), plugin )
107
+ end
97
108
end
98
- return values
99
109
end
100
110
101
111
--- @param plugin LazyPlugin
102
112
function M :add (plugin )
103
- for key , value in pairs (self : values ( plugin ) ) do
113
+ for key , value in pairs (plugin . _ . handlers [ self . type ] or {} ) do
104
114
if not self .active [key ] then
105
115
self .active [key ] = {}
106
116
self :_add (value )
112
122
113
123
--- @param plugin LazyPlugin
114
124
function M :del (plugin )
115
- for key , value in pairs (self :values (plugin )) do
125
+ if not plugin ._ .handlers then
126
+ return
127
+ end
128
+ for key , value in pairs (plugin ._ .handlers [self .type ] or {}) do
116
129
if self .active [key ] and self .active [key ][plugin .name ] then
117
130
self .active [key ][plugin .name ] = nil
118
131
if vim .tbl_isempty (self .active [key ]) then
0 commit comments