diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..68da2f2 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,9 @@ +{ + "runtime": { + "version": "LuaJIT", + "pathStrict": true + }, + "type": { + "checkTableShape": true + } +} diff --git a/lua/overseer/commands.lua b/lua/overseer/commands.lua index 1afc156..74894d6 100644 --- a/lua/overseer/commands.lua +++ b/lua/overseer/commands.lua @@ -212,17 +212,13 @@ local function get_search_params() } end ----@param opts nil|table ---- dir string ---- ft nil|string ----@param cb nil|fun() Called when preloading is complete +---@param opts? overseer.SearchParams +---@param cb? fun() Called when preloading is complete M.preload_cache = function(opts, cb) template.list(opts or get_search_params(), cb or function() end) end ----@param opts nil|table ---- dir string ---- ft nil|string +---@param opts? overseer.SearchParams M.clear_cache = function(opts) template.clear_cache(opts or get_search_params()) end diff --git a/lua/overseer/init.lua b/lua/overseer/init.lua index a084400..5ee380d 100644 --- a/lua/overseer/init.lua +++ b/lua/overseer/init.lua @@ -480,7 +480,9 @@ M.wrap_template = function(base, override, default_params) end end end - return setmetatable(override, { __index = base }) + setmetatable(override, { __index = base }) + ---@cast override overseer.TemplateFileDefinition + return override end ---Add a hook that runs on a TaskDefinition before the task is created diff --git a/lua/overseer/parser/init.lua b/lua/overseer/parser/init.lua index 3332544..0103077 100644 --- a/lua/overseer/parser/init.lua +++ b/lua/overseer/parser/init.lua @@ -111,13 +111,15 @@ end ---@field subs table local ListParser = {} +---@return overseer.ListParser function ListParser.new(children) - local parser = setmetatable({ + local parser = { tree = M.loop({ ignore_failure = true }, M.sequence(children)), results = {}, item = {}, subs = {}, - }, { __index = ListParser }) + } + setmetatable(parser, { __index = ListParser }) parser:subscribe("clear_results", function() parser.results = {} if parser.ctx then @@ -183,6 +185,7 @@ end ---@field subs table local MapParser = {} +---@return overseer.MapParser function MapParser.new(children) local results = {} local items = {} @@ -192,12 +195,13 @@ function MapParser.new(children) items[k] = {} wrapped_children[k] = M.loop({ ignore_failure = true }, M.sequence(v)) end - local parser = setmetatable({ + local parser = { children = wrapped_children, results = results, items = items, subs = {}, - }, { __index = MapParser }) + } + setmetatable(parser, { __index = MapParser }) parser:subscribe("clear_results", function(current_key_only) if not current_key_only then for k in pairs(parser.children) do diff --git a/lua/overseer/strategy/init.lua b/lua/overseer/strategy/init.lua index fadfcf0..7381a93 100644 --- a/lua/overseer/strategy/init.lua +++ b/lua/overseer/strategy/init.lua @@ -17,7 +17,10 @@ local NilStrategy = {} ---@return overseer.Strategy function NilStrategy.new() - return setmetatable({}, { __index = NilStrategy }) + local strategy = {} + setmetatable(strategy, { __index = NilStrategy }) + ---@cast strategy overseer.Strategy + return strategy end function NilStrategy:reset() end @@ -48,7 +51,7 @@ M.load = function(name_or_config) return instance else log:error("No task strategy '%s'", name) - return NilStrategy + return NilStrategy.new() end end diff --git a/lua/overseer/strategy/jobstart.lua b/lua/overseer/strategy/jobstart.lua index 0d1cf72..e4af91f 100644 --- a/lua/overseer/strategy/jobstart.lua +++ b/lua/overseer/strategy/jobstart.lua @@ -3,7 +3,7 @@ local log = require("overseer.log") local util = require("overseer.util") ---@class overseer.JobstartStrategy : overseer.Strategy ----@field bufnr integer +---@field bufnr nil|integer ---@field job_id nil|integer ---@field term_id nil|integer ---@field opts table @@ -19,12 +19,15 @@ function JobstartStrategy.new(opts) preserve_output = false, use_terminal = true, }) - return setmetatable({ + ---@type overseer.JobstartStrategy + local strategy = { bufnr = nil, job_id = nil, term_id = nil, opts = opts, - }, { __index = JobstartStrategy }) + } + setmetatable(strategy, { __index = JobstartStrategy }) + return strategy end function JobstartStrategy:reset() diff --git a/lua/overseer/strategy/orchestrator.lua b/lua/overseer/strategy/orchestrator.lua index 4411775..f569dbb 100644 --- a/lua/overseer/strategy/orchestrator.lua +++ b/lua/overseer/strategy/orchestrator.lua @@ -65,12 +65,15 @@ function OrchestratorStrategy.new(opts) task_defns[i] = { v } end end - return setmetatable({ + ---@type overseer.OrchestratorStrategy + local strategy = { task = nil, bufnr = vim.api.nvim_create_buf(false, true), task_defns = task_defns, tasks = {}, - }, { __index = OrchestratorStrategy }) + } + setmetatable(strategy, { __index = OrchestratorStrategy }) + return strategy end function OrchestratorStrategy:render_buf() diff --git a/lua/overseer/strategy/terminal.lua b/lua/overseer/strategy/terminal.lua index 72ed4f5..7e58e13 100644 --- a/lua/overseer/strategy/terminal.lua +++ b/lua/overseer/strategy/terminal.lua @@ -3,17 +3,20 @@ local log = require("overseer.log") local util = require("overseer.util") ---@class overseer.TerminalStrategy : overseer.Strategy ----@field bufnr integer +---@field bufnr nil|integer ---@field chan_id nil|integer local TerminalStrategy = {} ---Run tasks using termopen() ---@return overseer.Strategy function TerminalStrategy.new() - return setmetatable({ + ---@type overseer.TerminalStrategy + local strategy = { bufnr = nil, chan_id = nil, - }, { __index = TerminalStrategy }) + } + setmetatable(strategy, { __index = TerminalStrategy }) + return strategy end function TerminalStrategy:reset() diff --git a/lua/overseer/strategy/test.lua b/lua/overseer/strategy/test.lua index f9a3f62..37a7aae 100644 --- a/lua/overseer/strategy/test.lua +++ b/lua/overseer/strategy/test.lua @@ -8,10 +8,13 @@ local TestStrategy = {} ---Strategy used for unit testing ---@return overseer.Strategy function TestStrategy.new() - return setmetatable({ + ---@type overseer.TestStrategy + local strategy = { task = nil, bufnr = vim.api.nvim_create_buf(false, true), - }, { __index = TestStrategy }) + } + setmetatable(strategy, { __index = TestStrategy }) + return strategy end function TestStrategy:reset() diff --git a/lua/overseer/strategy/toggleterm.lua b/lua/overseer/strategy/toggleterm.lua index b94faa0..3a7d440 100644 --- a/lua/overseer/strategy/toggleterm.lua +++ b/lua/overseer/strategy/toggleterm.lua @@ -37,10 +37,13 @@ function ToggleTermStrategy.new(opts) hidden = false, on_create = nil, }) - return setmetatable({ + ---@type overseer.ToggleTermStrategy + local strategy = { opts = opts, term = nil, - }, { __index = ToggleTermStrategy }) + } + setmetatable(strategy, { __index = ToggleTermStrategy }) + return strategy end function ToggleTermStrategy:reset() diff --git a/lua/overseer/task.lua b/lua/overseer/task.lua index 5ff9c0b..ad5e1f0 100644 --- a/lua/overseer/task.lua +++ b/lua/overseer/task.lua @@ -106,7 +106,7 @@ function Task.new_uninitialized(opts) end -- Build the instance data for the task - local data = { + local task = { result = nil, metadata = opts.metadata or {}, default_component_params = opts.default_component_params or {}, @@ -127,8 +127,9 @@ function Task.new_uninitialized(opts) ---@diagnostic disable-next-line: undefined-field parent_id = opts.parent_id, } - local task = setmetatable(data, { __index = Task }) + setmetatable(task, { __index = Task }) task:add_components(opts.components) + ---@cast task overseer.Task return task end diff --git a/lua/overseer/task_view.lua b/lua/overseer/task_view.lua index d89ebf4..1c43d31 100644 --- a/lua/overseer/task_view.lua +++ b/lua/overseer/task_view.lua @@ -36,13 +36,15 @@ function TaskView.new(winid, opts) winid = vim.api.nvim_get_current_win() end set_minimal_win_opts(winid) - local self = setmetatable({ + ---@type overseer.TaskView + local self = { winid = winid, select = opts.select or function(self, tasks) return tasks[1] end, autocmd_ids = {}, - }, { __index = TaskView }) + } + setmetatable(self, { __index = TaskView }) -- Create one single autocmd that tracks the task_id under the cursor if not TaskView.cursor_track_autocmd_id then