Skip to content

Commit 50e9194

Browse files
committed
Revert "refactor(#2871, #2886): multi instance: node classes created (#2916)"
This reverts commit 38aac09.
1 parent 010ae03 commit 50e9194

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

+742
-835
lines changed

.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.11.0 ]
72+
luals_version: [ 3.10.5 ]
7373

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

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 = node:get_parent_of_group()
128+
node = utils.get_parent_of_group(node)
129129

130130
local line = vim.api.nvim_get_current_line()
131131
local cursor = vim.api.nvim_win_get_cursor(0)
@@ -854,7 +854,7 @@ function M.setup(conf)
854854
require("nvim-tree.keymap").setup(opts)
855855
require("nvim-tree.appearance").setup()
856856
require("nvim-tree.diagnostics").setup(opts)
857-
require("nvim-tree.explorer"):setup(opts)
857+
require("nvim-tree.explorer").setup(opts)
858858
require("nvim-tree.git").setup(opts)
859859
require("nvim-tree.git.utils").setup(opts)
860860
require("nvim-tree.view").setup(opts)

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-
if node.name == ".." then
221-
node = self.explorer
222-
else
223-
node = node:last_group_node()
220+
node = lib.get_last_group_node(node)
221+
local explorer = core.get_explorer()
222+
if node.name == ".." and explorer then
223+
node = explorer
224224
end
225225
local clip = self.data[action]
226226
if #clip == 0 then

lua/nvim-tree/actions/fs/create-file.lua

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

@@ -39,22 +40,21 @@ local function get_containing_folder(node)
3940
return node.absolute_path:sub(0, -node_name_size - 1)
4041
end
4142

42-
---@param node Node?
43+
---@param node Node|nil
4344
function M.fn(node)
4445
local cwd = core.get_cwd()
4546
if cwd == nil then
4647
return
4748
end
4849

50+
node = node and lib.get_last_group_node(node)
4951
if not node or node.name == ".." then
5052
node = {
5153
absolute_path = cwd,
5254
name = "",
5355
nodes = core.get_explorer().nodes,
5456
open = true,
5557
}
56-
else
57-
node = node:last_group_node()
5858
end
5959

6060
local containing_folder = get_containing_folder(node)

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 = node:last_group_node()
123+
node = lib.get_last_group_node(node)
124124
if node.name == ".." then
125125
return
126126
end

lua/nvim-tree/actions/moves/item.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ 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")
56
local diagnostics = require("nvim-tree.diagnostics")
67

78
local M = {}
@@ -15,7 +16,7 @@ local MAX_DEPTH = 100
1516
---@return boolean
1617
local function status_is_valid(node, what, skip_gitignored)
1718
if what == "git" then
18-
local git_status = node:get_git_status()
19+
local git_status = explorer_node.get_git_status(node)
1920
return git_status ~= nil and (not skip_gitignored or git_status[1] ~= "!!")
2021
elseif what == "diag" then
2122
local diag_status = diagnostics.get_diag_status(node)
@@ -74,7 +75,7 @@ local function expand_node(node)
7475
if not node.open then
7576
-- Expand the node.
7677
-- Should never collapse since we checked open.
77-
node:expand_or_collapse()
78+
lib.expand_or_collapse(node)
7879
end
7980
end
8081

@@ -97,7 +98,7 @@ local function move_next_recursive(what, skip_gitignored)
9798
valid = status_is_valid(node_init, what, skip_gitignored)
9899
end
99100
if node_init.nodes ~= nil and valid and not node_init.open then
100-
node_init:expand_or_collapse()
101+
lib.expand_or_collapse(node_init)
101102
end
102103

103104
move("next", what, skip_gitignored)

lua/nvim-tree/actions/moves/parent.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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")
45

56
local M = {}
67

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

1213
return function(node)
1314
local explorer = core.get_explorer()
14-
node = node:last_group_node()
15+
node = lib.get_last_group_node(node)
1516
if should_close and node.open then
1617
node.open = false
1718
if explorer then
@@ -20,7 +21,7 @@ function M.fn(should_close)
2021
return
2122
end
2223

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

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

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 and parent.nodes or {})
18+
Iterator.builder(parent.nodes)
1919
:recursor(function()
2020
return nil
2121
end)

lua/nvim-tree/actions/tree/modifiers/expand-all.lua

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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")
45

56
local M = {}
67

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

1819
---@param node Node
1920
local function expand(node)
20-
node = node:last_group_node()
21+
node = lib.get_last_group_node(node)
2122
node.open = true
2223
if #node.nodes == 0 then
2324
core.get_explorer():expand(node)
@@ -61,10 +62,10 @@ local function gen_iterator()
6162
end
6263
end
6364

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

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(node:last_group_node().absolute_path)
141+
actions.root.change_dir.fn(lib.get_last_group_node(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 Node
201+
---@param node table
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-
node:expand_or_collapse(toggle_group)
217+
lib.expand_or_collapse(node, toggle_group)
218218
elseif not toggle_group then
219219
edit(mode, node)
220220
end

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 Node
24+
---@param node table
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 Node
35+
---@param node table
3636
---@return boolean
3737
function M.is_opened(node)
3838
return node and vim.fn.bufloaded(node.absolute_path) > 0

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"):create(foldername)
18+
TreeExplorer = require("nvim-tree.explorer"):new(foldername)
1919
if not first_init_done then
2020
events._dispatch_ready()
2121
first_init_done = true

lua/nvim-tree/enum.lua

-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
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-
113
---Setup options for "highlight_*"
124
---@enum HL_POSITION
135
M.HL_POSITION = {

0 commit comments

Comments
 (0)