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