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
@@ -1,5 +1,3 @@
|
||||
local git = require("nvim-tree.git")
|
||||
|
||||
local Class = require("nvim-tree.class")
|
||||
|
||||
---Abstract Node class.
|
||||
@@ -10,41 +8,28 @@ local Class = require("nvim-tree.class")
|
||||
---@field absolute_path string
|
||||
---@field executable boolean
|
||||
---@field fs_stat uv.fs_stat.result?
|
||||
---@field git_status GitStatus?
|
||||
---@field git_status GitNodeStatus?
|
||||
---@field hidden boolean
|
||||
---@field name string
|
||||
---@field parent DirectoryNode?
|
||||
---@field diag_status DiagStatus?
|
||||
---@field is_dot boolean cached is_dotfile
|
||||
---@field private is_dot boolean cached is_dotfile
|
||||
local Node = Class:new()
|
||||
|
||||
function Node:destroy()
|
||||
end
|
||||
|
||||
--luacheck: push ignore 212
|
||||
---Update the GitStatus of the node
|
||||
---Update the git_status of the node
|
||||
---Abstract
|
||||
---@param parent_ignored boolean
|
||||
---@param status table?
|
||||
function Node:update_git_status(parent_ignored, status) ---@diagnostic disable-line: unused-local
|
||||
---TODO find a way to declare abstract methods
|
||||
---@param project GitProject?
|
||||
function Node:update_git_status(parent_ignored, project)
|
||||
self:nop(parent_ignored, project)
|
||||
end
|
||||
|
||||
--luacheck: pop
|
||||
|
||||
---@return GitStatus?
|
||||
function Node:get_git_status()
|
||||
end
|
||||
|
||||
---@param projects table
|
||||
function Node:reload_node_status(projects)
|
||||
local toplevel = git.get_toplevel(self.absolute_path)
|
||||
local status = projects[toplevel] or {}
|
||||
for _, node in ipairs(self.nodes) do
|
||||
node:update_git_status(self:is_git_ignored(), status)
|
||||
if node.nodes and #node.nodes > 0 then
|
||||
node:reload_node_status(projects)
|
||||
end
|
||||
end
|
||||
---Short-format statuses
|
||||
---@return GitXY[]?
|
||||
function Node:get_git_xy()
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
@@ -66,38 +51,6 @@ function Node:is_dotfile()
|
||||
return false
|
||||
end
|
||||
|
||||
---@param project table?
|
||||
---@param root string?
|
||||
function Node:update_parent_statuses(project, root)
|
||||
local node = self
|
||||
while project and node do
|
||||
-- step up to the containing project
|
||||
if node.absolute_path == root then
|
||||
-- stop at the top of the tree
|
||||
if not node.parent then
|
||||
break
|
||||
end
|
||||
|
||||
root = git.get_toplevel(node.parent.absolute_path)
|
||||
|
||||
-- stop when no more projects
|
||||
if not root then
|
||||
break
|
||||
end
|
||||
|
||||
-- update the containing project
|
||||
project = git.get_project(root)
|
||||
git.reload_project(root, node.absolute_path, nil)
|
||||
end
|
||||
|
||||
-- update status
|
||||
node:update_git_status(node.parent and node.parent:is_git_ignored() or false, project)
|
||||
|
||||
-- maybe parent
|
||||
node = node.parent
|
||||
end
|
||||
end
|
||||
|
||||
---Get the highest parent of grouped nodes, nil when not grouped
|
||||
---@return DirectoryNode?
|
||||
function Node:get_parent_of_group()
|
||||
@@ -115,6 +68,34 @@ function Node:get_parent_of_group()
|
||||
end
|
||||
end
|
||||
|
||||
---Empty highlighted icon
|
||||
---@protected
|
||||
---@return HighlightedString icon
|
||||
function Node:highlighted_icon_empty()
|
||||
return { str = "", hl = {} }
|
||||
end
|
||||
|
||||
---Highlighted icon for the node
|
||||
---Empty for base Node
|
||||
---@return HighlightedString icon
|
||||
function Node:highlighted_icon()
|
||||
return self:highlighted_icon_empty()
|
||||
end
|
||||
|
||||
---Empty highlighted name
|
||||
---@protected
|
||||
---@return HighlightedString name
|
||||
function Node:highlighted_name_empty()
|
||||
return { str = "", hl = {} }
|
||||
end
|
||||
|
||||
---Highlighted name for the node
|
||||
---Empty for base Node
|
||||
---@return HighlightedString icon
|
||||
function Node:highlighted_name()
|
||||
return self:highlighted_name_empty()
|
||||
end
|
||||
|
||||
---Create a sanitized partial copy of a node, populating children recursively.
|
||||
---@return Node cloned
|
||||
function Node:clone()
|
||||
@@ -130,10 +111,10 @@ function Node:clone()
|
||||
fs_stat = self.fs_stat,
|
||||
git_status = self.git_status,
|
||||
hidden = self.hidden,
|
||||
is_dot = self.is_dot,
|
||||
name = self.name,
|
||||
parent = nil,
|
||||
diag_status = nil,
|
||||
is_dot = self.is_dot,
|
||||
}
|
||||
|
||||
return clone
|
||||
|
||||
Reference in New Issue
Block a user