Skip to content

Commit

Permalink
lint: stricter type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Sep 17, 2024
1 parent 35ea16c commit 44e927e
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 30 deletions.
9 changes: 9 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtime": {
"version": "LuaJIT",
"pathStrict": true
},
"type": {
"checkTableShape": true
}
}
10 changes: 3 additions & 7 deletions lua/overseer/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lua/overseer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions lua/overseer/parser/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ end
---@field subs table<string, fun(key: string, value: any)[]>
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
Expand Down Expand Up @@ -183,6 +185,7 @@ end
---@field subs table<string, fun(key: string, value: any)[]>
local MapParser = {}

---@return overseer.MapParser
function MapParser.new(children)
local results = {}
local items = {}
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lua/overseer/strategy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions lua/overseer/strategy/jobstart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions lua/overseer/strategy/orchestrator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions lua/overseer/strategy/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions lua/overseer/strategy/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions lua/overseer/strategy/toggleterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions lua/overseer/task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {},
Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions lua/overseer/task_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44e927e

Please sign in to comment.