From 641f125f6bd7185816478d83bd2e4df3ad42937c Mon Sep 17 00:00:00 2001 From: ghostbuster91 Date: Sun, 20 Jul 2025 21:24:29 +0200 Subject: [PATCH] Fix warnings --- lua/nvim-tree/actions/tree/modifiers/expand.lua | 7 ++++++- lua/nvim-tree/api.lua | 14 +++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lua/nvim-tree/actions/tree/modifiers/expand.lua b/lua/nvim-tree/actions/tree/modifiers/expand.lua index f8ba12ae..06d071c6 100644 --- a/lua/nvim-tree/actions/tree/modifiers/expand.lua +++ b/lua/nvim-tree/actions/tree/modifiers/expand.lua @@ -48,11 +48,16 @@ end ---@return boolean local function should_expand(expansion_count, node, should_descend) local dir = node:as(DirectoryNode) - return dir and not dir.open and should_descend(expansion_count, node) + if not dir then + return false + end + + return not dir.open and should_descend(expansion_count, node) end ---@param should_descend fun(expansion_count: integer, node: Node): boolean +---@return fun(node): any local function gen_iterator(should_descend) local expansion_count = 0 diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index f379f6ce..190722d0 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -232,15 +232,15 @@ Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse.all) Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all) Api.tree.toggle_descend_until = wrap_node(function(node, descend_until) - if node.open then - local dir = node:as(DirectoryNode) - dir:expand_or_collapse("edit") - else - if node.nodes then - actions.tree.modifiers.expand.all(node, { descend_until = descend_until }) + local dir = node:as(DirectoryNode) + if dir then + if node.open then + dir:expand_or_collapse(nil) else - edit("edit", node) + actions.tree.modifiers.expand.all(node, { descend_until = descend_until }) end + else + edit("edit", node) end end)