Skip to content

Commit be546ff

Browse files
committed
chore: resolve undefined-field
1 parent 79245ce commit be546ff

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

lua/nvim-tree/utils.lua

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
local Iterator = require("nvim-tree.iterators.node-iterator")
22
local notify = require("nvim-tree.notify")
33

4+
local DirectoryNode = require("nvim-tree.node.directory")
5+
46
local M = {
57
debouncers = {},
68
}
@@ -124,7 +126,12 @@ function M.find_node(nodes, fn)
124126
local node, i = Iterator.builder(nodes)
125127
:matcher(fn)
126128
:recursor(function(node)
127-
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
129+
local dir = node:as(DirectoryNode)
130+
if dir then
131+
return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes)
132+
else
133+
return false
134+
end
128135
end)
129136
:iterate()
130137
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
@@ -179,11 +186,12 @@ function M.get_node_from_path(path)
179186
return node.absolute_path == path or node.link_to == path
180187
end)
181188
:recursor(function(node)
182-
if node.group_next then
183-
return { node.group_next }
189+
local dir = node:as(DirectoryNode)
190+
if dir and dir.group_next then
191+
return { dir.group_next }
184192
end
185-
if node.nodes then
186-
return node.nodes
193+
if dir then
194+
return dir.nodes
187195
end
188196
end)
189197
:iterate()
@@ -219,14 +227,20 @@ function M.get_nodes_by_line(nodes_all, line_start)
219227

220228
Iterator.builder(nodes_all)
221229
:applier(function(node)
222-
if node.group_next then
230+
local dir = node:as(DirectoryNode)
231+
if dir and dir.group_next then
223232
return
224233
end
225234
nodes_by_line[line] = node
226235
line = line + 1
227236
end)
228237
:recursor(function(node)
229-
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
238+
local dir = node:as(DirectoryNode)
239+
if dir then
240+
return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes)
241+
else
242+
return false
243+
end
230244
end)
231245
:iterate()
232246

0 commit comments

Comments
 (0)