chore: resolve undefined-field warnings, fix link git statuses, rewrite devicons (#2968)

* add todo

* refactor(#2886): multi instance: node class refactoring: extract links, *_git_status (#2944)

* extract DirectoryLinkNode and FileLinkNode, move Node methods to children

* temporarily move DirectoryNode methods into BaseNode for easier reviewing

* move mostly unchanged DirectoryNode methods back to BaseNode

* tidy

* git.git_status_file takes an array

* update git status of links

* luacheck hack

* safer git_status_dir

* refactor(#2886): multi instance: node class refactoring: DirectoryNode:expand_or_collapse (#2957)

move expand_or_collapse to DirectoryNode

* refactor(#2886): multi instance: node group functions refactoring (#2959)

* move last_group_node to DirectoryNode

* move add BaseNode:as and more doc

* revert parameter name changes

* revert parameter name changes

* add Class

* move group methods into DN

* tidy group methods

* tidy group methods

* tidy group methods

* tidy group methods

* parent is DirectoryNode

* tidy expand all

* BaseNode -> Node

* move watcher to DirectoryNode

* last_group_node is DirectoryNode only

* simplify create-file

* simplify parent

* simplify collapse-all

* simplify live-filter

* style

* move lib.get_cursor_position to Explorer

* move lib.get_node_at_cursor to Explorer

* move lib.get_nodes to Explorer

* move place_cursor_on_node to Explorer

* resolve resource leak in purge_all_state

* move many autocommands into Explorer

* post merge tidy

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* Revert "chore: resolve undefined-field"

This reverts commit be546ff18d41f28466b065c857e1e041659bd2c8.

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* Revert "chore: resolve undefined-field"

This reverts commit e82db1c44d.

* chore: resolve undefined-field

* chore: class new is now generic

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* Revert "chore: resolve undefined-field"

This reverts commit 0e9b844d22.

* move icon builders into node classes

* move icon builders into node classes

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* chore: resolve undefined-field

* move folder specifics from icons to Directory

* move folder specifics from icons to Directory

* move folder specifics from icons to Directory

* move folder specifics from icons to Directory

* move file specifics from icons to File

* clean up sorters

* chore: resolve undefined-field

* tidy hl icon name

* file devicon uses library to fall back

* file devicon uses library to fall back

* file devicon uses library to fall back
This commit is contained in:
Alexander Courtis
2024-11-03 14:06:12 +11:00
committed by GitHub
parent c22124b374
commit 610a1c189b
43 changed files with 1073 additions and 887 deletions

View File

@@ -1,24 +1,48 @@
local log = require("nvim-tree.log")
local utils = require("nvim-tree.utils")
local git_utils = require("nvim-tree.git.utils")
local Runner = require("nvim-tree.git.runner")
local GitRunner = require("nvim-tree.git.runner")
local Watcher = require("nvim-tree.watcher").Watcher
local Iterator = require("nvim-tree.iterators.node-iterator")
local DirectoryNode = require("nvim-tree.node.directory")
---@class GitStatus
---@field file string|nil
---@field dir table|nil
---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
---@field file GitXY?
---@field dir table<"direct" | "indirect", GitXY[]>?
---Git state for an entire repo
---@class (exact) GitProject
---@field files GitProjectFiles?
---@field dirs GitProjectDirs?
---@field watcher Watcher?
---@alias GitProjectFiles GitPathXY
---@alias GitProjectDirs table<"direct" | "indirect", GitPathXYs>
local M = {
config = {},
-- all projects keyed by toplevel
---all projects keyed by toplevel
---@type table<string, GitProject>
_projects_by_toplevel = {},
-- index of paths inside toplevels, false when not inside a project
---index of paths inside toplevels, false when not inside a project
---@type table<string, string|false>
_toplevels_by_path = {},
-- git dirs by toplevel
---@type table<string, string>
_git_dirs_by_toplevel = {},
}
@@ -34,35 +58,35 @@ local WATCHED_FILES = {
---@param toplevel string|nil
---@param path string|nil
---@param project table
---@param git_status table|nil
local function reload_git_status(toplevel, path, project, git_status)
---@param project GitProject
---@param project_files GitProjectFiles?
local function reload_git_project(toplevel, path, project, project_files)
if path then
for p in pairs(project.files) do
if p:find(path, 1, true) == 1 then
project.files[p] = nil
end
end
project.files = vim.tbl_deep_extend("force", project.files, git_status)
project.files = vim.tbl_deep_extend("force", project.files, project_files)
else
project.files = git_status
project.files = project_files or {}
end
project.dirs = git_utils.file_status_to_dir_status(project.files, toplevel)
project.dirs = git_utils.project_files_to_project_dirs(project.files, toplevel)
end
--- Is this path in a known ignored directory?
---@param path string
---@param project table git status
---@param project GitProject
---@return boolean
local function path_ignored_in_project(path, project)
if not path or not project then
return false
end
if project and project.files then
for file, status in pairs(project.files) do
if status == "!!" and vim.startswith(path, file) then
if project.files then
for p, xy in pairs(project.files) do
if xy == "!!" and vim.startswith(path, p) then
return true
end
end
@@ -70,9 +94,8 @@ local function path_ignored_in_project(path, project)
return false
end
--- Reload all projects
---@return table projects maybe empty
function M.reload()
---@return GitProject[] maybe empty
function M.reload_all_projects()
if not M.config.git.enable then
return {}
end
@@ -85,11 +108,12 @@ function M.reload()
end
--- Reload one project. Does nothing when no project or path is ignored
---@param toplevel string|nil
---@param path string|nil optional path to update only
---@param callback function|nil
---@param toplevel string?
---@param path string? optional path to update only
---@param callback function?
function M.reload_project(toplevel, path, callback)
local project = M._projects_by_toplevel[toplevel]
local project = M._projects_by_toplevel[toplevel] --[[@as GitProject]]
if not toplevel or not project or not M.config.git.enable then
if callback then
callback()
@@ -104,7 +128,8 @@ function M.reload_project(toplevel, path, callback)
return
end
local opts = {
---@type GitRunnerOpts
local runner_opts = {
toplevel = toplevel,
path = path,
list_untracked = git_utils.should_show_untracked(toplevel),
@@ -113,20 +138,21 @@ function M.reload_project(toplevel, path, callback)
}
if callback then
Runner.run(opts, function(git_status)
reload_git_status(toplevel, path, project, git_status)
---@param path_xy GitPathXY
runner_opts.callback = function(path_xy)
reload_git_project(toplevel, path, project, path_xy)
callback()
end)
end
GitRunner:run(runner_opts)
else
-- TODO #1974 use callback once async/await is available
local git_status = Runner.run(opts)
reload_git_status(toplevel, path, project, git_status)
reload_git_project(toplevel, path, project, GitRunner:run(runner_opts))
end
end
--- Retrieve a known project
---@param toplevel string|nil
---@return table|nil project
---@param toplevel string?
---@return GitProject? project
function M.get_project(toplevel)
return M._projects_by_toplevel[toplevel]
end
@@ -147,11 +173,10 @@ function M.get_toplevel(path)
return nil
end
if M._toplevels_by_path[path] then
return M._toplevels_by_path[path]
end
if M._toplevels_by_path[path] == false then
local tl = M._toplevels_by_path[path]
if tl then
return tl
elseif tl == false then
return nil
end
@@ -190,8 +215,15 @@ function M.get_toplevel(path)
end
M._toplevels_by_path[path] = toplevel
M._git_dirs_by_toplevel[toplevel] = git_dir
return M._toplevels_by_path[path]
toplevel = M._toplevels_by_path[path]
if toplevel == false then
return nil
else
return toplevel
end
end
local function reload_tree_at(toplevel)
@@ -206,13 +238,13 @@ local function reload_tree_at(toplevel)
end
M.reload_project(toplevel, nil, function()
local git_status = M.get_project(toplevel)
local project = M.get_project(toplevel)
Iterator.builder(root_node.nodes)
:hidden()
:applier(function(node)
local parent_ignored = node.parent and node.parent:is_git_ignored() or false
node:update_git_status(parent_ignored, git_status)
node:update_git_status(parent_ignored, project)
end)
:recursor(function(node)
return node.nodes and #node.nodes > 0 and node.nodes
@@ -226,8 +258,8 @@ end
--- Load the project status for a path. Does nothing when no toplevel for path.
--- Only fetches project status when unknown, otherwise returns existing.
---@param path string absolute
---@return table project maybe empty
function M.load_project_status(path)
---@return GitProject maybe empty
function M.load_project(path)
if not M.config.git.enable then
return {}
end
@@ -238,12 +270,12 @@ function M.load_project_status(path)
return {}
end
local status = M._projects_by_toplevel[toplevel]
if status then
return status
local project = M._projects_by_toplevel[toplevel]
if project then
return project
end
local git_status = Runner.run({
local path_xys = GitRunner:run({
toplevel = toplevel,
list_untracked = git_utils.should_show_untracked(toplevel),
list_ignored = true,
@@ -254,26 +286,27 @@ function M.load_project_status(path)
if M.config.filesystem_watchers.enable then
log.line("watcher", "git start")
---@param w Watcher
local callback = function(w)
log.line("watcher", "git event scheduled '%s'", w.toplevel)
utils.debounce("git:watcher:" .. w.toplevel, M.config.filesystem_watchers.debounce_delay, function()
log.line("watcher", "git event scheduled '%s'", w.data.toplevel)
utils.debounce("git:watcher:" .. w.data.toplevel, M.config.filesystem_watchers.debounce_delay, function()
if w.destroyed then
return
end
reload_tree_at(w.toplevel)
reload_tree_at(w.data.toplevel)
end)
end
local git_dir = vim.env.GIT_DIR or M._git_dirs_by_toplevel[toplevel] or utils.path_join({ toplevel, ".git" })
watcher = Watcher:new(git_dir, WATCHED_FILES, callback, {
watcher = Watcher:create(git_dir, WATCHED_FILES, callback, {
toplevel = toplevel,
})
end
if git_status then
if path_xys then
M._projects_by_toplevel[toplevel] = {
files = git_status,
dirs = git_utils.file_status_to_dir_status(git_status, toplevel),
files = path_xys,
dirs = git_utils.project_files_to_project_dirs(path_xys, toplevel),
watcher = watcher,
}
return M._projects_by_toplevel[toplevel]
@@ -283,46 +316,69 @@ function M.load_project_status(path)
end
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
---@param dir DirectoryNode
---@param project GitProject?
---@param root string?
function M.update_parent_projects(dir, project, root)
while project and dir do
-- step up to the containing project
if dir.absolute_path == root then
-- stop at the top of the tree
if not dir.parent then
break
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],
},
}
root = M.get_toplevel(dir.parent.absolute_path)
-- stop when no more projects
if not root then
break
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
---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 = "!!" }
---Refresh contents and git status for a single directory
---@param dir DirectoryNode
function M.refresh_dir(dir)
local node = dir:get_parent_of_group() or dir
local toplevel = M.get_toplevel(dir.absolute_path)
M.reload_project(toplevel, dir.absolute_path, function()
local project = M.get_project(toplevel) or {}
dir.explorer:reload(node, project)
M.update_parent_projects(dir, project, toplevel)
dir.explorer.renderer:draw()
end)
end
---@param dir DirectoryNode?
---@param projects GitProject[]
function M.reload_node_status(dir, projects)
dir = dir and dir:as(DirectoryNode)
if not dir or #dir.nodes == 0 then
return
end
if not status or not status.files then
return {}
local toplevel = M.get_toplevel(dir.absolute_path)
local project = projects[toplevel] or {}
for _, node in ipairs(dir.nodes) do
node:update_git_status(dir:is_git_ignored(), project)
M.reload_node_status(node:as(DirectoryNode), projects)
end
return {
file = status.files[path] or status.files[path_fallback]
}
end
function M.purge_state()

View File

@@ -2,9 +2,21 @@ local log = require("nvim-tree.log")
local utils = require("nvim-tree.utils")
local notify = require("nvim-tree.notify")
---@class Runner
local Runner = {}
Runner.__index = Runner
local Class = require("nvim-tree.class")
---@class (exact) GitRunnerOpts
---@field toplevel string absolute path
---@field path string? absolute path
---@field list_untracked boolean
---@field list_ignored boolean
---@field timeout integer
---@field callback fun(path_xy: GitPathXY)?
---@class (exact) GitRunner: Class
---@field private opts GitRunnerOpts
---@field private path_xy GitPathXY
---@field private rc integer? -- -1 indicates timeout
local GitRunner = Class:new()
local timeouts = 0
local MAX_TIMEOUTS = 5
@@ -12,7 +24,7 @@ local MAX_TIMEOUTS = 5
---@private
---@param status string
---@param path string|nil
function Runner:_parse_status_output(status, path)
function GitRunner:parse_status_output(status, path)
if not path then
return
end
@@ -22,7 +34,7 @@ function Runner:_parse_status_output(status, path)
path = path:gsub("/", "\\")
end
if #status > 0 and #path > 0 then
self.output[utils.path_remove_trailing(utils.path_join({ self.toplevel, path }))] = status
self.path_xy[utils.path_remove_trailing(utils.path_join({ self.opts.toplevel, path }))] = status
end
end
@@ -30,7 +42,7 @@ end
---@param prev_output string
---@param incoming string
---@return string
function Runner:_handle_incoming_data(prev_output, incoming)
function GitRunner:handle_incoming_data(prev_output, incoming)
if incoming and utils.str_find(incoming, "\n") then
local prev = prev_output .. incoming
local i = 1
@@ -45,7 +57,7 @@ function Runner:_handle_incoming_data(prev_output, incoming)
-- skip next line if it is a rename entry
skip_next_line = true
end
self:_parse_status_output(status, path)
self:parse_status_output(status, path)
end
i = i + #line
end
@@ -58,35 +70,38 @@ function Runner:_handle_incoming_data(prev_output, incoming)
end
for line in prev_output:gmatch("[^\n]*\n") do
self:_parse_status_output(line)
self:parse_status_output(line)
end
return ""
end
---@private
---@param stdout_handle uv.uv_pipe_t
---@param stderr_handle uv.uv_pipe_t
---@return table
function Runner:_getopts(stdout_handle, stderr_handle)
local untracked = self.list_untracked and "-u" or nil
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
---@return uv.spawn.options
function GitRunner:get_spawn_options(stdout_handle, stderr_handle)
local untracked = self.opts.list_untracked and "-u" or nil
local ignored = (self.opts.list_untracked and self.opts.list_ignored) and "--ignored=matching" or "--ignored=no"
return {
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.path },
cwd = self.toplevel,
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.opts.path },
cwd = self.opts.toplevel,
stdio = { nil, stdout_handle, stderr_handle },
}
end
---@private
---@param output string
function Runner:_log_raw_output(output)
function GitRunner:log_raw_output(output)
if log.enabled("git") and output and type(output) == "string" then
log.raw("git", "%s", output)
log.line("git", "done")
end
end
---@private
---@param callback function|nil
function Runner:_run_git_job(callback)
function GitRunner:run_git_job(callback)
local handle, pid
local stdout = vim.loop.new_pipe(false)
local stderr = vim.loop.new_pipe(false)
@@ -123,20 +138,20 @@ function Runner:_run_git_job(callback)
end
end
local opts = self:_getopts(stdout, stderr)
log.line("git", "running job with timeout %dms", self.timeout)
log.line("git", "git %s", table.concat(utils.array_remove_nils(opts.args), " "))
local spawn_options = self:get_spawn_options(stdout, stderr)
log.line("git", "running job with timeout %dms", self.opts.timeout)
log.line("git", "git %s", table.concat(utils.array_remove_nils(spawn_options.args), " "))
handle, pid = vim.loop.spawn(
"git",
opts,
spawn_options,
vim.schedule_wrap(function(rc)
on_finish(rc)
end)
)
timer:start(
self.timeout,
self.opts.timeout,
0,
vim.schedule_wrap(function()
on_finish(-1)
@@ -151,19 +166,20 @@ function Runner:_run_git_job(callback)
if data then
data = data:gsub("%z", "\n")
end
self:_log_raw_output(data)
output_leftover = self:_handle_incoming_data(output_leftover, data)
self:log_raw_output(data)
output_leftover = self:handle_incoming_data(output_leftover, data)
end
local function manage_stderr(_, data)
self:_log_raw_output(data)
self:log_raw_output(data)
end
vim.loop.read_start(stdout, vim.schedule_wrap(manage_stdout))
vim.loop.read_start(stderr, vim.schedule_wrap(manage_stderr))
end
function Runner:_wait()
---@private
function GitRunner:wait()
local function is_done()
return self.rc ~= nil
end
@@ -172,64 +188,69 @@ function Runner:_wait()
end
end
---@param opts table
function Runner:_finalise(opts)
---@private
function GitRunner:finalise()
if self.rc == -1 then
log.line("git", "job timed out %s %s", opts.toplevel, opts.path)
log.line("git", "job timed out %s %s", self.opts.toplevel, self.opts.path)
timeouts = timeouts + 1
if timeouts == MAX_TIMEOUTS then
notify.warn(string.format("%d git jobs have timed out after git.timeout %dms, disabling git integration.", timeouts, opts.timeout))
notify.warn(string.format("%d git jobs have timed out after git.timeout %dms, disabling git integration.", timeouts,
self.opts.timeout))
require("nvim-tree.git").disable_git_integration()
end
elseif self.rc ~= 0 then
log.line("git", "job fail rc %d %s %s", self.rc, opts.toplevel, opts.path)
log.line("git", "job fail rc %d %s %s", self.rc, self.opts.toplevel, self.opts.path)
else
log.line("git", "job success %s %s", opts.toplevel, opts.path)
log.line("git", "job success %s %s", self.opts.toplevel, self.opts.path)
end
end
--- Runs a git process, which will be killed if it takes more than timeout which defaults to 400ms
---@param opts table
---@param callback function|nil executed passing return when complete
---@return table|nil status by absolute path, nil if callback present
function Runner.run(opts, callback)
local self = setmetatable({
toplevel = opts.toplevel,
path = opts.path,
list_untracked = opts.list_untracked,
list_ignored = opts.list_ignored,
timeout = opts.timeout or 400,
output = {},
rc = nil, -- -1 indicates timeout
}, Runner)
---Return nil when callback present
---@private
---@return GitPathXY?
function GitRunner:execute()
local async = self.opts.callback ~= nil
local profile = log.profile_start("git %s job %s %s", async and "async" or "sync", self.opts.toplevel, self.opts.path)
local async = callback ~= nil
local profile = log.profile_start("git %s job %s %s", async and "async" or "sync", opts.toplevel, opts.path)
if async and callback then
if async and self.opts.callback then
-- async, always call back
self:_run_git_job(function()
self:run_git_job(function()
log.profile_end(profile)
self:_finalise(opts)
self:finalise()
callback(self.output)
self.opts.callback(self.path_xy)
end)
else
-- sync, maybe call back
self:_run_git_job()
self:_wait()
self:run_git_job()
self:wait()
log.profile_end(profile)
self:_finalise(opts)
self:finalise()
if callback then
callback(self.output)
if self.opts.callback then
self.opts.callback(self.path_xy)
else
return self.output
return self.path_xy
end
end
end
return Runner
---Static method to run a git process, which will be killed if it takes more than timeout
---Return nil when callback present
---@param opts GitRunnerOpts
---@return GitPathXY?
function GitRunner:run(opts)
---@type GitRunner
local runner = {
opts = opts,
path_xy = {},
}
runner = GitRunner:new(runner)
return runner:execute()
end
return GitRunner

View File

@@ -58,10 +58,11 @@ function M.get_toplevel(cwd)
return toplevel, git_dir
end
---@type table<string, boolean>
local untracked = {}
---@param cwd string
---@return string|nil
---@return boolean
function M.should_show_untracked(cwd)
if untracked[cwd] ~= nil then
return untracked[cwd]
@@ -81,8 +82,8 @@ function M.should_show_untracked(cwd)
return untracked[cwd]
end
---@param t table|nil
---@param k string
---@param t table<string|integer, boolean>?
---@param k string|integer
---@return table
local function nil_insert(t, k)
t = t or {}
@@ -90,31 +91,33 @@ local function nil_insert(t, k)
return t
end
---@param status table
---@param project_files GitProjectFiles
---@param cwd string|nil
---@return table
function M.file_status_to_dir_status(status, cwd)
local direct = {}
for p, s in pairs(status) do
---@return GitProjectDirs
function M.project_files_to_project_dirs(project_files, cwd)
---@type GitProjectDirs
local project_dirs = {}
project_dirs.direct = {}
for p, s in pairs(project_files) do
if s ~= "!!" then
local modified = vim.fn.fnamemodify(p, ":h")
direct[modified] = nil_insert(direct[modified], s)
project_dirs.direct[modified] = nil_insert(project_dirs.direct[modified], s)
end
end
local indirect = {}
for dirname, statuses in pairs(direct) do
project_dirs.indirect = {}
for dirname, statuses in pairs(project_dirs.direct) do
for s, _ in pairs(statuses) do
local modified = dirname
while modified ~= cwd and modified ~= "/" do
modified = vim.fn.fnamemodify(modified, ":h")
indirect[modified] = nil_insert(indirect[modified], s)
project_dirs.indirect[modified] = nil_insert(project_dirs.indirect[modified], s)
end
end
end
local r = { indirect = indirect, direct = direct }
for _, d in pairs(r) do
for _, d in pairs(project_dirs) do
for dirname, statuses in pairs(d) do
local new_statuses = {}
for s, _ in pairs(statuses) do
@@ -123,7 +126,60 @@ function M.file_status_to_dir_status(status, cwd)
d[dirname] = new_statuses
end
end
return r
return project_dirs
end
---Git file status for an absolute path
---@param parent_ignored boolean
---@param project GitProject?
---@param path string
---@param path_fallback string? alternative file path when no other file status
---@return GitNodeStatus
function M.git_status_file(parent_ignored, project, path, path_fallback)
---@type GitNodeStatus
local ns
if parent_ignored then
ns = {
file = "!!"
}
elseif project and project.files then
ns = {
file = project.files[path] or project.files[path_fallback]
}
else
ns = {}
end
return ns
end
---Git file and directory status for an absolute path
---@param parent_ignored boolean
---@param project GitProject?
---@param path string
---@param path_fallback string? alternative file path when no other file status
---@return GitNodeStatus?
function M.git_status_dir(parent_ignored, project, path, path_fallback)
---@type GitNodeStatus?
local ns
if parent_ignored then
ns = {
file = "!!"
}
elseif project then
ns = {
file = project.files and (project.files[path] or project.files[path_fallback]),
dir = project.dirs and {
direct = project.dirs.direct and project.dirs.direct[path],
indirect = project.dirs.indirect and project.dirs.indirect[path],
},
}
end
return ns
end
function M.setup(opts)