refactor(#2886): multi instance: node class refactoring (#2950)

* add todo

* refactor(#2886): multi instance: node class refactoring: extract links, *_git_status (#2944)

* extract DirectoryLinkNode and FileLinkNode, move Node methods to children

* temporarily move DirectoryNode methods into BaseNode for easier reviewing

* move mostly unchanged DirectoryNode methods back to BaseNode

* tidy

* git.git_status_file takes an array

* update git status of links

* luacheck hack

* safer git_status_dir

* refactor(#2886): multi instance: node class refactoring: DirectoryNode:expand_or_collapse (#2957)

move expand_or_collapse to DirectoryNode

* refactor(#2886): multi instance: node group functions refactoring (#2959)

* move last_group_node to DirectoryNode

* move add BaseNode:as and more doc

* revert parameter name changes

* revert parameter name changes

* add Class

* move group methods into DN

* tidy group methods

* tidy group methods

* tidy group methods

* tidy group methods

* parent is DirectoryNode

* tidy expand all

* BaseNode -> Node

* move watcher to DirectoryNode

* last_group_node is DirectoryNode only

* simplify create-file

* simplify parent

* simplify collapse-all

* simplify live-filter

* style

* more type safety
This commit is contained in:
Alexander Courtis
2024-10-25 12:24:59 +11:00
committed by GitHub
parent 63c7ad9037
commit 68be6df2fc
25 changed files with 591 additions and 482 deletions

View File

@@ -3,6 +3,8 @@ local core = require("nvim-tree.core")
local lib = require("nvim-tree.lib")
local Iterator = require("nvim-tree.iterators.node-iterator")
local DirectoryNode = require("nvim-tree.node.directory")
local M = {}
---@return fun(path: string): boolean
@@ -36,8 +38,9 @@ function M.fn(keep_buffers)
Iterator.builder(explorer.nodes)
:hidden()
:applier(function(n)
if n.nodes ~= nil then
n.open = keep_buffers == true and matches(n.absolute_path)
local dir = n:as(DirectoryNode)
if dir then
dir.open = keep_buffers and matches(dir.absolute_path)
end
end)
:recursor(function(n)

View File

@@ -2,6 +2,8 @@ local core = require("nvim-tree.core")
local Iterator = require("nvim-tree.iterators.node-iterator")
local notify = require("nvim-tree.notify")
local DirectoryNode = require("nvim-tree.node.directory")
local M = {}
---@param list string[]
@@ -15,7 +17,7 @@ local function to_lookup_table(list)
return table
end
---@param node Node
---@param node DirectoryNode
local function expand(node)
node = node:last_group_node()
node.open = true
@@ -36,6 +38,7 @@ end
local function gen_iterator()
local expansion_count = 0
---@param parent DirectoryNode
return function(parent)
if parent.parent and parent.nodes and not parent.open then
expansion_count = expansion_count + 1
@@ -44,12 +47,14 @@ local function gen_iterator()
Iterator.builder(parent.nodes)
:hidden()
---@param node DirectoryNode
:applier(function(node)
if should_expand(expansion_count, node) then
expansion_count = expansion_count + 1
expand(node)
end
end)
---@param node DirectoryNode
:recursor(function(node)
return expansion_count < M.MAX_FOLDER_DISCOVERY and (node.group_next and { node.group_next } or (node.open and node.nodes))
end)
@@ -61,11 +66,16 @@ local function gen_iterator()
end
end
---Expand the directory node or the root
---@param node Node
function M.fn(node)
local explorer = core.get_explorer()
node = node.nodes and node or explorer
if gen_iterator()(node) then
local parent = node:as(DirectoryNode) or explorer
if not parent then
return
end
if gen_iterator()(parent) then
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
end
if explorer then