refactor: address emmylua diagnostics

This commit is contained in:
2026-04-20 22:11:18 +02:00
parent 516b9ea749
commit c7dd083083
29 changed files with 542 additions and 532 deletions
+45 -32
View File
@@ -1,7 +1,11 @@
local log = require("log")
local util = require("util")
local plugins_dir = vim.fs.joinpath(vim.fn.stdpath("config"), "plugins")
local config_dir = vim.fn.stdpath("config")
if type(config_dir) == "table" then
config_dir = assert(config_dir[1])
end
local plugins_dir = vim.fs.joinpath(config_dir, "plugins")
---@param path string
---@return boolean success
@@ -111,7 +115,7 @@ end
---@param plugin ow.Pack.Plugin
local function run_ts_build(plugin)
local ts = require("ts")
for _, p in ipairs(ts.normalize(plugin.ts_parser)) do
for _, p in ipairs(ts.normalize(assert(plugin.ts_parser))) do
ts.build(plugin, p)
end
end
@@ -149,9 +153,8 @@ end
---@type uv.uv_fs_event_t?
local watcher = nil
---@type (fun(filename: string) | ow.Util.KeyedDebouncer<string>)?
local reload = nil
---@type ow.Util.KeyedDebounceHandle<string>?
local on_change_handle = nil
---@class ow.Pack
---@field plugins ow.Pack.Plugin[]
@@ -174,7 +177,7 @@ function M.get_paths()
end
---@param name string
function M.reload(name)
function M.reload_plugin(name)
load(name, true)
end
@@ -184,29 +187,40 @@ function M.watch()
end
watcher = assert(vim.uv.new_fs_event())
reload = util.keyed_debounce(function(filename)
local path = vim.fs.joinpath(plugins_dir, filename)
if not vim.uv.fs_stat(path) then
return
end
local ok, load_err = exec(path)
if ok then
log.info("Reloaded %s", filename)
else
log.error("Failed to reload %s: %s", filename, load_err)
end
end, 100)
local on_change, handle = util.keyed_debounce(
---@param filename string
function(filename)
local path = vim.fs.joinpath(plugins_dir, filename)
if not vim.uv.fs_stat(path) then
return
end
local ok, load_err = exec(path)
if ok then
log.info("Reloaded %s", filename)
else
log.error("Failed to reload %s: %s", filename, load_err)
end
end,
200
)
on_change_handle = handle
assert(watcher:start(plugins_dir, {}, function(err, filename)
if err then
log.error("Watch error: %s", err)
return
assert(watcher:start(
plugins_dir,
{},
---@param err string?
---@param filename string
function(err, filename)
if err then
log.error("Watch error: %s", err)
return
end
if not filename or not filename:match("%.lua$") then
return
end
on_change(filename)
end
if not filename or not filename:match("%.lua$") then
return
end
reload(filename)
end))
))
end
function M.unwatch()
@@ -214,14 +228,13 @@ function M.unwatch()
return
end
if reload then
reload:close()
reload = nil
end
watcher:stop()
watcher:close()
watcher = nil
if on_change_handle then
on_change_handle.close()
on_change_handle = nil
end
end
---@param specs (string | ow.Pack.PluginSpec)[]