refactor(git/status): rework entries into typed variants on porcelain v2

This commit is contained in:
2026-05-09 22:59:07 +02:00
parent a7932bab5a
commit 067594ef9e
9 changed files with 793 additions and 292 deletions
+17 -11
View File
@@ -49,9 +49,11 @@ function GitDecorator:new()
self.highlight_range = "name"
end
local status = require("git.status")
---@param node Node
---@return ow.Git.Status.Entry[]?
local function entries_for(node)
---@return ow.Git.Status.Mark[]?
local function marks_for(node)
local r = repo.find(node.absolute_path)
if not r then
return
@@ -64,20 +66,24 @@ local function entries_for(node)
local list = r.status:aggregate_at(rel)
return #list > 0 and list or nil
end
return r.status.entries[rel]
local entry = r.status.entries[rel]
if not entry then
return
end
return status.marks_for(entry)
end
---@param node Node
---@return { str: string, hl: string[] }[]?
function GitDecorator.icons(_, node)
local list = entries_for(node)
local list = marks_for(node)
if not list then
return
end
local out = {}
for _, entry in ipairs(list) do
if entry.kind ~= "ignored" then
table.insert(out, { str = entry.char, hl = { entry.hl } })
for _, mark in ipairs(list) do
if mark.hl ~= "GitIgnored" then
table.insert(out, { str = mark.char, hl = { mark.hl } })
end
end
return out
@@ -86,16 +92,16 @@ end
---@param node Node
---@return string?
function GitDecorator.highlight_group(_, node)
local list = entries_for(node)
local list = marks_for(node)
if not list then
return
end
local hl
for _, entry in ipairs(list) do
if entry.kind ~= "ignored" then
for _, mark in ipairs(list) do
if mark.hl ~= "GitIgnored" then
return
end
hl = hl or entry.hl
hl = hl or mark.hl
end
return hl
end