Skip to content

Commit 4859497

Browse files
committed
doc: add Task fields to API documentation
1 parent a3966d1 commit 4859497

File tree

8 files changed

+89
-34
lines changed

8 files changed

+89
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ If you want to define custom tasks for your project, I'd recommend starting with
239239
- [register_template(defn)](doc/reference.md#register_templatedefn)
240240
- [register_alias(name, components, override)](doc/reference.md#register_aliasname-components-override)
241241
- [create_task_output_view(winid, opts)](doc/reference.md#create_task_output_viewwinid-opts)
242-
- [Task](doc/reference.md#task)
242+
- [overseer.Task](doc/reference.md#overseertask)
243243
- [Task:serialize()](doc/reference.md#taskserialize)
244244
- [Task:clone()](doc/reference.md#taskclone)
245245
- [Task:add_component(comp)](doc/reference.md#taskadd_componentcomp)

doc/overseer.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,33 @@ create_task_output_view({winid}, {opts}) *overseer.create_task_output_vie
487487
<
488488

489489
overseer.Task *overseer.Task*
490-
The task class and methods
490+
491+
Fields:
492+
{id} `integer` Unique ID for this task
493+
{result} `nil|table<string, any>` For successful tasks, arbitrary
494+
key-value mapping of data produced by components
495+
{metadata} `table<string, any>` Arbitrary key-value mapping passed by
496+
the user during construction
497+
{status} `overseer.Status` Current task status
498+
{cmd} `string|string[]` Command to run. If it's a string it is
499+
run in the shell
500+
{cwd} `string` Working directory the task is run in
501+
{env} `nil|table<string, string>` Additional environment
502+
variables for the task
503+
{name} `string` Name of the task
504+
{ephemeral} `boolean` Indicates that this task was generated
505+
indirectly (e.g. with run_after)
506+
{source} `nil|overseer.Caller` If this task was created by wrapping
507+
jobstart/vim.system, this contains information about the
508+
callsite
509+
{exit_code} `nil|integer` Exit code of the task process
510+
{parent_id} `nil|integer` ID of parent task. Used only to visually
511+
group tasks in the task list
512+
{time_start} `nil|integer` Timestamp when the task was started
513+
(os.time())
514+
{time_end} `nil|integer` Timestamp when the task ended (os.time())
515+
516+
491517

492518
Task:clone(): overseer.Task *overseer.Task:clone*
493519
Create a deep copy of this task
@@ -546,8 +572,8 @@ Task:subscribe({event}, {callback}) *overseer.Task:subscrib
546572
return a truthy value to unsubscribe itself
547573

548574
Note:
549-
Listeners cannot be serialized, so will not be saved when saving task to disk and will not be
550-
copied when cloning the task.
575+
Listeners cannot be serialized, so will not be saved when saving task
576+
to disk and will not be copied when cloning the task.
551577

552578
Task:unsubscribe({event}, {callback}) *overseer.Task:unsubscribe*
553579
Unsubscribe from an event that was previously subscribed to

doc/reference.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- [register_template(defn)](#register_templatedefn)
2222
- [register_alias(name, components, override)](#register_aliasname-components-override)
2323
- [create_task_output_view(winid, opts)](#create_task_output_viewwinid-opts)
24-
- [Task](#task)
24+
- [overseer.Task](#overseertask)
2525
- [Task:serialize()](#taskserialize)
2626
- [Task:clone()](#taskclone)
2727
- [Task:add_component(comp)](#taskadd_componentcomp)
@@ -557,11 +557,26 @@ overseer.create_task_output_view(0, {
557557

558558
<!-- /API -->
559559

560-
### Task
561-
562-
The Task class and its associated methods
563-
564560
<!-- Task API -->
561+
### overseer.Task
562+
563+
| Field | Type | Desc |
564+
| ---------- | ---------------------------- | ------------------------------------------------------------------------------------------------------ |
565+
| id | `integer` | Unique ID for this task |
566+
| result | `nil\|table<string, any>` | For successful tasks, arbitrary key-value mapping of data produced by components |
567+
| metadata | `table<string, any>` | Arbitrary key-value mapping passed by the user during construction |
568+
| status | `overseer.Status` | Current task status |
569+
| cmd | `string\|string[]` | Command to run. If it's a string it is run in the shell |
570+
| cwd | `string` | Working directory the task is run in |
571+
| env | `nil\|table<string, string>` | Additional environment variables for the task |
572+
| name | `string` | Name of the task |
573+
| ephemeral | `boolean` | Indicates that this task was generated indirectly (e.g. with run_after) |
574+
| source | `nil\|overseer.Caller` | If this task was created by wrapping jobstart/vim.system, this contains information about the callsite |
575+
| exit_code | `nil\|integer` | Exit code of the task process |
576+
| parent_id | `nil\|integer` | ID of parent task. Used only to visually group tasks in the task list |
577+
| time_start | `nil\|integer` | Timestamp when the task was started (os.time()) |
578+
| time_end | `nil\|integer` | Timestamp when the task ended (os.time()) |
579+
565580

566581
#### Task:serialize()
567582

@@ -655,8 +670,8 @@ Subscribe to events on this task
655670

656671
**Note:**
657672
<pre>
658-
Listeners cannot be serialized, so will not be saved when saving task to disk and will not be
659-
copied when cloning the task.
673+
Listeners cannot be serialized, so will not be saved when saving task
674+
to disk and will not be copied when cloning the task.
660675
</pre>
661676

662677
#### Task:unsubscribe(event, callback)

lua/overseer/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ local wrapped_jobstart = function(cmd, opts)
406406
components = { "default_builtin" },
407407
})
408408
task:start()
409+
---@diagnostic disable-next-line: invisible
409410
local strat = task.strategy
410411
---@cast strat overseer.JobstartStrategy
411412
return strat.job_id
@@ -434,6 +435,7 @@ local wrapped_system = function(cmd, opts, on_exit)
434435
components = { "default_builtin" },
435436
})
436437
task:start()
438+
---@diagnostic disable-next-line: invisible
437439
local strat = task.strategy
438440
---@cast strat overseer.SystemStrategy
439441
return strat.handle

lua/overseer/task.lua

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,32 @@ local util = require("overseer.util")
1111
local STATUS = constants.STATUS
1212

1313
---@class overseer.Task
14-
---@field id number
15-
---@field result? table
16-
---@field metadata table
17-
---@field default_component_params table
18-
---@field status overseer.Status
19-
---@field cmd string|string[]
20-
---@field cwd string
21-
---@field env? table<string, string>
22-
---@field strategy_defn string|table
23-
---@field strategy overseer.Strategy
24-
---@field name string
14+
---@opaque
15+
---@field id integer Unique ID for this task
16+
---@field result? table<string, any> For successful tasks, arbitrary key-value mapping of data produced by components
17+
---@field metadata table<string, any> Arbitrary key-value mapping passed by the user during construction
18+
---@field private default_component_params table<string, any>
19+
---@field status overseer.Status Current task status
20+
---@field cmd string|string[] Command to run. If it's a string it is run in the shell
21+
---@field cwd string Working directory the task is run in
22+
---@field env? table<string, string> Additional environment variables for the task
23+
---@field private strategy_defn string|table
24+
---@field private strategy overseer.Strategy
25+
---@field name string Name of the task
2526
---@field ephemeral boolean Indicates that this task was generated indirectly (e.g. with run_after)
2627
---@field source? overseer.Caller If this task was created by wrapping jobstart/vim.system, this contains information about the callsite
27-
---@field exit_code? number
28-
---@field components overseer.Component[]
28+
---@field exit_code? integer Exit code of the task process
29+
---@field private components overseer.Component[]
2930
---@field parent_id? integer ID of parent task. Used only to visually group tasks in the task list
30-
---@field time_start? integer
31-
---@field time_end? integer
31+
---@field time_start? integer Timestamp when the task was started (os.time())
32+
---@field time_end? integer Timestamp when the task ended (os.time())
3233
---@field private from_template? overseer.TemplateSource
3334
---@field private prev_bufnr? integer
34-
---@field private _subscribers table<string, function[]>
35+
---@field private _subscribers table<string, overseer.TaskEventHandler[]>
3536
local Task = {}
3637

38+
---@alias overseer.TaskEventHandler fun(task: overseer.Task, ...: any): nil|boolean
39+
3740
local next_id = 1
3841

3942
---@class (exact) overseer.TaskDefinition
@@ -289,8 +292,8 @@ end
289292
---@param event string
290293
---@param callback fun(task: overseer.Task, ...: any): nil|boolean Callback can return a truthy value to unsubscribe itself
291294
---@note
292-
--- Listeners cannot be serialized, so will not be saved when saving task to disk and will not be
293-
--- copied when cloning the task.
295+
--- Listeners cannot be serialized, so will not be saved when saving task
296+
--- to disk and will not be copied when cloning the task.
294297
function Task:subscribe(event, callback)
295298
if not self._subscribers[event] then
296299
self._subscribers[event] = {}

lua/overseer/task_editor.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ function Editor:submit()
423423
return c[1]
424424
end, self.components))
425425
local to_remove = {}
426+
---@diagnostic disable-next-line: invisible
426427
for _, v in ipairs(self.task.components) do
427428
if not seen[v.name] then
428429
table.insert(to_remove, v.name)

lua/overseer/task_list/actions.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ M = {
187187
title = task.name,
188188
lines = lines,
189189
-- Peep into the default component params to fetch the errorformat
190+
---@diagnostic disable-next-line: invisible
190191
efm = task.default_component_params.errorformat,
191192
})
192193
vim.cmd("botright copen")

scripts/generate.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
parse_directory,
2222
read_section,
2323
render_md_api2,
24+
render_md_classes,
2425
render_vimdoc_api2,
26+
render_vimdoc_classes,
2527
replace_section,
2628
wrap,
2729
)
@@ -336,13 +338,13 @@ def get_api_vimdoc() -> "VimdocSection":
336338
section = VimdocSection(
337339
"API", "overseer-api", render_vimdoc_api2("overseer", funcs, types)
338340
)
341+
342+
task = types.classes["overseer.Task"]
343+
section.body.extend(render_vimdoc_classes([task], types))
344+
section.body.append("\n")
339345
funcs = types.files["overseer/task.lua"].functions
340346
# Strip out Task.new because it's duplicative of overseer.new_task
341347
funcs.pop(0)
342-
section.body.append(
343-
"overseer.Task *overseer.Task*\n"
344-
)
345-
section.body.append("The task class and methods\n")
346348
section.body.append("\n")
347349
section.body.extend(render_vimdoc_api2("overseer", funcs, types))
348350
section.body.append("\n")
@@ -525,10 +527,15 @@ def update_md_api():
525527
lines,
526528
)
527529

530+
task = types.classes["overseer.Task"]
531+
lines = render_md_classes([task], types, level=3)
532+
lines.append("\n")
533+
528534
funcs = types.files["overseer/task.lua"].functions
529535
# Strip out Task.new because it's duplicative of overseer.new_task
530536
funcs.pop(0)
531-
lines = ["\n"] + render_md_api2(funcs, types, level=4) + ["\n"]
537+
lines.extend(render_md_api2(funcs, types, level=4))
538+
lines.append("\n")
532539
replace_section(
533540
os.path.join(DOC, "reference.md"),
534541
r"^<!-- Task API -->$",

0 commit comments

Comments
 (0)