chore: resolve undefined-field warnings, fix link git statuses, rewrite devicons (#2968)

* add todo

* refactor(#2886): multi instance: node class refactoring: extract links, *_git_status (#2944)

* extract DirectoryLinkNode and FileLinkNode, move Node methods to children

* temporarily move DirectoryNode methods into BaseNode for easier reviewing

* move mostly unchanged DirectoryNode methods back to BaseNode

* tidy

* git.git_status_file takes an array

* update git status of links

* luacheck hack

* safer git_status_dir

* refactor(#2886): multi instance: node class refactoring: DirectoryNode:expand_or_collapse (#2957)

move expand_or_collapse to DirectoryNode

* refactor(#2886): multi instance: node group functions refactoring (#2959)

* move last_group_node to DirectoryNode

* move add BaseNode:as and more doc

* revert parameter name changes

* revert parameter name changes

* add Class

* move group methods into DN

* tidy group methods

* tidy group methods

* tidy group methods

* tidy group methods

* parent is DirectoryNode

* tidy expand all

* BaseNode -> Node

* move watcher to DirectoryNode

* last_group_node is DirectoryNode only

* simplify create-file

* simplify parent

* simplify collapse-all

* simplify live-filter

* style

* move lib.get_cursor_position to Explorer

* move lib.get_node_at_cursor to Explorer

* move lib.get_nodes to Explorer

* move place_cursor_on_node to Explorer

* resolve resource leak in purge_all_state

* move many autocommands into Explorer

* post merge tidy

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* Revert "chore: resolve undefined-field"

This reverts commit be546ff18d41f28466b065c857e1e041659bd2c8.

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* Revert "chore: resolve undefined-field"

This reverts commit e82db1c44d.

* chore: resolve undefined-field

* chore: class new is now generic

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* Revert "chore: resolve undefined-field"

This reverts commit 0e9b844d22.

* move icon builders into node classes

* move icon builders into node classes

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* move folder specifics from icons to Directory

* move folder specifics from icons to Directory

* move folder specifics from icons to Directory

* move folder specifics from icons to Directory

* move file specifics from icons to File

* clean up sorters

* chore: resolve undefined-field

* tidy hl icon name

* file devicon uses library to fall back

* file devicon uses library to fall back

* file devicon uses library to fall back
This commit is contained in:
Alexander Courtis
2024-11-03 14:06:12 +11:00
committed by GitHub
parent c22124b374
commit 610a1c189b
43 changed files with 1073 additions and 887 deletions

View File

@@ -2,9 +2,7 @@ local notify = require("nvim-tree.notify")
local utils = require("nvim-tree.utils")
local view = require("nvim-tree.view")
local DirectoryLinkNode = require("nvim-tree.node.directory-link")
local DirectoryNode = require("nvim-tree.node.directory")
local FileLinkNode = require("nvim-tree.node.file-link")
local DecoratorBookmarks = require("nvim-tree.renderer.decorator.bookmarks")
local DecoratorCopied = require("nvim-tree.renderer.decorator.copied")
@@ -16,16 +14,6 @@ local DecoratorHidden = require("nvim-tree.renderer.decorator.hidden")
local DecoratorOpened = require("nvim-tree.renderer.decorator.opened")
local pad = require("nvim-tree.renderer.components.padding")
local icons = require("nvim-tree.renderer.components.icons")
local PICTURE_MAP = {
jpg = true,
jpeg = true,
png = true,
gif = true,
webp = true,
jxl = true,
}
---@class (exact) HighlightedString
---@field str string
@@ -45,6 +33,7 @@ local PICTURE_MAP = {
---@field extmarks table[] extra marks for right icon placement
---@field virtual_lines table[] virtual lines for hidden count display
---@field private explorer Explorer
---@field private opts table
---@field private index number
---@field private depth number
---@field private combined_groups table<string, boolean> combined group names
@@ -99,27 +88,6 @@ function Builder:insert_highlight(groups, start, end_)
table.insert(self.hl_args, { groups, self.index, start, end_ or -1 })
end
---@private
function Builder:get_folder_name(node)
local name = node.name
local next = node.group_next
while next do
name = string.format("%s/%s", name, next.name)
next = next.group_next
end
if node.group_next and type(self.opts.renderer.group_empty) == "function" then
local new_name = self.opts.renderer.group_empty(name)
if type(new_name) == "string" then
name = new_name
else
notify.warn(string.format("Invalid return type for field renderer.group_empty. Expected string, got %s", type(new_name)))
end
end
return string.format("%s%s", name, self.opts.renderer.add_trailing and "/" or "")
end
---@private
---@param highlighted_strings HighlightedString[]
---@return string
@@ -140,82 +108,6 @@ function Builder:unwrap_highlighted_strings(highlighted_strings)
return string
end
---@private
---@param node Node
---@return HighlightedString icon
---@return HighlightedString name
function Builder:build_folder(node)
local has_children = #node.nodes ~= 0 or node.has_children
local icon, icon_hl = icons.get_folder_icon(node, has_children)
local foldername = self:get_folder_name(node)
if #icon > 0 and icon_hl == nil then
if node.open then
icon_hl = "NvimTreeOpenedFolderIcon"
else
icon_hl = "NvimTreeClosedFolderIcon"
end
end
local foldername_hl = "NvimTreeFolderName"
if node.link_to and self.opts.renderer.symlink_destination then
local arrow = icons.i.symlink_arrow
local link_to = utils.path_relative(node.link_to, self.explorer.absolute_path)
foldername = string.format("%s%s%s", foldername, arrow, link_to)
foldername_hl = "NvimTreeSymlinkFolderName"
elseif
vim.tbl_contains(self.opts.renderer.special_files, node.absolute_path) or vim.tbl_contains(self.opts.renderer.special_files, node.name)
then
foldername_hl = "NvimTreeSpecialFolderName"
elseif node.open then
foldername_hl = "NvimTreeOpenedFolderName"
elseif not has_children then
foldername_hl = "NvimTreeEmptyFolderName"
end
return { str = icon, hl = { icon_hl } }, { str = foldername, hl = { foldername_hl } }
end
---@private
---@param node table
---@return HighlightedString icon
---@return HighlightedString name
function Builder:build_symlink(node)
local icon = icons.i.symlink
local arrow = icons.i.symlink_arrow
local symlink_formatted = node.name
if self.opts.renderer.symlink_destination then
local link_to = utils.path_relative(node.link_to, self.explorer.absolute_path)
symlink_formatted = string.format("%s%s%s", symlink_formatted, arrow, link_to)
end
if self.opts.renderer.icons.show.file then
return { str = icon, hl = { "NvimTreeSymlinkIcon" } }, { str = symlink_formatted, hl = { "NvimTreeSymlink" } }
else
return { str = "", hl = {} }, { str = symlink_formatted, hl = { "NvimTreeSymlink" } }
end
end
---@private
---@param node Node
---@return HighlightedString icon
---@return HighlightedString name
function Builder:build_file(node)
local hl
if
vim.tbl_contains(self.opts.renderer.special_files, node.absolute_path) or vim.tbl_contains(self.opts.renderer.special_files, node.name)
then
hl = "NvimTreeSpecialFile"
elseif node.executable then
hl = "NvimTreeExecFile"
elseif PICTURE_MAP[node.extension] then
hl = "NvimTreeImageFile"
end
local icon, hl_group = icons.get_file_icon(node.name, node.extension)
return { str = icon, hl = { hl_group } }, { str = node.name, hl = { hl } }
end
---@private
---@param indent_markers HighlightedString[]
---@param arrows HighlightedString[]|nil
@@ -360,14 +252,7 @@ function Builder:build_line(node, idx, num_children)
local arrows = pad.get_arrows(node)
-- main components
local icon, name
if node:is(DirectoryNode) then
icon, name = self:build_folder(node)
elseif node:is(DirectoryLinkNode) or node:is(FileLinkNode) then
icon, name = self:build_symlink(node)
else
icon, name = self:build_file(node)
end
local icon, name = node:highlighted_icon(), node:highlighted_name()
-- highighting
local icon_hl_group, name_hl_group = self:add_highlights(node)
@@ -379,11 +264,12 @@ function Builder:build_line(node, idx, num_children)
self.index = self.index + 1
if node:is(DirectoryNode) then
node = node:last_group_node()
if node.open then
local dir = node:as(DirectoryNode)
if dir then
dir = dir:last_group_node()
if dir.open then
self.depth = self.depth + 1
self:build_lines(node)
self:build_lines(dir)
self.depth = self.depth - 1
end
end

View File

@@ -0,0 +1,35 @@
---@alias devicons_get_icon fun(name: string, ext: string?, opts: table?): string?, string?
---@alias devicons_setup fun(opts: table?)
---@class (strict) DevIcons?
---@field setup devicons_setup
---@field get_icon devicons_get_icon
local devicons
local M = {}
---Wrapper around nvim-web-devicons, nils if devicons not available
---@type devicons_get_icon
function M.get_icon(name, ext, opts)
if devicons then
return devicons.get_icon(name, ext, opts)
else
return nil, nil
end
end
---Attempt to use nvim-web-devicons if present and enabled for file or folder
---@param opts table
function M.setup(opts)
if opts.renderer.icons.show.file or opts.renderer.icons.show.folder then
local ok, di = pcall(require, "nvim-web-devicons")
if ok then
devicons = di --[[@as DevIcons]]
-- does nothing if already called i.e. doesn't clobber previous user setup
devicons.setup()
end
end
end
return M

View File

@@ -1,6 +1,8 @@
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local diagnostics = require("nvim-tree.diagnostics")
local DirectoryNode = require("nvim-tree.node.directory")
local M = {
-- highlight strings for the icons
HS_ICON = {},
@@ -24,7 +26,7 @@ function M.get_highlight(node)
local group
local diag_status = diagnostics.get_diag_status(node)
if node.nodes then
if node:is(DirectoryNode) then
group = M.HS_FOLDER[diag_status and diag_status.value]
else
group = M.HS_FILE[diag_status and diag_status.value]

View File

@@ -1,129 +0,0 @@
local M = { i = {} }
local function config_symlinks()
M.i.symlink = #M.config.glyphs.symlink > 0 and M.config.glyphs.symlink or ""
M.i.symlink_arrow = M.config.symlink_arrow
end
---@return string icon
---@return string? name
local function empty()
return "", nil
end
---@param node Node
---@param has_children boolean
---@return string icon
---@return string? name
local function get_folder_icon_default(node, has_children)
local is_symlink = node.link_to ~= nil
local n
if is_symlink and node.open then
n = M.config.glyphs.folder.symlink_open
elseif is_symlink then
n = M.config.glyphs.folder.symlink
elseif node.open then
if has_children then
n = M.config.glyphs.folder.open
else
n = M.config.glyphs.folder.empty_open
end
else
if has_children then
n = M.config.glyphs.folder.default
else
n = M.config.glyphs.folder.empty
end
end
return n, nil
end
---@param node Node
---@param has_children boolean
---@return string icon
---@return string? name
local function get_folder_icon_webdev(node, has_children)
local icon, hl_group = M.devicons.get_icon(node.name, node.extension)
if not M.config.web_devicons.folder.color then
hl_group = nil
end
if icon ~= nil then
return icon, hl_group
else
return get_folder_icon_default(node, has_children)
end
end
---@return string icon
---@return string? name
local function get_file_icon_default()
local hl_group = "NvimTreeFileIcon"
local icon = M.config.glyphs.default
if #icon > 0 then
return icon, hl_group
else
return "", nil
end
end
---@param fname string
---@param extension string
---@return string icon
---@return string? name
local function get_file_icon_webdev(fname, extension)
local icon, hl_group = M.devicons.get_icon(fname, extension)
if not M.config.web_devicons.file.color then
hl_group = "NvimTreeFileIcon"
end
if icon and hl_group ~= "DevIconDefault" then
return icon, hl_group
elseif string.match(extension, "%.(.*)") then
-- If there are more extensions to the file, try to grab the icon for them recursively
return get_file_icon_webdev(fname, string.match(extension, "%.(.*)"))
else
local devicons_default = M.devicons.get_default_icon()
if devicons_default and type(devicons_default.icon) == "string" and type(devicons_default.name) == "string" then
return devicons_default.icon, "DevIcon" .. devicons_default.name
else
return get_file_icon_default()
end
end
end
local function config_file_icon()
if M.config.show.file then
if M.devicons and M.config.web_devicons.file.enable then
M.get_file_icon = get_file_icon_webdev
else
M.get_file_icon = get_file_icon_default
end
else
M.get_file_icon = empty
end
end
local function config_folder_icon()
if M.config.show.folder then
if M.devicons and M.config.web_devicons.folder.enable then
M.get_folder_icon = get_folder_icon_webdev
else
M.get_folder_icon = get_folder_icon_default
end
else
M.get_folder_icon = empty
end
end
function M.reset_config()
config_symlinks()
config_file_icon()
config_folder_icon()
end
function M.setup(opts)
M.config = opts.renderer.icons
M.devicons = pcall(require, "nvim-web-devicons") and require("nvim-web-devicons") or nil
end
return M

View File

@@ -2,13 +2,13 @@ local M = {}
M.diagnostics = require("nvim-tree.renderer.components.diagnostics")
M.full_name = require("nvim-tree.renderer.components.full-name")
M.icons = require("nvim-tree.renderer.components.icons")
M.devicons = require("nvim-tree.renderer.components.devicons")
M.padding = require("nvim-tree.renderer.components.padding")
function M.setup(opts)
M.diagnostics.setup(opts)
M.full_name.setup(opts)
M.icons.setup(opts)
M.devicons.setup(opts)
M.padding.setup(opts)
end

View File

@@ -1,3 +1,5 @@
local DirectoryNode = require("nvim-tree.node.directory")
local M = {}
local function check_siblings_for_folder(node, with_arrows)
@@ -62,7 +64,7 @@ end
---@param node Node
---@param markers table
---@param early_stop integer?
---@return HighlightedString[]
---@return HighlightedString
function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop)
local str = ""
@@ -90,8 +92,9 @@ function M.get_arrows(node)
local str
local hl = "NvimTreeFolderArrowClosed"
if node.nodes then
if node.open then
local dir = node:as(DirectoryNode)
if dir then
if dir.open then
str = M.config.icons.glyphs.folder["arrow_open"] .. " "
hl = "NvimTreeFolderArrowOpen"
else

View File

@@ -19,7 +19,7 @@ function DecoratorBookmarks:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_bookmarks] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.bookmarks_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorBookmarks]]
o = self:new(o)
if opts.renderer.icons.show.bookmarks then
o.icon = {

View File

@@ -19,7 +19,7 @@ function DecoratorCopied:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorCopied]]
o = self:new(o)
return o
end

View File

@@ -18,7 +18,7 @@ function DecoratorCut:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorCut]]
o = self:new(o)
return o
end

View File

@@ -4,6 +4,7 @@ local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
local DirectoryNode = require("nvim-tree.node.directory")
-- highlight groups by severity
local HG_ICON = {
@@ -48,7 +49,7 @@ function DecoratorDiagnostics:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_diagnostics] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.diagnostics_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorDiagnostics]]
o = self:new(o)
if not o.enabled then
return o
@@ -98,7 +99,7 @@ function DecoratorDiagnostics:calculate_highlight(node)
end
local group
if node.nodes then
if node:is(DirectoryNode) then
group = HG_FOLDER[diag_value]
else
group = HG_FILE[diag_value]

View File

@@ -4,15 +4,22 @@ local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
local DirectoryNode = require("nvim-tree.node.directory")
---@class HighlightedStringGit: HighlightedString
---@class (exact) GitHighlightedString: HighlightedString
---@field ord number decreasing priority
---@alias GitStatusStrings "deleted" | "ignored" | "renamed" | "staged" | "unmerged" | "unstaged" | "untracked"
---@alias GitIconsByStatus table<GitStatusStrings, GitHighlightedString> human status
---@alias GitIconsByXY table<GitXY, GitHighlightedString[]> porcelain status
---@alias GitGlyphsByStatus table<GitStatusStrings, string> from opts
---@class (exact) DecoratorGit: Decorator
---@field file_hl table<string, string>? by porcelain status e.g. "AM"
---@field folder_hl table<string, string>? by porcelain status
---@field icons_by_status HighlightedStringGit[]? by human status
---@field icons_by_xy table<string, HighlightedStringGit[]>? by porcelain status
---@field file_hl_by_xy table<GitXY, string>?
---@field folder_hl_by_xy table<GitXY, string>?
---@field icons_by_status GitIconsByStatus?
---@field icons_by_xy GitIconsByXY?
local DecoratorGit = Decorator:new()
---Static factory method
@@ -27,14 +34,14 @@ function DecoratorGit:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_git] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.git_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorGit]]
o = self:new(o)
if not o.enabled then
return o
end
if o.hl_pos ~= HL_POSITION.none then
o:build_hl_table()
o:build_file_folder_hl_by_xy()
end
if opts.renderer.icons.show.git then
@@ -49,20 +56,19 @@ function DecoratorGit:create(opts, explorer)
return o
end
---@param glyphs table<string, string> user glyps
---@param glyphs GitGlyphsByStatus
function DecoratorGit:build_icons_by_status(glyphs)
self.icons_by_status = {
staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 },
unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 },
renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 },
deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 },
unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 },
untracked = { str = glyphs.untracked, hl = { "NvimTreeGitNewIcon" }, ord = 6 },
ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 },
}
self.icons_by_status = {}
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 }
self.icons_by_status.renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 }
self.icons_by_status.deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 }
self.icons_by_status.unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 }
self.icons_by_status.untracked = { str = glyphs.untracked, hl = { "NvimTreeGitNewIcon" }, ord = 6 }
self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 }
end
---@param icons HighlightedStringGit[]
---@param icons GitIconsByXY
function DecoratorGit:build_icons_by_xy(icons)
self.icons_by_xy = {
["M "] = { icons.staged },
@@ -100,8 +106,8 @@ function DecoratorGit:build_icons_by_xy(icons)
}
end
function DecoratorGit:build_hl_table()
self.file_hl = {
function DecoratorGit:build_file_folder_hl_by_xy()
self.file_hl_by_xy = {
["M "] = "NvimTreeGitFileStagedHL",
["C "] = "NvimTreeGitFileStagedHL",
["AA"] = "NvimTreeGitFileStagedHL",
@@ -134,9 +140,9 @@ function DecoratorGit:build_hl_table()
[" A"] = "none",
}
self.folder_hl = {}
for k, v in pairs(self.file_hl) do
self.folder_hl[k] = v:gsub("File", "Folder")
self.folder_hl_by_xy = {}
for k, v in pairs(self.file_hl_by_xy) do
self.folder_hl_by_xy[k] = v:gsub("File", "Folder")
end
end
@@ -148,19 +154,19 @@ function DecoratorGit:calculate_icons(node)
return nil
end
local git_status = node:get_git_status()
if git_status == nil then
local git_xy = node:get_git_xy()
if git_xy == nil then
return nil
end
local inserted = {}
local iconss = {}
for _, s in pairs(git_status) do
for _, s in pairs(git_xy) do
local icons = self.icons_by_xy[s]
if not icons then
if self.hl_pos == HL_POSITION.none then
notify.warn(string.format("Unrecognized git state '%s'", git_status))
notify.warn(string.format("Unrecognized git state '%s'", git_xy))
end
return nil
end
@@ -209,15 +215,15 @@ function DecoratorGit:calculate_highlight(node)
return nil
end
local git_status = node:get_git_status()
if not git_status then
local git_xy = node:get_git_xy()
if not git_xy then
return nil
end
if node.nodes then
return self.folder_hl[git_status[1]]
if node:is(DirectoryNode) then
return self.folder_hl_by_xy[git_xy[1]]
else
return self.file_hl[git_status[1]]
return self.file_hl_by_xy[git_xy[1]]
end
end

View File

@@ -1,6 +1,8 @@
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
local DirectoryNode = require("nvim-tree.node.directory")
---@class (exact) DecoratorHidden: Decorator
---@field icon HighlightedString?
@@ -18,7 +20,7 @@ function DecoratorHidden:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_hidden] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorHidden]]
o = self:new(o)
if opts.renderer.icons.show.hidden then
o.icon = {
@@ -48,7 +50,7 @@ function DecoratorHidden:calculate_highlight(node)
return nil
end
if node.nodes then
if node:is(DirectoryNode) then
return "NvimTreeHiddenFolderHL"
else
return "NvimTreeHiddenFileHL"

View File

@@ -4,6 +4,7 @@ local HL_POSITION = require("nvim-tree.enum").HL_POSITION
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT
local Decorator = require("nvim-tree.renderer.decorator")
local DirectoryNode = require("nvim-tree.node.directory")
---@class (exact) DecoratorModified: Decorator
---@field icon HighlightedString|nil
@@ -21,7 +22,7 @@ function DecoratorModified:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_modified] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT[opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorModified]]
o = self:new(o)
if not o.enabled then
return o
@@ -55,7 +56,7 @@ function DecoratorModified:calculate_highlight(node)
return nil
end
if node.nodes then
if node:is(DirectoryNode) then
return "NvimTreeModifiedFolderHL"
else
return "NvimTreeModifiedFileHL"

View File

@@ -21,7 +21,7 @@ function DecoratorOpened:create(opts, explorer)
hl_pos = HL_POSITION[opts.renderer.highlight_opened_files] or HL_POSITION.none,
icon_placement = ICON_PLACEMENT.none,
}
o = self:new(o) --[[@as DecoratorOpened]]
o = self:new(o)
return o
end

View File

@@ -2,8 +2,6 @@ local log = require("nvim-tree.log")
local view = require("nvim-tree.view")
local events = require("nvim-tree.events")
local icon_component = require("nvim-tree.renderer.components.icons")
local Builder = require("nvim-tree.renderer.builder")
local SIGN_GROUP = "NvimTreeRendererSigns"
@@ -16,7 +14,6 @@ local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtua
---@field private __index? table
---@field private opts table user options
---@field private explorer Explorer
---@field private builder Builder
local Renderer = {}
---@param opts table user options
@@ -27,7 +24,6 @@ function Renderer:new(opts, explorer)
local o = {
opts = opts,
explorer = explorer,
builder = Builder:new(opts, explorer),
}
setmetatable(o, self)
@@ -109,7 +105,6 @@ function Renderer:draw()
local profile = log.profile_start("draw")
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr() or 0)
icon_component.reset_config()
local builder = Builder:new(self.opts, self.explorer):build()