stevearc / overseer.nvim

A task runner and job management plugin for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improvement: pass params to dependencies

alexjwilliams opened this issue · comments

I don't think there is any reasonable way of achieving this currently. Consider the following templates:
compile.lua:

return {
  name = "compile",
  builder = function(params)
    return {
      cmd = "meson compile --verbose -C $BUILD_DIR " .. params.target,
      components = {
        {
          "dependencies",
          task_names = {
            {
              "configure",
              param_values = { build_type = params.build_type, quit_on_exit = "success" }, -- FICTITIOUS
            }
          }
        }
      }
    }
  end,
  params = {
    build_type = {
      type = "enum",
      choices = {
        "release",
        "debug"
      },
      default = "release",
    },
    target = {
      type = "enum",
      choices = {
        "my_target_1",
        "my_target_2",
        "my_target_3"
      },
      default = "my_target_1",
    }
  }
}

configure.lua:

return {
  name = "configure",
  builder = function(params)
    return {
      name = "shell",
      cmd = "meson configure --buildtype " .. params.build_type .. " $BUILD_DIR",
      strategy = { "toggleterm", direction = "horizontal", quit_on_exit = params.quit_on_exit }
    }
  end,
  params = {
    build_type = {
      type = "enum",
      choices = {
        "release",
        "debug"
      },
      default = "release",
    },
    quit_on_exit = {
      type = "enum",
      choices = {
        "never",
        "success",
        "always"
      },
      default = "never",
    }
  },
  no_pop_up_when_i_am_a_dependency = true --FICTITIOUS
}

Desired behavior: The values in param_values are used for the values of configure's parameters when configure is run as a dependency of compile. This could happen in one of two manners: 1. The "parameter pop up" for configure is displayed with the values from "param_values" present (instead of showing the defaults specified in configure.lua). 2. The "parameter pop up" for configure is not displayed and configure is executed without any additional user input, using the values in param_values. The choice between these two manners should be configurable via a config value somewhere in configure.lua.

I'm going to close this as out of scope. I thought about it, but I can't come up with a design for something like this that I like. One of the strengths of the dependencies component is that it's just a normal component. Nothing is stopping you from making your own, similar component. I don't want to add special case handling for this component in the task launcher, because then it becomes special.

I also thought about some other way to possibly promote or automatically reference and pass params from other tasks, but that would add a lot of complexity to an already complex system, and I'm not convinced it's worth it. You can already do what you want to do, by just duplicating params from dependencies and passing them down, it just requires more explicit code. I don't think that a small syntactic sugar improvement for that is worth adding the amount of complexity it would take.

Thanks for taking a look.

You can already do what you want to do, by just duplicating params from dependencies and passing them down, it just requires more explicit code.

I was able to get this working. This entire issue is unecessary. I was confused by the following documentation:

overseer.nvim/doc/guides.md

Lines 338 to 342 in 8065976

task:add_component({'dependencies', task_names = {
'npm build',
-- You can also pass in params to the task
{'shell', cmd = 'sleep 10'},
}, sequential = true})

I didn't realize that cmd was a parameter (yes, I know that the comment says it right there). I confused it with the cmd entry in a TaskDefinition. You might want to change this to use a parameter whose name is not also an entry in a TaskDefintion.