* 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
This commit is contained in:
committed by
GitHub
parent
50e919426a
commit
5ad87620ec
31
lua/nvim-tree/node/factory.lua
Normal file
31
lua/nvim-tree/node/factory.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
Reference in New Issue
Block a user