refactor(#2871, #2886): multi instance: node classes created (#2916)

* 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:
Alexander Courtis
2024-10-07 13:46:56 +11:00
committed by GitHub
parent c9104a5d07
commit 38aac09151
43 changed files with 835 additions and 742 deletions

View File

@@ -112,8 +112,7 @@ function M.find_node(nodes, fn)
end)
:iterate()
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
local explorer = require("nvim-tree.core").get_explorer()
if explorer and explorer.live_filter.filter then
if node and node.explorer.live_filter.filter then
i = i + 1
end
return node, i
@@ -121,7 +120,7 @@ end
-- Find the line number of a node.
-- Return -1 is node is nil or not found.
---@param node Node|nil
---@param node Node?
---@return integer
function M.find_node_line(node)
if not node then
@@ -174,16 +173,6 @@ function M.get_node_from_path(path)
:iterate()
end
---Get the highest parent of grouped nodes
---@param node Node
---@return Node node or parent
function M.get_parent_of_group(node)
while node and node.parent and node.parent.group_next do
node = node.parent
end
return node
end
M.default_format_hidden_count = function(hidden_count, simple)
local parts = {}
local total_count = 0
@@ -473,7 +462,7 @@ end
---Focus node passed as parameter if visible, otherwise focus first visible parent.
---If none of the parents is visible focus root.
---If node is nil do nothing.
---@param node Node|nil node to focus
---@param node Node? node to focus
function M.focus_node_or_parent(node)
local explorer = require("nvim-tree.core").get_explorer()
@@ -549,14 +538,6 @@ function M.array_remove_nils(array)
end, array)
end
---@param f fun(node: Node|nil)
---@return function
function M.inject_node(f)
return function()
f(require("nvim-tree.lib").get_node_at_cursor())
end
end
--- Is the buffer named NvimTree_[0-9]+ a tree? filetype is "NvimTree" or not readable file.
--- This is cheap, as the readable test should only ever be needed when resuming a vim session.
---@param bufnr number|nil may be 0 or nil for current
@@ -578,4 +559,16 @@ function M.is_nvim_tree_buf(bufnr)
return false
end
--- path is an executable file or directory
---@param absolute_path string
---@return boolean
function M.is_executable(absolute_path)
if M.is_windows or M.is_wsl then
--- executable detection on windows is buggy and not performant hence it is disabled
return false
else
return vim.loop.fs_access(absolute_path, "X") or false
end
end
return M