Renderer and Builder use classic, tidy opts
This commit is contained in:
@@ -58,7 +58,7 @@ function Explorer:new(args)
|
|||||||
self.opts = config
|
self.opts = config
|
||||||
|
|
||||||
self.sorters = Sorter(config)
|
self.sorters = Sorter(config)
|
||||||
self.renderer = Renderer:new(config, self)
|
self.renderer = Renderer({ explorer = self })
|
||||||
self.filters = Filters:new(config, self)
|
self.filters = Filters:new(config, self)
|
||||||
self.live_filter = LiveFilter:new(config, self)
|
self.live_filter = LiveFilter:new(config, self)
|
||||||
self.marks = Marks:new(config, self)
|
self.marks = Marks:new(config, self)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local notify = require("nvim-tree.notify")
|
|||||||
local utils = require("nvim-tree.utils")
|
local utils = require("nvim-tree.utils")
|
||||||
local view = require("nvim-tree.view")
|
local view = require("nvim-tree.view")
|
||||||
|
|
||||||
|
local Class = require("nvim-tree.classic")
|
||||||
local DirectoryNode = require("nvim-tree.node.directory")
|
local DirectoryNode = require("nvim-tree.node.directory")
|
||||||
|
|
||||||
local DecoratorBookmarks = require("nvim-tree.renderer.decorator.bookmarks")
|
local DecoratorBookmarks = require("nvim-tree.renderer.decorator.bookmarks")
|
||||||
@@ -33,50 +34,44 @@ local pad = require("nvim-tree.renderer.components.padding")
|
|||||||
---@field extmarks table[] extra marks for right icon placement
|
---@field extmarks table[] extra marks for right icon placement
|
||||||
---@field virtual_lines table[] virtual lines for hidden count display
|
---@field virtual_lines table[] virtual lines for hidden count display
|
||||||
---@field private explorer Explorer
|
---@field private explorer Explorer
|
||||||
---@field private opts table
|
|
||||||
---@field private index number
|
---@field private index number
|
||||||
---@field private depth number
|
---@field private depth number
|
||||||
---@field private combined_groups table<string, boolean> combined group names
|
---@field private combined_groups table<string, boolean> combined group names
|
||||||
---@field private markers boolean[] indent markers
|
---@field private markers boolean[] indent markers
|
||||||
---@field private decorators Decorator[]
|
---@field private decorators Decorator[]
|
||||||
---@field private hidden_display fun(node: Node): string|nil
|
---@field private hidden_display fun(node: Node): string|nil
|
||||||
local Builder = {}
|
local Builder = Class:extend()
|
||||||
|
|
||||||
---@param opts table user options
|
---@class Builder
|
||||||
---@param explorer Explorer
|
---@overload fun(args: BuilderArgs): Builder
|
||||||
---@return Builder
|
|
||||||
function Builder:new(opts, explorer)
|
---@class (exact) BuilderArgs
|
||||||
---@type Builder
|
---@field explorer Explorer
|
||||||
local o = {
|
|
||||||
opts = opts,
|
---@param args BuilderArgs
|
||||||
explorer = explorer,
|
function Builder:new(args)
|
||||||
index = 0,
|
self.explorer = args.explorer
|
||||||
depth = 0,
|
self.index = 0
|
||||||
hl_args = {},
|
self.depth = 0
|
||||||
combined_groups = {},
|
self.hl_args = {}
|
||||||
lines = {},
|
self.combined_groups = {}
|
||||||
markers = {},
|
self.lines = {}
|
||||||
signs = {},
|
self.markers = {}
|
||||||
extmarks = {},
|
self.signs = {}
|
||||||
virtual_lines = {},
|
self.extmarks = {}
|
||||||
decorators = {
|
self.virtual_lines = {}
|
||||||
|
self.decorators = {
|
||||||
-- priority order
|
-- priority order
|
||||||
DecoratorCut({ explorer = explorer }),
|
DecoratorCut({ explorer = args.explorer }),
|
||||||
DecoratorCopied({ explorer = explorer }),
|
DecoratorCopied({ explorer = args.explorer }),
|
||||||
DecoratorDiagnostics({ explorer = explorer }),
|
DecoratorDiagnostics({ explorer = args.explorer }),
|
||||||
DecoratorBookmarks({ explorer = explorer }),
|
DecoratorBookmarks({ explorer = args.explorer }),
|
||||||
DecoratorModified({ explorer = explorer }),
|
DecoratorModified({ explorer = args.explorer }),
|
||||||
DecoratorHidden({ explorer = explorer }),
|
DecoratorHidden({ explorer = args.explorer }),
|
||||||
DecoratorOpened({ explorer = explorer }),
|
DecoratorOpened({ explorer = args.explorer }),
|
||||||
DecoratorGit({ explorer = explorer })
|
DecoratorGit({ explorer = args.explorer })
|
||||||
},
|
|
||||||
hidden_display = Builder:setup_hidden_display_function(opts),
|
|
||||||
}
|
}
|
||||||
|
self.hidden_display = Builder:setup_hidden_display_function(args.explorer.opts)
|
||||||
setmetatable(o, self)
|
|
||||||
self.__index = self
|
|
||||||
|
|
||||||
return o
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Insert ranged highlight groups into self.highlights
|
---Insert ranged highlight groups into self.highlights
|
||||||
@@ -123,7 +118,7 @@ function Builder:format_line(indent_markers, arrows, icon, name, node)
|
|||||||
end
|
end
|
||||||
for _, v in ipairs(t2) do
|
for _, v in ipairs(t2) do
|
||||||
if added_len > 0 then
|
if added_len > 0 then
|
||||||
table.insert(t1, { str = self.opts.renderer.icons.padding })
|
table.insert(t1, { str = self.explorer.opts.renderer.icons.padding })
|
||||||
end
|
end
|
||||||
table.insert(t1, v)
|
table.insert(t1, v)
|
||||||
end
|
end
|
||||||
@@ -284,7 +279,7 @@ function Builder:add_hidden_count_string(node, idx, num_children)
|
|||||||
local hidden_count_string = self.hidden_display(node.hidden_stats)
|
local hidden_count_string = self.hidden_display(node.hidden_stats)
|
||||||
if hidden_count_string and hidden_count_string ~= "" then
|
if hidden_count_string and hidden_count_string ~= "" then
|
||||||
local indent_markers = pad.get_indent_markers(self.depth, idx or 0, num_children or 0, node, self.markers, 1)
|
local indent_markers = pad.get_indent_markers(self.depth, idx or 0, num_children or 0, node, self.markers, 1)
|
||||||
local indent_width = self.opts.renderer.indent_width
|
local indent_width = self.explorer.opts.renderer.indent_width
|
||||||
|
|
||||||
local indent_padding = string.rep(" ", indent_width)
|
local indent_padding = string.rep(" ", indent_width)
|
||||||
local indent_string = indent_padding .. indent_markers.str
|
local indent_string = indent_padding .. indent_markers.str
|
||||||
@@ -354,16 +349,16 @@ end
|
|||||||
---@private
|
---@private
|
||||||
function Builder:build_header()
|
function Builder:build_header()
|
||||||
if view.is_root_folder_visible(self.explorer.absolute_path) then
|
if view.is_root_folder_visible(self.explorer.absolute_path) then
|
||||||
local root_name = self:format_root_name(self.opts.renderer.root_folder_label)
|
local root_name = self:format_root_name(self.explorer.opts.renderer.root_folder_label)
|
||||||
table.insert(self.lines, root_name)
|
table.insert(self.lines, root_name)
|
||||||
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name))
|
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name))
|
||||||
self.index = 1
|
self.index = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.explorer.live_filter.filter then
|
if self.explorer.live_filter.filter then
|
||||||
local filter_line = string.format("%s/%s/", self.opts.live_filter.prefix, self.explorer.live_filter.filter)
|
local filter_line = string.format("%s/%s/", self.explorer.opts.live_filter.prefix, self.explorer.live_filter.filter)
|
||||||
table.insert(self.lines, filter_line)
|
table.insert(self.lines, filter_line)
|
||||||
local prefix_length = string.len(self.opts.live_filter.prefix)
|
local prefix_length = string.len(self.explorer.opts.live_filter.prefix)
|
||||||
self:insert_highlight({ "NvimTreeLiveFilterPrefix" }, 0, prefix_length)
|
self:insert_highlight({ "NvimTreeLiveFilterPrefix" }, 0, prefix_length)
|
||||||
self:insert_highlight({ "NvimTreeLiveFilterValue" }, prefix_length, string.len(filter_line))
|
self:insert_highlight({ "NvimTreeLiveFilterValue" }, prefix_length, string.len(filter_line))
|
||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local log = require("nvim-tree.log")
|
|||||||
local view = require("nvim-tree.view")
|
local view = require("nvim-tree.view")
|
||||||
local events = require("nvim-tree.events")
|
local events = require("nvim-tree.events")
|
||||||
|
|
||||||
|
local Class = require("nvim-tree.classic")
|
||||||
local Builder = require("nvim-tree.renderer.builder")
|
local Builder = require("nvim-tree.renderer.builder")
|
||||||
|
|
||||||
local SIGN_GROUP = "NvimTreeRendererSigns"
|
local SIGN_GROUP = "NvimTreeRendererSigns"
|
||||||
@@ -10,26 +11,19 @@ local namespace_highlights_id = vim.api.nvim_create_namespace("NvimTreeHighlight
|
|||||||
local namespace_extmarks_id = vim.api.nvim_create_namespace("NvimTreeExtmarks")
|
local namespace_extmarks_id = vim.api.nvim_create_namespace("NvimTreeExtmarks")
|
||||||
local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtualLines")
|
local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtualLines")
|
||||||
|
|
||||||
---@class (exact) Renderer
|
---@class (exact) Renderer: Class
|
||||||
---@field private __index? table
|
---@field explorer Explorer
|
||||||
---@field private opts table user options
|
local Renderer = Class:extend()
|
||||||
---@field private explorer Explorer
|
|
||||||
local Renderer = {}
|
|
||||||
|
|
||||||
---@param opts table user options
|
---@class Renderer
|
||||||
---@param explorer Explorer
|
---@overload fun(args: RendererArgs): Renderer
|
||||||
---@return Renderer
|
|
||||||
function Renderer:new(opts, explorer)
|
|
||||||
---@type Renderer
|
|
||||||
local o = {
|
|
||||||
opts = opts,
|
|
||||||
explorer = explorer,
|
|
||||||
}
|
|
||||||
|
|
||||||
setmetatable(o, self)
|
---@class (exact) RendererArgs
|
||||||
self.__index = self
|
---@field explorer Explorer
|
||||||
|
|
||||||
return o
|
---@param args RendererArgs
|
||||||
|
function Renderer:new(args)
|
||||||
|
self.explorer = args.explorer
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
@@ -106,7 +100,7 @@ function Renderer:draw()
|
|||||||
|
|
||||||
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr() or 0)
|
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr() or 0)
|
||||||
|
|
||||||
local builder = Builder:new(self.opts, self.explorer):build()
|
local builder = Builder(self.explorer):build()
|
||||||
|
|
||||||
self:_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
self:_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user