refactor: address emmylua diagnostics
This commit is contained in:
@@ -13,9 +13,13 @@ local REFRESH_DEBOUNCE_MS = 200
|
||||
local Session = {}
|
||||
Session.__index = Session
|
||||
|
||||
---@param session ow.lsp.codelens.Session
|
||||
local function do_refresh(session)
|
||||
if not session.enabled then
|
||||
---@type table<integer, ow.lsp.codelens.Session>
|
||||
local by_buf = {}
|
||||
|
||||
---@param buf integer
|
||||
local function do_refresh(buf)
|
||||
local session = by_buf[buf]
|
||||
if not session or not session.enabled then
|
||||
return
|
||||
end
|
||||
session:abort()
|
||||
@@ -24,21 +28,45 @@ local function do_refresh(session)
|
||||
task:run()
|
||||
end
|
||||
|
||||
local refresher = util.keyed_debounce(do_refresh, REFRESH_DEBOUNCE_MS)
|
||||
local refresh, refresh_handle =
|
||||
util.keyed_debounce(do_refresh, REFRESH_DEBOUNCE_MS)
|
||||
|
||||
---@param buf integer
|
||||
---@return ow.lsp.codelens.Session
|
||||
function Session.new(buf)
|
||||
return setmetatable({
|
||||
buf = buf,
|
||||
enabled = false,
|
||||
attached = false,
|
||||
rows = {},
|
||||
}, Session)
|
||||
function Session.get(buf)
|
||||
if not by_buf[buf] then
|
||||
by_buf[buf] = setmetatable({
|
||||
buf = buf,
|
||||
enabled = false,
|
||||
attached = false,
|
||||
rows = {},
|
||||
}, Session)
|
||||
end
|
||||
return by_buf[buf]
|
||||
end
|
||||
|
||||
---@param buf integer
|
||||
---@return ow.lsp.codelens.Session?
|
||||
function Session.find(buf)
|
||||
return by_buf[buf]
|
||||
end
|
||||
|
||||
---@return table<integer, ow.lsp.codelens.Session>
|
||||
function Session.all()
|
||||
return by_buf
|
||||
end
|
||||
|
||||
---@param buf integer
|
||||
function Session.remove(buf)
|
||||
local session = by_buf[buf]
|
||||
if session then
|
||||
session:abort()
|
||||
end
|
||||
by_buf[buf] = nil
|
||||
end
|
||||
|
||||
function Session:abort()
|
||||
refresher:cancel(self)
|
||||
refresh_handle.cancel(self.buf)
|
||||
if self.current then
|
||||
self.current:abort()
|
||||
self.current = nil
|
||||
@@ -46,7 +74,7 @@ function Session:abort()
|
||||
end
|
||||
|
||||
function Session:refresh()
|
||||
refresher(self)
|
||||
refresh(self.buf)
|
||||
end
|
||||
|
||||
function Session:render()
|
||||
|
||||
Reference in New Issue
Block a user