From 142cb30b3d54c5a6ca94d58e9fc0120ea89ba023 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 28 Oct 2024 15:37:19 +1100 Subject: [PATCH] chore: resolve undefined-field --- lua/nvim-tree/actions/moves/item.lua | 6 +++--- lua/nvim-tree/git/init.lua | 27 +++++++++++++----------- lua/nvim-tree/node/directory-link.lua | 2 +- lua/nvim-tree/node/directory.lua | 22 +++++++++---------- lua/nvim-tree/node/file-link.lua | 2 +- lua/nvim-tree/node/file.lua | 4 ++-- lua/nvim-tree/node/init.lua | 7 +++--- lua/nvim-tree/renderer/decorator/git.lua | 26 +++++++++++------------ 8 files changed, 50 insertions(+), 46 deletions(-) diff --git a/lua/nvim-tree/actions/moves/item.lua b/lua/nvim-tree/actions/moves/item.lua index edd4b5c3..f6555f57 100644 --- a/lua/nvim-tree/actions/moves/item.lua +++ b/lua/nvim-tree/actions/moves/item.lua @@ -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 diff --git a/lua/nvim-tree/git/init.lua b/lua/nvim-tree/git/init.lua index 74d159b4..548d5a4b 100644 --- a/lua/nvim-tree/git/init.lua +++ b/lua/nvim-tree/git/init.lua @@ -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 + +-- Git short-format statuses +---@alias GitPathXYs table + +---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 - --- Git xy short-format statuses ----@alias GitPathXYs table - ----@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 = {}, diff --git a/lua/nvim-tree/node/directory-link.lua b/lua/nvim-tree/node/directory-link.lua index 4b917ca2..15212e49 100644 --- a/lua/nvim-tree/node/directory-link.lua +++ b/lua/nvim-tree/node/directory-link.lua @@ -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) diff --git a/lua/nvim-tree/node/directory.lua b/lua/nvim-tree/node/directory.lua index f492129e..fb3c5287 100644 --- a/lua/nvim-tree/node/directory.lua +++ b/lua/nvim-tree/node/directory.lua @@ -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 diff --git a/lua/nvim-tree/node/file-link.lua b/lua/nvim-tree/node/file-link.lua index eebf3864..089b2a25 100644 --- a/lua/nvim-tree/node/file-link.lua +++ b/lua/nvim-tree/node/file-link.lua @@ -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) diff --git a/lua/nvim-tree/node/file.lua b/lua/nvim-tree/node/file.lua index 98cfaa55..22463f26 100644 --- a/lua/nvim-tree/node/file.lua +++ b/lua/nvim-tree/node/file.lua @@ -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 diff --git a/lua/nvim-tree/node/init.lua b/lua/nvim-tree/node/init.lua index 4b191a40..57e6f3ca 100644 --- a/lua/nvim-tree/node/init.lua +++ b/lua/nvim-tree/node/init.lua @@ -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 diff --git a/lua/nvim-tree/renderer/decorator/git.lua b/lua/nvim-tree/renderer/decorator/git.lua index 628b2d2e..4a543bcd 100644 --- a/lua/nvim-tree/renderer/decorator/git.lua +++ b/lua/nvim-tree/renderer/decorator/git.lua @@ -12,12 +12,12 @@ local DirectoryNode = require("nvim-tree.node.directory") ---@alias GitStatusStrings "deleted" | "ignored" | "renamed" | "staged" | "unmerged" | "unstaged" | "untracked" ---@alias GitIconsByStatus table human status ----@alias GitIconsByXY table porcelain status ----@alias GitGlyphs table from opts +---@alias GitIconsByXY table porcelain status +---@alias GitGlyphsByStatus table from opts ---@class (exact) DecoratorGit: Decorator ----@field file_hl_by_xy table? ----@field folder_hl_by_xy table? +---@field file_hl_by_xy table? +---@field folder_hl_by_xy table? ---@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