Skip to content

Commit c7bb2bc

Browse files
committed
refactor(#2837): multi instance reload
1 parent d43ab67 commit c7bb2bc

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

lua/nvim-tree/core.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function M.init(foldername)
1616
if TreeExplorer then
1717
TreeExplorer:destroy()
1818
end
19-
TreeExplorer = explorer.Explorer.new(foldername)
19+
TreeExplorer = explorer:new(foldername)
2020
if not first_init_done then
2121
events._dispatch_ready()
2222
first_init_done = true

lua/nvim-tree/explorer/init.lua

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ local git = require "nvim-tree.git"
22
local notify = require "nvim-tree.notify"
33
local watch = require "nvim-tree.explorer.watch"
44
local explorer_node = require "nvim-tree.explorer.node"
5+
56
local Filters = require "nvim-tree.explorer.filters"
67
local Marks = {} -- circular dependencies
78
local LiveFilter = require "nvim-tree.explorer.live-filter"
89
local Sorters = require "nvim-tree.explorer.sorters"
910
local Clipboard = {} -- circular dependencies
1011

11-
local M = {}
12-
13-
M.explore = require("nvim-tree.explorer.explore").explore
14-
M.reload = require("nvim-tree.explorer.reload").reload
12+
local config
1513

1614
---@class Explorer
1715
---@field absolute_path string
@@ -22,13 +20,14 @@ M.reload = require("nvim-tree.explorer.reload").reload
2220
---@field sorters Sorter
2321
---@field marks Marks
2422
---@field clipboard Clipboard
25-
2623
local Explorer = {}
27-
Explorer.__index = Explorer
24+
25+
Explorer.explore = require("nvim-tree.explorer.explore").explore
26+
Explorer.reload = require("nvim-tree.explorer.reload").reload
2827

2928
---@param path string|nil
3029
---@return Explorer|nil
31-
function Explorer.new(path)
30+
function Explorer:new(path)
3231
local err
3332

3433
if path then
@@ -42,27 +41,32 @@ function Explorer.new(path)
4241
end
4342

4443
---@class Explorer
45-
local explorer = setmetatable({
44+
local o = setmetatable({
4645
absolute_path = path,
4746
nodes = {},
4847
open = true,
49-
sorters = Sorters:new(M.config),
48+
sorters = Sorters:new(config),
5049
}, Explorer)
51-
explorer.watcher = watch.create_watcher(explorer)
52-
explorer.filters = Filters:new(M.config, explorer)
53-
explorer.live_filter = LiveFilter:new(M.config, explorer)
54-
explorer.marks = Marks:new(M.config, explorer)
55-
explorer.clipboard = Clipboard:new(M.config, explorer)
56-
explorer:_load(explorer)
57-
return explorer
50+
setmetatable(o, self)
51+
self.__index = self
52+
53+
o.watcher = watch.create_watcher(o)
54+
o.filters = Filters:new(config, o)
55+
o.live_filter = LiveFilter:new(config, o)
56+
o.marks = Marks:new(config, o)
57+
o.clipboard = Clipboard:new(config, o)
58+
59+
o:_load(o)
60+
61+
return o
5862
end
5963

6064
---@private
6165
---@param node Node
6266
function Explorer:_load(node)
6367
local cwd = node.link_to or node.absolute_path
6468
local git_status = git.load_project_status(cwd)
65-
M.explore(node, git_status, self)
69+
Explorer.explore(node, git_status, self)
6670
end
6771

6872
---@param node Node
@@ -82,8 +86,8 @@ function Explorer:destroy()
8286
iterate(self)
8387
end
8488

85-
function M.setup(opts)
86-
M.config = opts
89+
function Explorer.setup(opts)
90+
config = opts
8791
require("nvim-tree.explorer.node").setup(opts)
8892
require("nvim-tree.explorer.explore").setup(opts)
8993
require("nvim-tree.explorer.reload").setup(opts)
@@ -93,6 +97,4 @@ function M.setup(opts)
9397
Clipboard = require "nvim-tree.actions.fs.clipboard"
9498
end
9599

96-
M.Explorer = Explorer
97-
98-
return M
100+
return Explorer

0 commit comments

Comments
 (0)