feat(nvim-tree): aggregate child git status onto directory nodes
This commit is contained in:
@@ -47,6 +47,7 @@ local STATUS_CMD = {
|
||||
"--porcelain=v1",
|
||||
"--branch",
|
||||
"--ignored",
|
||||
"--untracked-files=all",
|
||||
}
|
||||
|
||||
---@private
|
||||
|
||||
@@ -45,6 +45,29 @@ function Status:by_kind(kind)
|
||||
return out
|
||||
end
|
||||
|
||||
---@param prefix string
|
||||
---@return ow.Git.Status.Entry[]
|
||||
function Status:aggregate_at(prefix)
|
||||
local match = (prefix == "" or prefix == ".") and "" or prefix .. "/"
|
||||
local seen = {}
|
||||
local out = {}
|
||||
for path, list in pairs(self.entries) do
|
||||
if path == prefix or vim.startswith(path, match) then
|
||||
for _, e in ipairs(list) do
|
||||
local key = e.char .. "\0" .. e.hl
|
||||
if not seen[key] then
|
||||
seen[key] = true
|
||||
table.insert(out, e)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(out, function(a, b)
|
||||
return a.char < b.char
|
||||
end)
|
||||
return out
|
||||
end
|
||||
|
||||
---@param x string
|
||||
---@return string char, string hl
|
||||
local function staged_attrs(x)
|
||||
|
||||
+13
-3
@@ -57,7 +57,14 @@ local function entries_for(node)
|
||||
return
|
||||
end
|
||||
local rel = vim.fs.relpath(r.worktree, node.absolute_path)
|
||||
return rel and r.status.entries[rel]
|
||||
if not rel then
|
||||
return
|
||||
end
|
||||
if node.type == "directory" then
|
||||
local list = r.status:aggregate_at(rel)
|
||||
return #list > 0 and list or nil
|
||||
end
|
||||
return r.status.entries[rel]
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
@@ -83,11 +90,14 @@ function GitDecorator.highlight_group(_, node)
|
||||
if not list then
|
||||
return
|
||||
end
|
||||
local hl
|
||||
for _, entry in ipairs(list) do
|
||||
if entry.kind == "ignored" then
|
||||
return entry.hl
|
||||
if entry.kind ~= "ignored" then
|
||||
return
|
||||
end
|
||||
hl = hl or entry.hl
|
||||
end
|
||||
return hl
|
||||
end
|
||||
|
||||
local signs = require("lsp.diagnostic").signs
|
||||
|
||||
Reference in New Issue
Block a user