Skip to content

Commit

Permalink
chore: resolve undefined-field
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Oct 25, 2024
1 parent 79245ce commit be546ff
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local Iterator = require("nvim-tree.iterators.node-iterator")
local notify = require("nvim-tree.notify")

local DirectoryNode = require("nvim-tree.node.directory")

local M = {
debouncers = {},
}
Expand Down Expand Up @@ -124,7 +126,12 @@ function M.find_node(nodes, fn)
local node, i = Iterator.builder(nodes)
:matcher(fn)
:recursor(function(node)
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
local dir = node:as(DirectoryNode)
if dir then
return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes)
else
return false
end
end)
:iterate()
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
Expand Down Expand Up @@ -179,11 +186,12 @@ function M.get_node_from_path(path)
return node.absolute_path == path or node.link_to == path
end)
:recursor(function(node)
if node.group_next then
return { node.group_next }
local dir = node:as(DirectoryNode)
if dir and dir.group_next then
return { dir.group_next }
end
if node.nodes then
return node.nodes
if dir then
return dir.nodes
end
end)
:iterate()
Expand Down Expand Up @@ -219,14 +227,20 @@ function M.get_nodes_by_line(nodes_all, line_start)

Iterator.builder(nodes_all)
:applier(function(node)
if node.group_next then
local dir = node:as(DirectoryNode)
if dir and dir.group_next then
return
end
nodes_by_line[line] = node
line = line + 1
end)
:recursor(function(node)
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
local dir = node:as(DirectoryNode)
if dir then
return dir.group_next and { dir.group_next } or (dir.open and #dir.nodes > 0 and dir.nodes)
else
return false
end
end)
:iterate()

Expand Down

0 comments on commit be546ff

Please sign in to comment.