@@ -39,11 +39,6 @@ function BaseNode:new(o)
3939 return o
4040end
4141
42- -- TODO temporary hack to allow DirectoryNode methods in this file, for easier reviewing
43- --- @class DirectoryNode
44- local DirectoryNode = BaseNode :new ()
45- BaseNode .dn = DirectoryNode --- @diagnostic disable-line : inject-field
46-
4742function BaseNode :destroy ()
4843 if self .watcher then
4944 self .watcher :destroy ()
@@ -69,7 +64,7 @@ function BaseNode:is(T)
6964end
7065
7166--- @return boolean
72- function DirectoryNode :has_one_child_folder ()
67+ function BaseNode :has_one_child_folder ()
7368 return # self .nodes == 1 and self .nodes [1 ].nodes and vim .loop .fs_access (self .nodes [1 ].absolute_path , " R" ) or false
7469end
7570
8378function BaseNode :get_git_status ()
8479end
8580
86- --- @return GitStatus | nil
87- function DirectoryNode :get_git_status ()
88- if not self .git_status or not self .explorer .opts .git .show_on_dirs then
89- return nil
90- end
91-
92- local status = {}
93- if not self :last_group_node ().open or self .explorer .opts .git .show_on_open_dirs then
94- -- dir is closed or we should show on open_dirs
95- if self .git_status .file ~= nil then
96- table.insert (status , self .git_status .file )
97- end
98- if self .git_status .dir ~= nil then
99- if self .git_status .dir .direct ~= nil then
100- for _ , s in pairs (self .git_status .dir .direct ) do
101- table.insert (status , s )
102- end
103- end
104- if self .git_status .dir .indirect ~= nil then
105- for _ , s in pairs (self .git_status .dir .indirect ) do
106- table.insert (status , s )
107- end
108- end
109- end
110- else
111- -- dir is open and we shouldn't show on open_dirs
112- if self .git_status .file ~= nil then
113- table.insert (status , self .git_status .file )
114- end
115- if self .git_status .dir ~= nil and self .git_status .dir .direct ~= nil then
116- local deleted = {
117- [" D" ] = true ,
118- [" D " ] = true ,
119- [" RD" ] = true ,
120- [" DD" ] = true ,
121- }
122- for _ , s in pairs (self .git_status .dir .direct ) do
123- if deleted [s ] then
124- table.insert (status , s )
125- end
126- end
127- end
128- end
129- if # status == 0 then
130- return nil
131- else
132- return status
133- end
134- end
135-
13681--- @param projects table
137- function DirectoryNode :reload_node_status (projects )
82+ function BaseNode :reload_node_status (projects )
13883 local toplevel = git .get_toplevel (self .absolute_path )
13984 local status = projects [toplevel ] or {}
14085 for _ , node in ipairs (self .nodes ) do
165110
166111-- If node is grouped, return the last node in the group. Otherwise, return the given node.
167112--- @return Node
168- function DirectoryNode :last_group_node ()
113+ function BaseNode :last_group_node ()
169114 local node = self --[[ @as BaseNode]]
170115
171116 while node .group_next do
@@ -245,7 +190,7 @@ function BaseNode:get_all_nodes_in_group()
245190end
246191
247192-- Toggle group empty folders
248- function DirectoryNode :toggle_group_folders ()
193+ function BaseNode :toggle_group_folders ()
249194 local is_grouped = self .group_next ~= nil
250195
251196 if is_grouped then
@@ -258,10 +203,11 @@ end
258203--- Group empty folders
259204-- Recursively group nodes
260205--- @return Node[]
261- function DirectoryNode :group_empty_folders ()
206+ function BaseNode :group_empty_folders ()
262207 local is_root = not self .parent
263208 local child_folder_only = self :has_one_child_folder () and self .nodes [1 ]
264209 if self .explorer .opts .renderer .group_empty and not is_root and child_folder_only then
210+ --- @cast self DirectoryNode -- TODO move this to the class
265211 self .group_next = child_folder_only
266212 local ns = child_folder_only :group_empty_folders ()
267213 self .nodes = ns or {}
@@ -272,12 +218,12 @@ end
272218
273219--- Ungroup empty folders
274220-- If a node is grouped, ungroup it: put node.group_next to the node.nodes and set node.group_next to nil
275- function DirectoryNode :ungroup_empty_folders ()
276- local cur = self --[[ @as DirectoryNode ]]
221+ function BaseNode :ungroup_empty_folders ()
222+ local cur = self
277223 while cur and cur .group_next do
278224 cur .nodes = { cur .group_next }
279225 cur .group_next = nil
280- cur = cur .nodes [1 ] --[[ @as DirectoryNode ]]
226+ cur = cur .nodes [1 ]
281227 end
282228end
283229
@@ -337,34 +283,4 @@ function BaseNode:clone()
337283 return clone
338284end
339285
340- --
341- -- TODO temporary hack to allow DirectoryNode methods in this file, for easier reviewing
342- --
343-
344- --- @return boolean
345- function BaseNode :has_one_child_folder ()
346- return false
347- end
348-
349- --- @param _ table projects
350- function BaseNode :reload_node_status (_ )
351- end
352-
353- -- If node is grouped, return the last node in the group. Otherwise, return the given node.
354- --- @return Node
355- function BaseNode :last_group_node ()
356- return self
357- end
358-
359- --- Group empty folders
360- -- Recursively group nodes
361- --- @return Node[]
362- function BaseNode :group_empty_folders ()
363- return {}
364- end
365-
366- --- Ungroup empty folders
367- function BaseNode :ungroup_empty_folders ()
368- end
369-
370286return BaseNode
0 commit comments