feat(nvim-tree): aggregate child git status onto directory nodes
This commit is contained in:
@@ -47,6 +47,7 @@ local STATUS_CMD = {
|
|||||||
"--porcelain=v1",
|
"--porcelain=v1",
|
||||||
"--branch",
|
"--branch",
|
||||||
"--ignored",
|
"--ignored",
|
||||||
|
"--untracked-files=all",
|
||||||
}
|
}
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
|
|||||||
@@ -45,6 +45,29 @@ function Status:by_kind(kind)
|
|||||||
return out
|
return out
|
||||||
end
|
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
|
---@param x string
|
||||||
---@return string char, string hl
|
---@return string char, string hl
|
||||||
local function staged_attrs(x)
|
local function staged_attrs(x)
|
||||||
|
|||||||
+13
-3
@@ -57,7 +57,14 @@ local function entries_for(node)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local rel = vim.fs.relpath(r.worktree, node.absolute_path)
|
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
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
@@ -83,11 +90,14 @@ function GitDecorator.highlight_group(_, node)
|
|||||||
if not list then
|
if not list then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local hl
|
||||||
for _, entry in ipairs(list) do
|
for _, entry in ipairs(list) do
|
||||||
if entry.kind == "ignored" then
|
if entry.kind ~= "ignored" then
|
||||||
return entry.hl
|
return
|
||||||
end
|
end
|
||||||
|
hl = hl or entry.hl
|
||||||
end
|
end
|
||||||
|
return hl
|
||||||
end
|
end
|
||||||
|
|
||||||
local signs = require("lsp.diagnostic").signs
|
local signs = require("lsp.diagnostic").signs
|
||||||
|
|||||||
Reference in New Issue
Block a user