-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathopen_output.lua
114 lines (107 loc) · 3.35 KB
/
open_output.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
local constants = require("overseer.constants")
local STATUS = constants.STATUS
---@param task overseer.Task
---@param direction "dock"|"float"|"tab"|"vertical"|"horizontal"
---@param focus boolean
local function open_output(task, direction, focus)
if direction == "dock" then
local window = require("overseer.window")
window.open({
direction = "bottom",
enter = focus,
focus_task_id = task.id,
})
else
local winid = vim.api.nvim_get_current_win()
---@cast direction "float"|"tab"|"vertical"|"horizontal"
task:open_output(direction)
if not focus then
vim.api.nvim_set_current_win(winid)
end
end
end
---@type overseer.ComponentFileDefinition
local comp = {
desc = "Open task output",
params = {
on_start = {
desc = "Open the output when the task starts",
type = "enum",
choices = { "always", "never", "if_no_on_output_quickfix" },
default = "if_no_on_output_quickfix",
long_desc = "The 'if_no_on_output_quickfix' option will open the task output on start unless the task has the 'on_output_quickfix' component attached.",
},
on_complete = {
desc = "Open the output when the task completes",
type = "enum",
choices = { "always", "never", "success", "failure" },
default = "never",
},
on_result = {
desc = "Open the output when the task produces a result",
type = "enum",
choices = { "always", "never", "if_diagnostics" },
default = "never",
},
direction = {
desc = "Where to open the task output",
type = "enum",
choices = { "dock", "float", "tab", "vertical", "horizontal" },
default = "dock",
long_desc = "The 'dock' option will open the output docked to the bottom next to the task list.",
},
focus = {
desc = "Focus the output window when it is opened",
type = "boolean",
default = false,
},
},
constructor = function(params)
-- backwards compatibility
if params.on_start == true then
params.on_start = "always"
elseif params.on_start == false then
params.on_start = "never"
end
---@type overseer.ComponentSkeleton
local methods = {}
if params.on_start ~= "never" then
methods.on_start = function(self, task)
if
params.on_start == "always"
or (
params.on_start == "if_no_on_output_quickfix"
and not task:has_component("on_output_quickfix")
)
then
open_output(task, params.direction, params.focus)
end
end
end
if params.on_result ~= "never" then
methods.on_result = function(self, task, result)
if
params.on_result == "always"
or (
params.on_result == "if_diagnostics" and not vim.tbl_isempty(result.diagnostics or {})
)
then
open_output(task, params.direction, params.focus)
end
end
end
if params.on_complete ~= "never" then
methods.on_complete = function(self, task, status, result)
if
params.on_complete == "always"
or (params.on_complete == "success" and status == STATUS.SUCCESS)
or (params.on_complete == "failure" and status == STATUS.FAILURE)
then
open_output(task, params.direction, params.focus)
end
end
end
return methods
end,
}
return comp