chore: resolve undefined-field

This commit is contained in:
Alexander Courtis
2024-10-25 14:55:00 +11:00
parent 7fd4cc8113
commit e115199c5f
3 changed files with 21 additions and 17 deletions

View File

@@ -37,4 +37,9 @@ function Class:as(class)
return self:is(class) and self or nil
end
-- avoid unused param warnings in abstract methods
---@param ... any
function Class:nop(...)
end
return Class

View File

@@ -139,6 +139,19 @@ function DirectoryNode:refresh()
end)
end
---@param projects table
function DirectoryNode: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)
local dir = node:as(DirectoryNode)
if dir and #dir.nodes > 0 then
dir:reload_node_status(projects)
end
end
end
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
---@return DirectoryNode
function DirectoryNode:last_group_node()

View File

@@ -21,32 +21,18 @@ local Node = Class:new()
function Node:destroy()
end
--luacheck: push ignore 212
---Update the GitStatus 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
function Node:update_git_status(parent_ignored, status)
self:nop(parent_ignored, status)
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
end
---@return boolean
function Node:is_git_ignored()
return self.git_status ~= nil and self.git_status.file == "!!"