From be546ff18d41f28466b065c857e1e041659bd2c8 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 15:18:58 +1100 Subject: [PATCH] chore: resolve undefined-field --- lua/nvim-tree/utils.lua | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index 936982ec0a7..a27f6daf60e 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -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 = {}, } @@ -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 @@ -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() @@ -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()