Skip to content

Commit 38aac09

Browse files
authored
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
1 parent c9104a5 commit 38aac09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+835
-742
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
strategy:
7070
matrix:
7171
nvim_version: [ stable, nightly ]
72-
luals_version: [ 3.10.5 ]
72+
luals_version: [ 3.11.0 ]
7373

7474
steps:
7575
- uses: actions/checkout@v4

Diff for: lua/nvim-tree.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function M.place_cursor_on_node()
125125
if not node or node.name == ".." then
126126
return
127127
end
128-
node = utils.get_parent_of_group(node)
128+
node = node:get_parent_of_group()
129129

130130
local line = vim.api.nvim_get_current_line()
131131
local cursor = vim.api.nvim_win_get_cursor(0)
@@ -849,7 +849,7 @@ function M.setup(conf)
849849
require("nvim-tree.keymap").setup(opts)
850850
require("nvim-tree.appearance").setup()
851851
require("nvim-tree.diagnostics").setup(opts)
852-
require("nvim-tree.explorer").setup(opts)
852+
require("nvim-tree.explorer"):setup(opts)
853853
require("nvim-tree.git").setup(opts)
854854
require("nvim-tree.git.utils").setup(opts)
855855
require("nvim-tree.view").setup(opts)

Diff for: lua/nvim-tree/actions/fs/clipboard.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ end
217217
---@param action ACTION
218218
---@param action_fn fun(source: string, dest: string)
219219
function Clipboard:do_paste(node, action, action_fn)
220-
node = lib.get_last_group_node(node)
221-
local explorer = core.get_explorer()
222-
if node.name == ".." and explorer then
223-
node = explorer
220+
if node.name == ".." then
221+
node = self.explorer
222+
else
223+
node = node:last_group_node()
224224
end
225225
local clip = self.data[action]
226226
if #clip == 0 then

Diff for: lua/nvim-tree/actions/fs/create-file.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local utils = require("nvim-tree.utils")
22
local events = require("nvim-tree.events")
3-
local lib = require("nvim-tree.lib")
43
local core = require("nvim-tree.core")
54
local notify = require("nvim-tree.notify")
65

@@ -40,21 +39,22 @@ local function get_containing_folder(node)
4039
return node.absolute_path:sub(0, -node_name_size - 1)
4140
end
4241

43-
---@param node Node|nil
42+
---@param node Node?
4443
function M.fn(node)
4544
local cwd = core.get_cwd()
4645
if cwd == nil then
4746
return
4847
end
4948

50-
node = node and lib.get_last_group_node(node)
5149
if not node or node.name == ".." then
5250
node = {
5351
absolute_path = cwd,
5452
name = "",
5553
nodes = core.get_explorer().nodes,
5654
open = true,
5755
}
56+
else
57+
node = node:last_group_node()
5858
end
5959

6060
local containing_folder = get_containing_folder(node)

Diff for: lua/nvim-tree/actions/fs/rename-file.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function M.fn(default_modifier)
120120
return
121121
end
122122

123-
node = lib.get_last_group_node(node)
123+
node = node:last_group_node()
124124
if node.name == ".." then
125125
return
126126
end

Diff for: lua/nvim-tree/actions/moves/item.lua

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local utils = require("nvim-tree.utils")
22
local view = require("nvim-tree.view")
33
local core = require("nvim-tree.core")
44
local lib = require("nvim-tree.lib")
5-
local explorer_node = require("nvim-tree.explorer.node")
65
local diagnostics = require("nvim-tree.diagnostics")
76

87
local M = {}
@@ -16,7 +15,7 @@ local MAX_DEPTH = 100
1615
---@return boolean
1716
local function status_is_valid(node, what, skip_gitignored)
1817
if what == "git" then
19-
local git_status = explorer_node.get_git_status(node)
18+
local git_status = node:get_git_status()
2019
return git_status ~= nil and (not skip_gitignored or git_status[1] ~= "!!")
2120
elseif what == "diag" then
2221
local diag_status = diagnostics.get_diag_status(node)
@@ -75,7 +74,7 @@ local function expand_node(node)
7574
if not node.open then
7675
-- Expand the node.
7776
-- Should never collapse since we checked open.
78-
lib.expand_or_collapse(node)
77+
node:expand_or_collapse()
7978
end
8079
end
8180

@@ -98,7 +97,7 @@ local function move_next_recursive(what, skip_gitignored)
9897
valid = status_is_valid(node_init, what, skip_gitignored)
9998
end
10099
if node_init.nodes ~= nil and valid and not node_init.open then
101-
lib.expand_or_collapse(node_init)
100+
node_init:expand_or_collapse()
102101
end
103102

104103
move("next", what, skip_gitignored)

Diff for: lua/nvim-tree/actions/moves/parent.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local view = require("nvim-tree.view")
22
local utils = require("nvim-tree.utils")
33
local core = require("nvim-tree.core")
4-
local lib = require("nvim-tree.lib")
54

65
local M = {}
76

@@ -12,7 +11,7 @@ function M.fn(should_close)
1211

1312
return function(node)
1413
local explorer = core.get_explorer()
15-
node = lib.get_last_group_node(node)
14+
node = node:last_group_node()
1615
if should_close and node.open then
1716
node.open = false
1817
if explorer then
@@ -21,7 +20,7 @@ function M.fn(should_close)
2120
return
2221
end
2322

24-
local parent = utils.get_parent_of_group(node).parent
23+
local parent = node:get_parent_of_group().parent
2524

2625
if not parent or not parent.parent then
2726
return view.set_cursor({ 1, 0 })

Diff for: lua/nvim-tree/actions/moves/sibling.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function M.fn(direction)
1515
local first, last, next, prev = nil, nil, nil, nil
1616
local found = false
1717
local parent = node.parent or core.get_explorer()
18-
Iterator.builder(parent.nodes)
18+
Iterator.builder(parent and parent.nodes or {})
1919
:recursor(function()
2020
return nil
2121
end)

Diff for: lua/nvim-tree/actions/tree/modifiers/expand-all.lua

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local core = require("nvim-tree.core")
22
local Iterator = require("nvim-tree.iterators.node-iterator")
33
local notify = require("nvim-tree.notify")
4-
local lib = require("nvim-tree.lib")
54

65
local M = {}
76

@@ -18,7 +17,7 @@ end
1817

1918
---@param node Node
2019
local function expand(node)
21-
node = lib.get_last_group_node(node)
20+
node = node:last_group_node()
2221
node.open = true
2322
if #node.nodes == 0 then
2423
core.get_explorer():expand(node)
@@ -62,10 +61,10 @@ local function gen_iterator()
6261
end
6362
end
6463

65-
---@param base_node table
66-
function M.fn(base_node)
64+
---@param node Node
65+
function M.fn(node)
6766
local explorer = core.get_explorer()
68-
local node = base_node.nodes and base_node or explorer
67+
node = node.nodes and node or explorer
6968
if gen_iterator()(node) then
7069
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
7170
end

Diff for: lua/nvim-tree/api.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Api.tree.change_root_to_node = wrap_node(function(node)
138138
if node.name == ".." then
139139
actions.root.change_dir.fn("..")
140140
elseif node.nodes ~= nil then
141-
actions.root.change_dir.fn(lib.get_last_group_node(node).absolute_path)
141+
actions.root.change_dir.fn(node:last_group_node().absolute_path)
142142
end
143143
end)
144144

@@ -198,7 +198,7 @@ Api.fs.copy.basename = wrap_node(wrap_explorer_member("clipboard", "copy_basenam
198198
Api.fs.copy.relative_path = wrap_node(wrap_explorer_member("clipboard", "copy_path"))
199199

200200
---@param mode string
201-
---@param node table
201+
---@param node Node
202202
local function edit(mode, node)
203203
local path = node.absolute_path
204204
if node.link_to and not node.nodes then
@@ -214,7 +214,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
214214
if node.name == ".." then
215215
actions.root.change_dir.fn("..")
216216
elseif node.nodes then
217-
lib.expand_or_collapse(node, toggle_group)
217+
node:expand_or_collapse(toggle_group)
218218
elseif not toggle_group then
219219
edit(mode, node)
220220
end

Diff for: lua/nvim-tree/buffers.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function M.reload_modified()
2121
end
2222
end
2323

24-
---@param node table
24+
---@param node Node
2525
---@return boolean
2626
function M.is_modified(node)
2727
return node
@@ -32,7 +32,7 @@ function M.is_modified(node)
3232
end
3333

3434
---A buffer exists for the node's absolute path
35-
---@param node table
35+
---@param node Node
3636
---@return boolean
3737
function M.is_opened(node)
3838
return node and vim.fn.bufloaded(node.absolute_path) > 0

Diff for: lua/nvim-tree/core.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function M.init(foldername)
1515
if TreeExplorer then
1616
TreeExplorer:destroy()
1717
end
18-
TreeExplorer = require("nvim-tree.explorer"):new(foldername)
18+
TreeExplorer = require("nvim-tree.explorer"):create(foldername)
1919
if not first_init_done then
2020
events._dispatch_ready()
2121
first_init_done = true

Diff for: lua/nvim-tree/enum.lua

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
local M = {}
22

3+
---Must be synced with uv.fs_stat.result as it is compared with it
4+
---@enum (key) NODE_TYPE
5+
M.NODE_TYPE = {
6+
directory = 1,
7+
file = 2,
8+
link = 4,
9+
}
10+
311
---Setup options for "highlight_*"
412
---@enum HL_POSITION
513
M.HL_POSITION = {

0 commit comments

Comments
 (0)