Skip to content

Commit 2dde0df

Browse files
committed
refactor(#2875): multi instance renderer
1 parent 44f8aaa commit 2dde0df

File tree

10 files changed

+48
-37
lines changed

10 files changed

+48
-37
lines changed

Diff for: lua/nvim-tree/renderer/builder.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ function Builder:new(opts, explorer)
111111
virtual_lines = {},
112112
decorators = {
113113
-- priority order
114-
DecoratorCut:new(opts),
115-
DecoratorCopied:new(opts),
116-
DecoratorDiagnostics:new(opts),
117-
DecoratorBookmarks:new(opts),
118-
DecoratorModified:new(opts),
119-
DecoratorHidden:new(opts),
120-
DecoratorOpened:new(opts),
121-
DecoratorGit:new(opts),
114+
DecoratorCut:new(opts, explorer),
115+
DecoratorCopied:new(opts, explorer),
116+
DecoratorDiagnostics:new(opts, explorer),
117+
DecoratorBookmarks:new(opts, explorer),
118+
DecoratorModified:new(opts, explorer),
119+
DecoratorHidden:new(opts, explorer),
120+
DecoratorOpened:new(opts, explorer),
121+
DecoratorGit:new(opts, explorer),
122122
},
123123
hidden_display = setup_hidden_display_function(opts),
124124
}

Diff for: lua/nvim-tree/renderer/decorator/bookmarks.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
local core = require "nvim-tree.core"
2-
31
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
42
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
53

64
local Decorator = require "nvim-tree.renderer.decorator"
75

8-
---@class DecoratorBookmarks: Decorator
6+
---@class (exact) DecoratorBookmarks: Decorator
97
---@field icon HighlightedString
108
local DecoratorBookmarks = Decorator:new()
119

1210
---@param opts table
11+
---@param explorer Explorer
1312
---@return DecoratorBookmarks
14-
function DecoratorBookmarks:new(opts)
13+
function DecoratorBookmarks:new(opts, explorer)
1514
local o = Decorator.new(self, {
15+
explorer = explorer,
1616
enabled = true,
1717
hl_pos = HL_POSITION[opts.renderer.highlight_bookmarks] or HL_POSITION.none,
1818
icon_placement = ICON_PLACEMENT[opts.renderer.icons.bookmarks_placement] or ICON_PLACEMENT.none,
@@ -34,7 +34,7 @@ end
3434
---@param node Node
3535
---@return HighlightedString[]|nil icons
3636
function DecoratorBookmarks:calculate_icons(node)
37-
if core.get_explorer() and core.get_explorer().marks:get(node) then
37+
if self.explorer.marks:get(node) then
3838
return { self.icon }
3939
end
4040
end
@@ -43,7 +43,7 @@ end
4343
---@param node Node
4444
---@return string|nil group
4545
function DecoratorBookmarks:calculate_highlight(node)
46-
if self.hl_pos ~= HL_POSITION.none and core.get_explorer() and core.get_explorer().marks:get(node) then
46+
if self.hl_pos ~= HL_POSITION.none and self.explorer.marks:get(node) then
4747
return "NvimTreeBookmarkHL"
4848
end
4949
end

Diff for: lua/nvim-tree/renderer/decorator/copied.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
local core = require "nvim-tree.core"
2-
31
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
42
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
53

64
local Decorator = require "nvim-tree.renderer.decorator"
75

8-
---@class DecoratorCopied: Decorator
6+
---@class (exact) DecoratorCopied: Decorator
97
---@field enabled boolean
108
---@field icon HighlightedString|nil
119
local DecoratorCopied = Decorator:new()
1210

1311
---@param opts table
12+
---@param explorer Explorer
1413
---@return DecoratorCopied
15-
function DecoratorCopied:new(opts)
14+
function DecoratorCopied:new(opts, explorer)
1615
local o = Decorator.new(self, {
16+
explorer = explorer,
1717
enabled = true,
1818
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
1919
icon_placement = ICON_PLACEMENT.none,
@@ -27,7 +27,7 @@ end
2727
---@param node Node
2828
---@return string|nil group
2929
function DecoratorCopied:calculate_highlight(node)
30-
if self.hl_pos ~= HL_POSITION.none and core.get_explorer() and core.get_explorer().clipboard:is_copied(node) then
30+
if self.hl_pos ~= HL_POSITION.none and self.explorer.clipboard:is_copied(node) then
3131
return "NvimTreeCopiedHL"
3232
end
3333
end

Diff for: lua/nvim-tree/renderer/decorator/cut.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
local core = require "nvim-tree.core"
2-
31
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
42
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
53

64
local Decorator = require "nvim-tree.renderer.decorator"
75

8-
---@class DecoratorCut: Decorator
6+
---@class (exact) DecoratorCut: Decorator
97
---@field enabled boolean
108
---@field icon HighlightedString|nil
119
local DecoratorCut = Decorator:new()
1210

1311
---@param opts table
12+
---@param explorer Explorer
1413
---@return DecoratorCut
15-
function DecoratorCut:new(opts)
14+
function DecoratorCut:new(opts, explorer)
1615
local o = Decorator.new(self, {
16+
explorer = explorer,
1717
enabled = true,
1818
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
1919
icon_placement = ICON_PLACEMENT.none,
@@ -27,7 +27,7 @@ end
2727
---@param node Node
2828
---@return string|nil group
2929
function DecoratorCut:calculate_highlight(node)
30-
if self.hl_pos ~= HL_POSITION.none and core.get_explorer() and core.get_explorer().clipboard:is_cut(node) then
30+
if self.hl_pos ~= HL_POSITION.none and self.explorer.clipboard:is_cut(node) then
3131
return "NvimTreeCutHL"
3232
end
3333
end

Diff for: lua/nvim-tree/renderer/decorator/diagnostics.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ local ICON_KEYS = {
3232
["hint"] = vim.diagnostic.severity.HINT,
3333
}
3434

35-
---@class DecoratorDiagnostics: Decorator
35+
---@class (exact) DecoratorDiagnostics: Decorator
3636
---@field icons HighlightedString[]
3737
local DecoratorDiagnostics = Decorator:new()
3838

3939
---@param opts table
40+
---@param explorer Explorer
4041
---@return DecoratorDiagnostics
41-
function DecoratorDiagnostics:new(opts)
42+
function DecoratorDiagnostics:new(opts, explorer)
4243
local o = Decorator.new(self, {
44+
explorer = explorer,
4345
enabled = opts.diagnostics.enable,
4446
hl_pos = HL_POSITION[opts.renderer.highlight_diagnostics] or HL_POSITION.none,
4547
icon_placement = ICON_PLACEMENT[opts.renderer.icons.diagnostics_placement] or ICON_PLACEMENT.none,

Diff for: lua/nvim-tree/renderer/decorator/git.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ local Decorator = require "nvim-tree.renderer.decorator"
99
---@class HighlightedStringGit: HighlightedString
1010
---@field ord number decreasing priority
1111

12-
---@class DecoratorGit: Decorator
12+
---@class (exact) DecoratorGit: Decorator
1313
---@field file_hl table<string, string> by porcelain status e.g. "AM"
1414
---@field folder_hl table<string, string> by porcelain status
1515
---@field icons_by_status HighlightedStringGit[] by human status
1616
---@field icons_by_xy table<string, HighlightedStringGit[]> by porcelain status
1717
local DecoratorGit = Decorator:new()
1818

1919
---@param opts table
20+
---@param explorer Explorer
2021
---@return DecoratorGit
21-
function DecoratorGit:new(opts)
22+
function DecoratorGit:new(opts, explorer)
2223
local o = Decorator.new(self, {
24+
explorer = explorer,
2325
enabled = opts.git.enable,
2426
hl_pos = HL_POSITION[opts.renderer.highlight_git] or HL_POSITION.none,
2527
icon_placement = ICON_PLACEMENT[opts.renderer.icons.git_placement] or ICON_PLACEMENT.none,

Diff for: lua/nvim-tree/renderer/decorator/hidden.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
33
local explorer_node = require "nvim-tree.explorer.node"
44
local Decorator = require "nvim-tree.renderer.decorator"
55

6-
---@class DecoratorHidden: Decorator
6+
---@class (exact) DecoratorHidden: Decorator
77
---@field icon HighlightedString|nil
88
local DecoratorHidden = Decorator:new()
99

1010
---@param opts table
11+
---@param explorer Explorer
1112
---@return DecoratorHidden
12-
function DecoratorHidden:new(opts)
13+
function DecoratorHidden:new(opts, explorer)
1314
local o = Decorator.new(self, {
15+
explorer = explorer,
1416
enabled = true,
1517
hl_pos = HL_POSITION[opts.renderer.highlight_hidden] or HL_POSITION.none,
1618
icon_placement = ICON_PLACEMENT[opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,

Diff for: lua/nvim-tree/renderer/decorator/init.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
22
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
33

4-
---@class Decorator
4+
---@class (exact) Decorator
5+
---@field protected explorer Explorer
56
---@field protected enabled boolean
67
---@field protected hl_pos HL_POSITION
78
---@field protected icon_placement ICON_PLACEMENT
@@ -11,8 +12,8 @@ local Decorator = {}
1112
---@return Decorator
1213
function Decorator:new(o)
1314
o = o or {}
14-
setmetatable(o, self)
15-
self.__index = self
15+
16+
setmetatable(o, { __index = self })
1617

1718
return o
1819
end

Diff for: lua/nvim-tree/renderer/decorator/modified.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
55

66
local Decorator = require "nvim-tree.renderer.decorator"
77

8-
---@class DecoratorModified: Decorator
8+
---@class (exact) DecoratorModified: Decorator
99
---@field icon HighlightedString|nil
1010
local DecoratorModified = Decorator:new()
1111

1212
---@param opts table
13+
---@param explorer Explorer
1314
---@return DecoratorModified
14-
function DecoratorModified:new(opts)
15+
function DecoratorModified:new(opts, explorer)
1516
local o = Decorator.new(self, {
17+
explorer = explorer,
1618
enabled = opts.modified.enable,
1719
hl_pos = HL_POSITION[opts.renderer.highlight_modified] or HL_POSITION.none,
1820
icon_placement = ICON_PLACEMENT[opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,

Diff for: lua/nvim-tree/renderer/decorator/opened.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
55

66
local Decorator = require "nvim-tree.renderer.decorator"
77

8-
---@class DecoratorOpened: Decorator
8+
---@class (exact) DecoratorOpened: Decorator
99
---@field enabled boolean
1010
---@field icon HighlightedString|nil
1111
local DecoratorOpened = Decorator:new()
1212

1313
---@param opts table
14+
---@param explorer Explorer
1415
---@return DecoratorOpened
15-
function DecoratorOpened:new(opts)
16+
function DecoratorOpened:new(opts, explorer)
1617
local o = Decorator.new(self, {
18+
explorer = explorer,
1719
enabled = true,
1820
hl_pos = HL_POSITION[opts.renderer.highlight_opened_files] or HL_POSITION.none,
1921
icon_placement = ICON_PLACEMENT.none,

0 commit comments

Comments
 (0)