Open matu3ba opened 1 year ago
I'll got stuck how to provide params
necessary in a module from the action "validate":
-- $NVIMRC/lua/my_over.lua
local has_overseer, overseer = pcall(require, "overseer")
if not has_overseer then
vim.print("no overseer")
return
end
local constants = require("overseer.constants")
local STATUS = constants.STATUS
overseer.setup({
actions = {
["validate"] = {
desc = "Create and execute derived task to validate result",
condition = function(task)
return not task:has_component("validate") -- dont validate validation
and (task.status == STATUS.SUCCESS or task.status == STATUS.FAILURE)
end,
run = function(task)
-- print(task:has_component("validate")) -- DEBUG
local newtask = overseer.new_task({
cmd = task.cmd;
cwd = task.cwd;
env = task.env;
name = "val_" .. task.name;
components = {
"validate",
"on_complete_notify",
"default"
}
})
newtask:start()
end,
},
},
component_aliases = {
default = {
{ "display_duration", detail_level = 2 },
"on_output_summarize",
"on_exit_set_status",
--"on_complete_notify",
--"on_complete_dispose", -- this should keep the task
},
-- Tasks from tasks.json use these components
default_vscode = {
"default",
"on_result_diagnostics",
"on_result_diagnostics_quickfix",
},
},
strategy = { "jobstart", use_terminal = false },
templates = { "builtin", "user.cpp_build", "user.run_script" },
})
-- $NVIMRC/lua/overseer/component/validate.lua
local constants = require("overseer.constants")
-- local overseer = require "overseer"
local find_index_task = function(task_list, task_name)
local j = -1
for i = 1, #task_list do
if task_list[i].name == task_name then
j = i
break
end
end
return j
end
return {
desc = "Create and execute derived task to validate result",
params = { -- parameters passed to component
type = "string" -- task name as dependency
},
editable = false, -- editing disallowed
serializable = true, -- serializing disabled
constructor = function(params)
return {
on_init = function(self, task)
local task_list = require("overseer").list_tasks()
local fin_i = find_index_task(task_list, params[1])
if fin_i == -1 then
-- idea: add things to result of job
task:finalize(constants.STATUS.FAILURE)
else
task.name = "validate" .. task.name
task.cmd = task_list[fin_i].cmd
task.cwd = task_list[fin_i].cwd
task.env = task_list[fin_i].env
self.expected_output = task_list[fin_i].result
self.expected_exitcode = task_list[fin_i].exit_code
end
end,
---@return nil|boolean
on_reset = function(self, task) -- reset => task runs again
local _ = task
local task_list = require("overseer").list_tasks()
local fin_i = find_index_task(task_list, params[1])
if fin_i == -1 then
task:finalize(constants.STATUS.FAILURE)
else
if self.expected_output ~= task_list[fin_i].result then
-- TODO how to provide reason for exit failure?
task:finalize(constants.STATUS.FAILURE)
end
if self.expected_exitcode ~= task_list[fin_i].exit_code then
task:finalize(constants.STATUS.FAILURE)
end
end
end,
---@param code number The process exit code
on_exit = function(self, task, code)
if self.expected_exitcode == code then
task:finalize(constants.STATUS.SUCCESS)
else
task:finalize(constants.STATUS.FAILURE)
end
end,
}
end,
}
E5108: Error executing lua: ...hare/nvim/lazy/overseer.nvim/lua/overseer/form/utils.lua:66: attempt to index local 'param' (a string value)
stack traceback:
...hare/nvim/lazy/overseer.nvim/lua/overseer/form/utils.lua:66: in function 'validate_params'
.../nvim/lazy/overseer.nvim/lua/overseer/component/init.lua:91: in function 'validate_component'
.../nvim/lazy/overseer.nvim/lua/overseer/component/init.lua:128: in function 'get'
.../nvim/lazy/overseer.nvim/lua/overseer/component/init.lua:301: in function 'load'
...ocal/share/nvim/lazy/overseer.nvim/lua/overseer/task.lua:265: in function 'add_components'
...ocal/share/nvim/lazy/overseer.nvim/lua/overseer/task.lua:122: in function 'new_uninitialized'
...ocal/share/nvim/lazy/overseer.nvim/lua/overseer/task.lua:130: in function 'new_task'
/home/jan/.config/nvim/lua/my_over.lua:61: in function 'run'
...are/nvim/lazy/overseer.nvim/lua/overseer/action_util.lua:80: in function 'on_choice'
...neovim-unwrapped-0.9.1/share/nvim/runtime/lua/vim/ui.lua:54: in function 'select'
...are/nvim/lazy/overseer.nvim/lua/overseer/action_util.lua:67: in function 'run_action'
...are/nvim/lazy/overseer.nvim/lua/overseer/action_util.lua:11: in function 'run_task_action'
...im/lazy/overseer.nvim/lua/overseer/task_list/sidebar.lua:288: in function 'run_action'
...m/lazy/overseer.nvim/lua/overseer/task_list/bindings.lua:15: in function 'rhs'
...re/nvim/lazy/overseer.nvim/lua/overseer/binding_util.lua:12: in function <...re/nvim/lazy/overseer.nvim/lua/overseer/binding_util.lua:11>
As of now, the behavior of tasks seems to be relative static and defined by once defined input (cwd, cmd + args, expand, name for referencing) xor template.
However, there seems to be no component yet to do 1. one shot tasks or 2. permanent ones to compare the result behavior. This point becomes relevant, ones one does (big) refactorings and/or wants to compare logs for (simple) behavioral differences of unit tests, which include simple printf debugging.
I'll see, if I can come up with something.