nvim-tree.lua/lua/nvim-tree/node/factory.lua
Alexander Courtis 5ad87620ec
fix(#2945): stack overflow on api.git.reload or fugitive event with watchers disabled (#2949)
* Reapply "refactor(#2871, #2886): multi instance: node classes created (#2916)"

This reverts commit 50e919426a.

* fix(#2945): stack overflow on api.git.reload or fugitive event
2024-10-11 13:47:01 +11:00

32 lines
937 B
Lua

local DirectoryNode = require("nvim-tree.node.directory")
local LinkNode = require("nvim-tree.node.link")
local FileNode = require("nvim-tree.node.file")
local Watcher = require("nvim-tree.watcher")
local M = {}
---Factory function to create the appropriate Node
---@param explorer Explorer
---@param parent Node
---@param abs string
---@param stat uv.fs_stat.result? -- on nil stat return nil Node
---@param name string
---@return Node?
function M.create_node(explorer, parent, abs, stat, name)
if not stat then
return nil
end
if stat.type == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then
return DirectoryNode:create(explorer, parent, abs, name, stat)
elseif stat.type == "file" then
return FileNode:create(explorer, parent, abs, name, stat)
elseif stat.type == "link" then
return LinkNode:create(explorer, parent, abs, name, stat)
end
return nil
end
return M