* Filtered dir with git status that are open when show_on_open_dir is false * refactored for single source of truth of existence of git status on a node Putting `has_git_status()` in `explorer.common` because that's where node.status is constructed Or at least I think that's where it's constructed * 1786 semantic nit Co-authored-by: Alexander Courtis <alex@courtis.org>
75 lines
1.8 KiB
Lua
75 lines
1.8 KiB
Lua
local M = {}
|
|
|
|
local function get_dir_git_status(parent_ignored, status, absolute_path)
|
|
if parent_ignored then
|
|
return "!!"
|
|
end
|
|
|
|
local file_status = status.files and status.files[absolute_path]
|
|
if file_status then
|
|
return file_status
|
|
end
|
|
|
|
return status.dirs and status.dirs[absolute_path]
|
|
end
|
|
|
|
local function get_git_status(parent_ignored, status, absolute_path)
|
|
return parent_ignored and "!!" or status.files and status.files[absolute_path]
|
|
end
|
|
|
|
function M.has_one_child_folder(node)
|
|
return #node.nodes == 1 and node.nodes[1].nodes and vim.loop.fs_access(node.nodes[1].absolute_path, "R")
|
|
end
|
|
|
|
function M.update_git_status(node, parent_ignored, status)
|
|
-- status of the node's absolute path
|
|
if node.nodes then
|
|
node.git_status = get_dir_git_status(parent_ignored, status, node.absolute_path)
|
|
else
|
|
node.git_status = get_git_status(parent_ignored, status, node.absolute_path)
|
|
end
|
|
|
|
-- status of the link target, if the link itself is not dirty
|
|
if node.link_to and not node.git_status then
|
|
if node.nodes then
|
|
node.git_status = get_dir_git_status(parent_ignored, status, node.link_to)
|
|
else
|
|
node.git_status = get_git_status(parent_ignored, status, node.link_to)
|
|
end
|
|
end
|
|
end
|
|
|
|
function M.shows_git_status(node)
|
|
if not node.git_status then
|
|
-- status doesn't exist
|
|
return false
|
|
elseif not node.nodes then
|
|
-- status exist and is a file
|
|
return true
|
|
elseif not node.open then
|
|
-- status exist, is a closed dir
|
|
return M.config.git.show_on_dirs
|
|
else
|
|
-- status exist, is a open dir
|
|
return M.config.git.show_on_dirs and M.config.git.show_on_open_dirs
|
|
end
|
|
end
|
|
|
|
function M.node_destroy(node)
|
|
if not node then
|
|
return
|
|
end
|
|
|
|
if node.watcher then
|
|
node.watcher:destroy()
|
|
end
|
|
end
|
|
|
|
function M.setup(opts)
|
|
M.config = {
|
|
git = opts.git,
|
|
}
|
|
end
|
|
|
|
return M
|