Skip to content

Commit 6fe36fc

Browse files
committed
feat: visually group subtasks in sidebar
1 parent 4e654e1 commit 6fe36fc

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

lua/overseer/component/dependencies.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ return {
3939
end
4040
new_task.cwd = new_task.cwd or task.cwd
4141
new_task.env = new_task.env or task.env
42+
new_task.parent_id = task.parent_id or task.id
4243
self.task_lookup[i] = new_task.id
4344
new_task:add_component({ "on_success_complete_dependency", task_id = task.id })
4445
-- Don't include child tasks when saving to bundle.

lua/overseer/strategy/orchestrator.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ function OrchestratorStrategy:start(task)
231231
task_defn.env = vim.tbl_deep_extend("force", task_defn.env or {}, params.env or {})
232232
end
233233
local new_task = Task.new(task_defn)
234+
new_task.parent_id = task.id
234235
new_task:add_component("orchestrator.on_status_broadcast")
235236
-- Don't include child tasks when saving to bundle. We will re-create them when the
236237
-- orchestration task is loaded.

lua/overseer/task.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ local STATUS = constants.STATUS
1818
---@field cmd string|string[]
1919
---@field cwd string
2020
---@field env? table<string, string>
21-
---@field strategy_defn nil|string|table
21+
---@field strategy_defn? string|table
2222
---@field strategy? overseer.Strategy
2323
---@field name string
24-
---@field bufnr number|nil
25-
---@field exit_code number|nil
24+
---@field private bufnr? number
25+
---@field exit_code? number
2626
---@field components overseer.Component[]
27-
---@field _subscribers table<string, function[]>
27+
---@field parent_id? integer ID of parent task. Used only to visually group tasks in the task list
28+
---@field private _subscribers table<string, function[]>
2829
local Task = {}
2930

3031
local next_id = 1
@@ -40,7 +41,7 @@ Task.params = {
4041
},
4142
}
4243

43-
---@class overseer.TaskDefinition
44+
---@class (exact) overseer.TaskDefinition
4445
---@field cmd string|string[]
4546
---@field args? string[]
4647
---@field name? string

lua/overseer/task_list/init.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ end
2222

2323
M.rerender = rerender
2424

25+
local function group_parents_and_children()
26+
local order = {}
27+
for i, task in ipairs(tasks) do
28+
order[task.id] = i
29+
end
30+
for _, task in ipairs(tasks) do
31+
if task.parent_id then
32+
order[task.id] = order[task.parent_id] - 0.5
33+
end
34+
end
35+
table.sort(tasks, function(a, b)
36+
return order[a.id] < order[b.id]
37+
end)
38+
end
39+
2540
M.update = function(task)
2641
if not task then
2742
rerender()
@@ -33,6 +48,7 @@ M.update = function(task)
3348
if not lookup[task.id] then
3449
lookup[task.id] = task
3550
table.insert(tasks, task)
51+
group_parents_and_children()
3652
end
3753
rerender()
3854
end
@@ -46,6 +62,7 @@ M.touch_task = function(task)
4662
end)
4763
table.remove(tasks, idx)
4864
table.insert(tasks, task)
65+
group_parents_and_children()
4966
rerender()
5067
end
5168

lua/overseer/task_list/sidebar.lua

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,39 @@ function Sidebar:render(tasks)
300300
local lines = {}
301301
local highlights = {}
302302
self.task_lines = {}
303+
local subtask_prefix = ""
303304
-- Iterate backwards so we show most recent tasks first
304305
for i = #tasks, 1, -1 do
305306
local task = tasks[i]
306307
local detail = self.task_detail[task.id] or self.default_detail
308+
local start_idx = #lines + 1
309+
local hl_start_idx = #highlights + 1
307310
task:render(lines, highlights, detail)
311+
312+
-- Indent subtasks
313+
if task.parent_id then
314+
for j = start_idx, #lines do
315+
lines[j] = subtask_prefix .. lines[j]
316+
end
317+
for j = hl_start_idx, #highlights do
318+
local hl = highlights[j]
319+
hl[3] = hl[3] + subtask_prefix:len()
320+
if hl[4] ~= -1 then
321+
hl[4] = hl[4] + subtask_prefix:len()
322+
end
323+
highlights[j] = hl
324+
end
325+
for j = start_idx, #lines do
326+
table.insert(highlights, { "OverseerTaskBorder", j, 0, subtask_prefix:len() })
327+
end
328+
end
308329
table.insert(self.task_lines, { #lines, task })
309330
if i > 1 then
310-
table.insert(lines, config.task_list.separator)
331+
if tasks[i - 1].parent_id then
332+
table.insert(lines, subtask_prefix .. vim.fn.strcharpart(config.task_list.separator, 2))
333+
else
334+
table.insert(lines, config.task_list.separator)
335+
end
311336
table.insert(highlights, { "OverseerTaskBorder", #lines, 0, -1 })
312337
end
313338
end

0 commit comments

Comments
 (0)