chore: resolve undefined-field
This commit is contained in:
@@ -478,7 +478,7 @@ function Explorer:reload_git()
|
|||||||
event_running = true
|
event_running = true
|
||||||
|
|
||||||
local projects = git.reload()
|
local projects = git.reload()
|
||||||
self:reload_node_status(projects)
|
git.reload_node_status(self, projects)
|
||||||
self.renderer:draw()
|
self.renderer:draw()
|
||||||
event_running = false
|
event_running = false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local log = require("nvim-tree.log")
|
local log = require("nvim-tree.log")
|
||||||
|
local git = require("nvim-tree.git")
|
||||||
local utils = require("nvim-tree.utils")
|
local utils = require("nvim-tree.utils")
|
||||||
local Watcher = require("nvim-tree.watcher").Watcher
|
local Watcher = require("nvim-tree.watcher").Watcher
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ function M.create_watcher(node)
|
|||||||
else
|
else
|
||||||
log.line("watcher", "node event executing refresh '%s'", node.absolute_path)
|
log.line("watcher", "node event executing refresh '%s'", node.absolute_path)
|
||||||
end
|
end
|
||||||
node:refresh()
|
git.refresh_dir(node)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ local git_utils = require("nvim-tree.git.utils")
|
|||||||
local GitRunner = require("nvim-tree.git.runner")
|
local GitRunner = require("nvim-tree.git.runner")
|
||||||
local Watcher = require("nvim-tree.watcher").Watcher
|
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 = nil -- circular dependency
|
local DirectoryNode = require("nvim-tree.node.directory")
|
||||||
|
|
||||||
---@class GitStatus -- xy short-format statuses
|
---@class GitStatus -- xy short-format statuses
|
||||||
---@field file string?
|
---@field file string?
|
||||||
@@ -289,46 +289,67 @@ function M.load_project_status(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Git file and directory status for an absolute path with optional file fallback
|
---@param dir DirectoryNode
|
||||||
---@param parent_ignored boolean
|
---@param project table?
|
||||||
---@param status table|nil
|
---@param root string?
|
||||||
---@param path string
|
function M.update_parent_statuses(dir, project, root)
|
||||||
---@param path_file string? alternative file path when no other file status
|
while project and dir do
|
||||||
---@return GitStatus|nil
|
-- step up to the containing project
|
||||||
function M.git_status_dir(parent_ignored, status, path, path_file)
|
if dir.absolute_path == root then
|
||||||
if parent_ignored then
|
-- stop at the top of the tree
|
||||||
return { file = "!!" }
|
if not dir.parent then
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
if status then
|
root = M.get_toplevel(dir.parent.absolute_path)
|
||||||
return {
|
|
||||||
file = status.files and (status.files[path] or status.files[path_file]),
|
-- stop when no more projects
|
||||||
dir = status.dirs and {
|
if not root then
|
||||||
direct = status.dirs.direct and status.dirs.direct[path],
|
break
|
||||||
indirect = status.dirs.indirect and status.dirs.indirect[path],
|
end
|
||||||
},
|
|
||||||
}
|
-- update the containing project
|
||||||
|
project = M.get_project(root)
|
||||||
|
M.reload_project(root, dir.absolute_path, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- update status
|
||||||
|
dir:update_git_status(dir.parent and dir.parent:is_git_ignored() or false, project)
|
||||||
|
|
||||||
|
-- maybe parent
|
||||||
|
dir = dir.parent
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Git file status for an absolute path with optional fallback
|
---Refresh contents and git status for a single directory
|
||||||
---@param parent_ignored boolean
|
---@param dir DirectoryNode
|
||||||
---@param status table|nil
|
function M.refresh_dir(dir)
|
||||||
---@param path string
|
local node = dir:get_parent_of_group() or dir
|
||||||
---@param path_fallback string?
|
local toplevel = M.get_toplevel(dir.absolute_path)
|
||||||
---@return GitStatus
|
|
||||||
function M.git_status_file(parent_ignored, status, path, path_fallback)
|
M.reload_project(toplevel, dir.absolute_path, function()
|
||||||
if parent_ignored then
|
local project = M.get_project(toplevel) or {}
|
||||||
return { file = "!!" }
|
|
||||||
|
dir.explorer:reload(node, project)
|
||||||
|
|
||||||
|
M.update_parent_statuses(dir, project, toplevel)
|
||||||
|
|
||||||
|
dir.explorer.renderer:draw()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not status or not status.files then
|
---@param n DirectoryNode
|
||||||
return {}
|
---@param projects table
|
||||||
|
function M.reload_node_status(n, projects)
|
||||||
|
local toplevel = M.get_toplevel(n.absolute_path)
|
||||||
|
local status = projects[toplevel] or {}
|
||||||
|
for _, node in ipairs(n.nodes) do
|
||||||
|
node:update_git_status(n:is_git_ignored(), status)
|
||||||
|
local dir = node:as(DirectoryNode)
|
||||||
|
if dir and #dir.nodes > 0 then
|
||||||
|
dir:reload_node_status(projects)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
|
||||||
file = status.files[path] or status.files[path_fallback]
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.purge_state()
|
function M.purge_state()
|
||||||
@@ -355,7 +376,6 @@ end
|
|||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.config.git = opts.git
|
M.config.git = opts.git
|
||||||
M.config.filesystem_watchers = opts.filesystem_watchers
|
M.config.filesystem_watchers = opts.filesystem_watchers
|
||||||
DirectoryNode = require("nvim-tree.node.directory")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -127,6 +127,48 @@ function M.file_status_to_dir_status(status, cwd)
|
|||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Git file status for an absolute path with optional fallback
|
||||||
|
---@param parent_ignored boolean
|
||||||
|
---@param status table|nil
|
||||||
|
---@param path string
|
||||||
|
---@param path_fallback string?
|
||||||
|
---@return GitStatus
|
||||||
|
function M.git_status_file(parent_ignored, status, path, path_fallback)
|
||||||
|
if parent_ignored then
|
||||||
|
return { file = "!!" }
|
||||||
|
end
|
||||||
|
|
||||||
|
if not status or not status.files then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
file = status.files[path] or status.files[path_fallback]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
---Git file and directory status for an absolute path with optional file fallback
|
||||||
|
---@param parent_ignored boolean
|
||||||
|
---@param status table|nil
|
||||||
|
---@param path string
|
||||||
|
---@param path_file string? alternative file path when no other file status
|
||||||
|
---@return GitStatus|nil
|
||||||
|
function M.git_status_dir(parent_ignored, status, path, path_file)
|
||||||
|
if parent_ignored then
|
||||||
|
return { file = "!!" }
|
||||||
|
end
|
||||||
|
|
||||||
|
if status then
|
||||||
|
return {
|
||||||
|
file = status.files and (status.files[path] or status.files[path_file]),
|
||||||
|
dir = status.dirs and {
|
||||||
|
direct = status.dirs.direct and status.dirs.direct[path],
|
||||||
|
indirect = status.dirs.indirect and status.dirs.indirect[path],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
if opts.git.cygwin_support then
|
if opts.git.cygwin_support then
|
||||||
M.use_cygpath = vim.fn.executable("cygpath") == 1
|
M.use_cygpath = vim.fn.executable("cygpath") == 1
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local git = require("nvim-tree.git")
|
local git_utils = require("nvim-tree.git.utils")
|
||||||
|
|
||||||
local DirectoryNode = require("nvim-tree.node.directory")
|
local DirectoryNode = require("nvim-tree.node.directory")
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ end
|
|||||||
-----@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)
|
||||||
self.git_status = git.git_status_dir(parent_ignored, status, self.link_to, self.absolute_path)
|
self.git_status = git_utils.git_status_dir(parent_ignored, status, self.link_to, self.absolute_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Create a sanitized partial copy of a node, populating children recursively.
|
---Create a sanitized partial copy of a node, populating children recursively.
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
local git = require("nvim-tree.git")
|
local git_utils = require("nvim-tree.git.utils")
|
||||||
local watch = require("nvim-tree.explorer.watch")
|
|
||||||
|
|
||||||
local Node = require("nvim-tree.node")
|
local Node = require("nvim-tree.node")
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ function DirectoryNode:create(explorer, parent, absolute_path, name, fs_stat)
|
|||||||
}
|
}
|
||||||
o = self:new(o) --[[@as DirectoryNode]]
|
o = self:new(o) --[[@as DirectoryNode]]
|
||||||
|
|
||||||
o.watcher = watch.create_watcher(o)
|
o.watcher = require("nvim-tree.explorer.watch").create_watcher(o)
|
||||||
|
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
@@ -70,7 +69,7 @@ end
|
|||||||
---@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.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 string[]? xy short-format statuses
|
||||||
@@ -123,35 +122,6 @@ function DirectoryNode:get_git_status()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Refresh contents and git status for a single node
|
|
||||||
function DirectoryNode:refresh()
|
|
||||||
local node = self:get_parent_of_group() or self
|
|
||||||
local toplevel = git.get_toplevel(self.absolute_path)
|
|
||||||
|
|
||||||
git.reload_project(toplevel, self.absolute_path, function()
|
|
||||||
local project = git.get_project(toplevel) or {}
|
|
||||||
|
|
||||||
self.explorer:reload(node, project)
|
|
||||||
|
|
||||||
node:update_parent_statuses(project, toplevel)
|
|
||||||
|
|
||||||
self.explorer.renderer:draw()
|
|
||||||
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.
|
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
|
||||||
---@return DirectoryNode
|
---@return DirectoryNode
|
||||||
function DirectoryNode:last_group_node()
|
function DirectoryNode:last_group_node()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local git = require("nvim-tree.git")
|
local git_utils = require("nvim-tree.git.utils")
|
||||||
|
|
||||||
local FileNode = require("nvim-tree.node.file")
|
local FileNode = require("nvim-tree.node.file")
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ end
|
|||||||
-----@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)
|
||||||
self.git_status = git.git_status_file(parent_ignored, status, self.link_to, self.absolute_path)
|
self.git_status = git_utils.git_status_file(parent_ignored, status, self.link_to, self.absolute_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Create a sanitized partial copy of a node
|
---Create a sanitized partial copy of a node
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local git = require("nvim-tree.git")
|
local git_utils = require("nvim-tree.git.utils")
|
||||||
local utils = require("nvim-tree.utils")
|
local utils = require("nvim-tree.utils")
|
||||||
|
|
||||||
local Node = require("nvim-tree.node")
|
local Node = require("nvim-tree.node")
|
||||||
@@ -44,7 +44,7 @@ end
|
|||||||
---@param parent_ignored boolean
|
---@param parent_ignored boolean
|
||||||
---@param status table|nil
|
---@param status table|nil
|
||||||
function FileNode:update_git_status(parent_ignored, status)
|
function FileNode:update_git_status(parent_ignored, status)
|
||||||
self.git_status = git.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 string[]? xy short-format statuses
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
local git = require("nvim-tree.git")
|
|
||||||
|
|
||||||
local Class = require("nvim-tree.class")
|
local Class = require("nvim-tree.class")
|
||||||
|
|
||||||
---Abstract Node class.
|
---Abstract Node class.
|
||||||
@@ -52,38 +50,6 @@ function Node:is_dotfile()
|
|||||||
return false
|
return false
|
||||||
end
|
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
|
---Get the highest parent of grouped nodes, nil when not grouped
|
||||||
---@return DirectoryNode?
|
---@return DirectoryNode?
|
||||||
function Node:get_parent_of_group()
|
function Node:get_parent_of_group()
|
||||||
|
|||||||
Reference in New Issue
Block a user