11local Config = require (" lazy.core.config" )
2-
3- local M = {}
4-
5- M ._fid = 0
6-
7- local function next_id ()
8- M ._fid = M ._fid + 1
9- return M ._fid
10- end
2+ local Util = require (" lazy.core.util" )
113
124--- This class is used to manage the fragments of a plugin spec.
135--- It keeps track of the fragments and their relations to other fragments.
179--- @field frag_stack number[]
1810--- @field dep_stack number[]
1911--- @field dirty table<number , boolean>
12+ --- @field plugins table<LazyPlugin , number>
2013--- @field spec LazySpecLoader
21- local F = {}
14+ local M = {}
15+
16+ M ._fid = 0
17+
18+ local function next_id ()
19+ M ._fid = M ._fid + 1
20+ return M ._fid
21+ end
2222
2323--- @param spec LazySpecLoader
2424--- @return LazyFragments
2525function M .new (spec )
26- local self = setmetatable ({}, { __index = F })
26+ local self = setmetatable ({}, { __index = M })
2727 self .fragments = {}
2828 self .frag_stack = {}
2929 self .dep_stack = {}
3030 self .spec = spec
3131 self .dirty = {}
32+ self .plugins = {}
3233 return self
3334end
3435
3536--- @param id number
36- function F :get (id )
37+ function M :get (id )
3738 return self .fragments [id ]
3839end
3940
4041--- Remove a fragment and all its children.
4142--- This will also remove the fragment from its parent's children list.
4243--- @param id number
43- function F :del (id )
44+ function M :del (id )
4445 -- del fragment
4546 local fragment = self .fragments [id ]
4647 if not fragment then
@@ -55,13 +56,13 @@ function F:del(id)
5556 local parent = self .fragments [pid ]
5657 if parent .frags then
5758 --- @param fid number
58- parent .frags = vim . tbl_filter (function (fid )
59+ parent .frags = Util . filter (function (fid )
5960 return fid ~= id
6061 end , parent .frags )
6162 end
6263 if parent .deps then
6364 --- @param fid number
64- parent .deps = vim . tbl_filter (function (fid )
65+ parent .deps = Util . filter (function (fid )
6566 return fid ~= id
6667 end , parent .deps )
6768 end
8182--- Add a fragment to the fragments list.
8283--- This also resolves its name, url, dir, dependencies and child specs.
8384--- @param plugin LazyPluginSpec
84- function F :add (plugin )
85+ function M :add (plugin )
86+ if self .plugins [plugin ] then
87+ return self .fragments [self .plugins [plugin ]]
88+ end
89+
8590 local id = next_id ()
91+ setmetatable (plugin , nil )
92+
93+ self .plugins [plugin ] = id
8694
8795 local pid = self .frag_stack [# self .frag_stack ]
8896
0 commit comments