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
+54 -48
View File
@@ -113,6 +113,7 @@ local function build_items(responses, base)
items = vim.fn.matchfuzzy(items, base, { key = "filter" })
else
items = vim.tbl_filter(function(item)
---@diagnostic disable-next-line: undefined-field
return vim.startswith(item.filter, base)
end, items)
end
@@ -123,7 +124,7 @@ end
local function buffer_has_completion_client()
return #vim.lsp.get_clients({
bufnr = 0,
method = vim.lsp.protocol.Methods.textDocument_completion,
method = "textDocument/completion",
}) > 0
end
@@ -140,7 +141,7 @@ end
local function is_trigger_char(char)
local clients = vim.lsp.get_clients({
bufnr = 0,
method = vim.lsp.protocol.Methods.textDocument_completion,
method = "textDocument/completion",
})
for _, client in ipairs(clients) do
local chars = vim.tbl_get(
@@ -199,61 +200,66 @@ function Session:dispatch(trigger_kind, trigger_char, manual)
triggerKind = trigger_kind,
triggerCharacter = trigger_char,
}
local method = vim.lsp.protocol.Methods.textDocument_completion
self.cancel = vim.lsp.buf_request_all(buf, method, params, function(result)
if self.generation ~= gen then
return
end
vim.schedule(function()
-- Re-check: another dispatch may have fired between response
-- and the scheduled callback running.
self.cancel = vim.lsp.buf_request_all(
buf,
"textDocument/completion",
params,
function(result, ctx)
if self.generation ~= gen then
return
end
if vim.fn.mode() ~= "i" then
return
end
local word_start, cursor = word_bounds()
if
not self.manual
and not self.trigger_char
and word_start == cursor
then
return
end
self.is_incomplete = false
for client_id, response in pairs(result) do
if response.err then
log.warning(
"client %d: %s failed: %s",
client_id,
method,
response.err.message
)
vim.schedule(function()
-- Re-check: another dispatch may have fired between response
-- and the scheduled callback running.
if self.generation ~= gen then
return
end
local r = response.result
if type(r) == "table" and r.isIncomplete then
self.is_incomplete = true
break
if vim.fn.mode() ~= "i" then
return
end
end
local start = word_start
for _, response in pairs(result) do
local pos = edit_start(response)
if pos then
start = pos.character
break
local word_start, cursor = word_bounds()
if
not self.manual
and not self.trigger_char
and word_start == cursor
then
return
end
end
local base = vim.api.nvim_get_current_line():sub(start + 1, cursor)
vim.fn.complete(start + 1, build_items(result, base))
end)
end)
self.is_incomplete = false
for client_id, response in pairs(result) do
if response.err then
log.warning(
"client %d: %s failed: %s",
client_id,
ctx.method,
response.err.message
)
end
local r = response.result
if type(r) == "table" and r.isIncomplete then
self.is_incomplete = true
break
end
end
local start = word_start
for _, response in pairs(result) do
local pos = edit_start(response)
if pos then
start = pos.character
break
end
end
local base =
vim.api.nvim_get_current_line():sub(start + 1, cursor)
vim.fn.complete(start + 1, build_items(result, base))
end)
end
)
end
local session = Session.new()
local dispatcher = util.debounce(function(trigger_kind, char)
local dispatch = util.debounce(function(trigger_kind, char)
if vim.fn.mode() ~= "i" then
return
end
@@ -288,7 +294,7 @@ function M.on_insert_char_pre()
local kind_num = is_trigger
and vim.lsp.protocol.CompletionTriggerKind.TriggerCharacter
or vim.lsp.protocol.CompletionTriggerKind.Invoked
dispatcher(kind_num, is_trigger and char or nil)
dispatch(kind_num, is_trigger and char or nil)
end
return M