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 commite82db1c44d. * 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 commit0e9b844d22. * 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:
committed by
GitHub
parent
c22124b374
commit
610a1c189b
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user