chore: resolve undefined-field
This commit is contained in:
@@ -11,14 +11,14 @@ local MAX_DEPTH = 100
|
||||
|
||||
---Return the status of the node or nil if no status, depending on the type of
|
||||
---status.
|
||||
---@param node table node to inspect
|
||||
---@param node Node to inspect
|
||||
---@param what string type of status
|
||||
---@param skip_gitignored boolean default false
|
||||
---@return boolean
|
||||
local function status_is_valid(node, what, skip_gitignored)
|
||||
if what == "git" then
|
||||
local git_status = node:get_git_status()
|
||||
return git_status ~= nil and (not skip_gitignored or git_status[1] ~= "!!")
|
||||
local git_xy = node:get_git_xy()
|
||||
return git_xy ~= nil and (not skip_gitignored or git_xy[1] ~= "!!")
|
||||
elseif what == "diag" then
|
||||
local diag_status = diagnostics.get_diag_status(node)
|
||||
return diag_status ~= nil and diag_status.value ~= nil
|
||||
|
||||
@@ -7,19 +7,19 @@ local Watcher = require("nvim-tree.watcher").Watcher
|
||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---Git xy short-format statuses for a single node
|
||||
---Git short format status xy
|
||||
---@alias GitXY string
|
||||
|
||||
-- Git short-format status
|
||||
---@alias GitPathXY table<string, GitXY>
|
||||
|
||||
-- Git short-format statuses
|
||||
---@alias GitPathXYs table<string, GitXY[]>
|
||||
|
||||
---Git short-format statuses for a single node
|
||||
---@class (exact) GitNodeStatus
|
||||
---@field file string?
|
||||
---@field dir table<"direct" | "indirect", string[]>?
|
||||
|
||||
-- Git xy short-format status
|
||||
---@alias GitPathXY table<string, string>
|
||||
|
||||
-- Git xy short-format statuses
|
||||
---@alias GitPathXYs table<string, string[]>
|
||||
|
||||
---@alias GitProjectFiles GitPathXY
|
||||
---@alias GitProjectDirs table<"direct" | "indirect", GitPathXYs>
|
||||
---@field file GitXY
|
||||
---@field dir table<"direct" | "indirect", GitXY[]>?
|
||||
|
||||
---Git state for an entire repo
|
||||
---@class (exact) GitProject
|
||||
@@ -27,6 +27,9 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
||||
---@field dirs GitProjectDirs?
|
||||
---@field watcher Watcher?
|
||||
|
||||
---@alias GitProjectFiles GitPathXY
|
||||
---@alias GitProjectDirs table<"direct" | "indirect", GitPathXYs>
|
||||
|
||||
local M = {
|
||||
config = {},
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ function DirectoryLinkNode:destroy()
|
||||
DirectoryNode.destroy(self)
|
||||
end
|
||||
|
||||
---Update the directory GitStatus of link target and the file status of the link itself
|
||||
---Update the directory git_status of link target and the file status of the link itself
|
||||
---@param parent_ignored boolean
|
||||
---@param status table|nil
|
||||
function DirectoryLinkNode:update_git_status(parent_ignored, status)
|
||||
|
||||
@@ -65,41 +65,41 @@ function DirectoryNode:destroy()
|
||||
Node.destroy(self)
|
||||
end
|
||||
|
||||
---Update the GitStatus of the directory
|
||||
---Update the git_status of the directory
|
||||
---@param parent_ignored boolean
|
||||
---@param status table|nil
|
||||
function DirectoryNode:update_git_status(parent_ignored, status)
|
||||
self.git_status = git_utils.git_status_dir(parent_ignored, status, self.absolute_path, nil)
|
||||
end
|
||||
|
||||
---@return string[]? xy short-format statuses
|
||||
function DirectoryNode:get_git_status()
|
||||
---@return GitXY[]?
|
||||
function DirectoryNode:get_git_xy()
|
||||
if not self.git_status or not self.explorer.opts.git.show_on_dirs then
|
||||
return nil
|
||||
end
|
||||
|
||||
local status = {}
|
||||
local xys = {}
|
||||
if not self:last_group_node().open or self.explorer.opts.git.show_on_open_dirs then
|
||||
-- dir is closed or we should show on open_dirs
|
||||
if self.git_status.file ~= nil then
|
||||
table.insert(status, self.git_status.file)
|
||||
table.insert(xys, self.git_status.file)
|
||||
end
|
||||
if self.git_status.dir ~= nil then
|
||||
if self.git_status.dir.direct ~= nil then
|
||||
for _, s in pairs(self.git_status.dir.direct) do
|
||||
table.insert(status, s)
|
||||
table.insert(xys, s)
|
||||
end
|
||||
end
|
||||
if self.git_status.dir.indirect ~= nil then
|
||||
for _, s in pairs(self.git_status.dir.indirect) do
|
||||
table.insert(status, s)
|
||||
table.insert(xys, s)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- dir is open and we shouldn't show on open_dirs
|
||||
if self.git_status.file ~= nil then
|
||||
table.insert(status, self.git_status.file)
|
||||
table.insert(xys, self.git_status.file)
|
||||
end
|
||||
if self.git_status.dir ~= nil and self.git_status.dir.direct ~= nil then
|
||||
local deleted = {
|
||||
@@ -110,15 +110,15 @@ function DirectoryNode:get_git_status()
|
||||
}
|
||||
for _, s in pairs(self.git_status.dir.direct) do
|
||||
if deleted[s] then
|
||||
table.insert(status, s)
|
||||
table.insert(xys, s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #status == 0 then
|
||||
if #xys == 0 then
|
||||
return nil
|
||||
else
|
||||
return status
|
||||
return xys
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ function FileLinkNode:destroy()
|
||||
FileNode.destroy(self)
|
||||
end
|
||||
|
||||
---Update the GitStatus of the target otherwise the link itself
|
||||
---Update the git_status of the target otherwise the link itself
|
||||
---@param parent_ignored boolean
|
||||
---@param status table|nil
|
||||
function FileLinkNode:update_git_status(parent_ignored, status)
|
||||
|
||||
@@ -47,8 +47,8 @@ function FileNode:update_git_status(parent_ignored, status)
|
||||
self.git_status = git_utils.git_status_file(parent_ignored, status, self.absolute_path, nil)
|
||||
end
|
||||
|
||||
---@return string[]? xy short-format statuses
|
||||
function FileNode:get_git_status()
|
||||
---@return GitXY[]?
|
||||
function FileNode:get_git_xy()
|
||||
if not self.git_status then
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -19,7 +19,7 @@ local Node = Class:new()
|
||||
function Node:destroy()
|
||||
end
|
||||
|
||||
---Update the GitStatus of the node
|
||||
---Update the git_status of the node
|
||||
---Abstract
|
||||
---@param parent_ignored boolean
|
||||
---@param status table?
|
||||
@@ -27,8 +27,9 @@ function Node:update_git_status(parent_ignored, status)
|
||||
self:nop(parent_ignored, status)
|
||||
end
|
||||
|
||||
---@return string[]? xy short-format statuses
|
||||
function Node:get_git_status()
|
||||
---Short-format statuses
|
||||
---@return GitXY[]?
|
||||
function Node:get_git_xy()
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
|
||||
@@ -12,12 +12,12 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
||||
---@alias GitStatusStrings "deleted" | "ignored" | "renamed" | "staged" | "unmerged" | "unstaged" | "untracked"
|
||||
|
||||
---@alias GitIconsByStatus table<GitStatusStrings, GitHighlightedString> human status
|
||||
---@alias GitIconsByXY table<string, GitHighlightedString[]> porcelain status
|
||||
---@alias GitGlyphs table<GitStatusStrings, string> from opts
|
||||
---@alias GitIconsByXY table<GitXY, GitHighlightedString[]> porcelain status
|
||||
---@alias GitGlyphsByStatus table<GitStatusStrings, string> from opts
|
||||
|
||||
---@class (exact) DecoratorGit: Decorator
|
||||
---@field file_hl_by_xy table<string, string>?
|
||||
---@field folder_hl_by_xy table<string, string>?
|
||||
---@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()
|
||||
@@ -56,7 +56,7 @@ function DecoratorGit:create(opts, explorer)
|
||||
return o
|
||||
end
|
||||
|
||||
---@param glyphs GitGlyphs
|
||||
---@param glyphs GitGlyphsByStatus
|
||||
function DecoratorGit:build_icons_by_status(glyphs)
|
||||
self.icons_by_status = {}
|
||||
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
|
||||
@@ -154,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
|
||||
@@ -215,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:is(DirectoryNode) then
|
||||
return self.folder_hl_by_xy[git_status[1]]
|
||||
return self.folder_hl_by_xy[git_xy[1]]
|
||||
else
|
||||
return self.file_hl_by_xy[git_status[1]]
|
||||
return self.file_hl_by_xy[git_xy[1]]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user