* refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * node classes and constructors * node methods * refactor(#2875): multi instance renderer * node classes and constructors * explorer is a directory node * extract methods from explore_node * extract methods from explore_node * extract methods from explore_node * extract methods from lib * use .. name for root node for compatibility * use node.explorer * extract node factory, remove unused code * factories for all nodes, add RootNode * factories for all nodes, add RootNode * use factory pattern for decorators * note regression and commit * fix dir git status regression * destroy nodes, not explorer * add BaseNode:is * revert changes to create-file, handle in #2924 * extract methods from explorer * extract methods from explorer * extract methods from explorer * use Node everywhere in luadoc * extract methods from lib * extract methods from lib * lint * remove unused code * don't call methods on fake root node * get_node_at_cursor returns explorer (root) node instead of { name = '..' } * remove unused inject_node * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * refactor(#2875): multi instance renderer * extract methods from lib * node factory uses stat only * temporary DirectoryNode casting until method extraction into child classes * lua-language-server 3.10.5 -> 3.11.0 * explicitly call Explorer constructor * normalise explorer RootNode new call, tidy annotations
This commit is contained in:
committed by
GitHub
parent
c9104a5d07
commit
38aac09151
89
lua/nvim-tree/node/link.lua
Normal file
89
lua/nvim-tree/node/link.lua
Normal file
@@ -0,0 +1,89 @@
|
||||
local watch = require("nvim-tree.explorer.watch")
|
||||
|
||||
local BaseNode = require("nvim-tree.node")
|
||||
|
||||
---@class (exact) LinkNode: BaseNode
|
||||
---@field has_children boolean
|
||||
---@field group_next Node? -- If node is grouped, this points to the next child dir/link node
|
||||
---@field link_to string absolute path
|
||||
---@field nodes Node[]
|
||||
---@field open boolean
|
||||
local LinkNode = BaseNode:new()
|
||||
|
||||
---Static factory method
|
||||
---@param explorer Explorer
|
||||
---@param parent Node
|
||||
---@param absolute_path string
|
||||
---@param name string
|
||||
---@param fs_stat uv.fs_stat.result?
|
||||
---@return LinkNode? nil on vim.loop.fs_realpath failure
|
||||
function LinkNode:create(explorer, parent, absolute_path, name, fs_stat)
|
||||
-- INFO: sometimes fs_realpath returns nil
|
||||
-- I expect this be a bug in glibc, because it fails to retrieve the path for some
|
||||
-- links (for instance libr2.so in /usr/lib) and thus even with a C program realpath fails
|
||||
-- when it has no real reason to. Maybe there is a reason, but errno is definitely wrong.
|
||||
local link_to = vim.loop.fs_realpath(absolute_path)
|
||||
if not link_to then
|
||||
return nil
|
||||
end
|
||||
|
||||
local open, nodes, has_children
|
||||
local is_dir_link = (link_to ~= nil) and vim.loop.fs_stat(link_to).type == "directory"
|
||||
|
||||
if is_dir_link and link_to then
|
||||
local handle = vim.loop.fs_scandir(link_to)
|
||||
has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil or false
|
||||
open = false
|
||||
nodes = {}
|
||||
end
|
||||
|
||||
---@type LinkNode
|
||||
local o = {
|
||||
type = "link",
|
||||
explorer = explorer,
|
||||
absolute_path = absolute_path,
|
||||
executable = false,
|
||||
fs_stat = fs_stat,
|
||||
hidden = false,
|
||||
is_dot = false,
|
||||
name = name,
|
||||
parent = parent,
|
||||
watcher = nil,
|
||||
diag_status = nil,
|
||||
|
||||
has_children = has_children,
|
||||
group_next = nil,
|
||||
link_to = link_to,
|
||||
nodes = nodes,
|
||||
open = open,
|
||||
}
|
||||
o = self:new(o) --[[@as LinkNode]]
|
||||
|
||||
if is_dir_link then
|
||||
o.watcher = watch.create_watcher(o)
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Create a sanitized partial copy of a node, populating children recursively.
|
||||
---@return LinkNode cloned
|
||||
function LinkNode:clone()
|
||||
local clone = BaseNode.clone(self) --[[@as LinkNode]]
|
||||
|
||||
clone.has_children = self.has_children
|
||||
clone.group_next = nil
|
||||
clone.link_to = self.link_to
|
||||
clone.nodes = {}
|
||||
clone.open = self.open
|
||||
|
||||
if self.nodes then
|
||||
for _, child in ipairs(self.nodes) do
|
||||
table.insert(clone.nodes, child:clone())
|
||||
end
|
||||
end
|
||||
|
||||
return clone
|
||||
end
|
||||
|
||||
return LinkNode
|
||||
Reference in New Issue
Block a user