fix(util): refactor debouncer
This commit is contained in:
+6
-10
@@ -1,7 +1,7 @@
|
||||
local log = require("log")
|
||||
local util = require("util")
|
||||
|
||||
local config_dir = vim.fn.stdpath("config")
|
||||
local plugins_dir = vim.fs.joinpath(vim.fn.stdpath("config"), "plugins")
|
||||
|
||||
---@param path string
|
||||
---@return boolean success
|
||||
@@ -51,9 +51,7 @@ local function plugin_config_path(name)
|
||||
return
|
||||
end
|
||||
|
||||
local path = vim.fs.joinpath(config_dir, "plugins", normalized .. ".lua")
|
||||
|
||||
return path
|
||||
return vim.fs.joinpath(plugins_dir, normalized .. ".lua")
|
||||
end
|
||||
|
||||
---@param name string
|
||||
@@ -152,7 +150,7 @@ end
|
||||
---@type uv.uv_fs_event_t?
|
||||
local watcher = nil
|
||||
|
||||
---@type ow.Util.Debouncer?
|
||||
---@type (fun(filename: string) | ow.Util.KeyedDebouncer<string>)?
|
||||
local reload = nil
|
||||
|
||||
---@class ow.Pack
|
||||
@@ -185,10 +183,8 @@ function M.watch()
|
||||
return
|
||||
end
|
||||
|
||||
local plugins_dir = vim.fs.joinpath(config_dir, "plugins")
|
||||
|
||||
watcher = assert(vim.uv.new_fs_event())
|
||||
reload = util.debounce(function(filename)
|
||||
reload = util.keyed_debounce(function(filename)
|
||||
local path = vim.fs.joinpath(plugins_dir, filename)
|
||||
if not vim.uv.fs_stat(path) then
|
||||
return
|
||||
@@ -209,7 +205,7 @@ function M.watch()
|
||||
if not filename or not filename:match("%.lua$") then
|
||||
return
|
||||
end
|
||||
reload:call(filename)
|
||||
reload(filename)
|
||||
end))
|
||||
end
|
||||
|
||||
@@ -219,7 +215,7 @@ function M.unwatch()
|
||||
end
|
||||
|
||||
if reload then
|
||||
reload:cancel()
|
||||
reload:close()
|
||||
reload = nil
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user