|
| 1 | +local overseer = require("overseer") |
| 2 | + |
| 3 | +---@param opts overseer.SearchParams |
| 4 | +---@return nil|string |
| 5 | +local function get_devenv_file(opts) |
| 6 | + local devenv_nix = { "devenv.nix" } |
| 7 | + return vim.fs.find(devenv_nix, { upward = true, type = "file", path = opts.dir })[1] |
| 8 | +end |
| 9 | + |
| 10 | +return { |
| 11 | + cache_key = function(opts) |
| 12 | + return get_devenv_file(opts) |
| 13 | + end, |
| 14 | + generator = function(opts, cb) |
| 15 | + if vim.fn.executable("devenv") == 0 then |
| 16 | + return 'Command "devenv" not found' |
| 17 | + end |
| 18 | + local devenv = get_devenv_file(opts) |
| 19 | + if not devenv then |
| 20 | + return "No devenv.nix file found" |
| 21 | + end |
| 22 | + local devenv_dir = vim.fs.dirname(devenv) |
| 23 | + local ret = {} |
| 24 | + overseer.builtin.system( |
| 25 | + { "devenv", "shell", "echo $DEVENV_TASKS" }, |
| 26 | + { cwd = devenv_dir, text = true }, |
| 27 | + vim.schedule_wrap(function(out) |
| 28 | + local ok, data = pcall(vim.json.decode, out.stdout, { luanil = { object = true } }) |
| 29 | + |
| 30 | + if not ok then |
| 31 | + cb(data) |
| 32 | + return |
| 33 | + end |
| 34 | + |
| 35 | + for _, task in ipairs(data) do |
| 36 | + table.insert(ret, { |
| 37 | + name = string.format("devenv %s", task.name), |
| 38 | + builder = function() |
| 39 | + return { |
| 40 | + cwd = devenv_dir, |
| 41 | + cmd = { "devenv", "tasks", "run", task.name }, |
| 42 | + } |
| 43 | + end, |
| 44 | + }) |
| 45 | + end |
| 46 | + |
| 47 | + cb(ret) |
| 48 | + end) |
| 49 | + ) |
| 50 | + end, |
| 51 | +} |
0 commit comments