refactor: address emmylua diagnostics
This commit is contained in:
+55
-52
@@ -10,11 +10,7 @@ local popup = Popup.new()
|
||||
---@param client vim.lsp.Client
|
||||
---@param buf integer
|
||||
local function on_attach(client, buf)
|
||||
if
|
||||
not client:supports_method(
|
||||
vim.lsp.protocol.Methods.textDocument_completion
|
||||
)
|
||||
then
|
||||
if not client:supports_method("textDocument/completion") then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -64,26 +60,23 @@ function M.setup()
|
||||
end
|
||||
|
||||
local ft = vim.bo[ev.buf].filetype
|
||||
|
||||
---@type ow.lsp.completion.Pum
|
||||
local pum = {
|
||||
row = vim.v.event.row,
|
||||
col = vim.v.event.col,
|
||||
width = vim.v.event.width,
|
||||
height = vim.v.event.height,
|
||||
scrollbar = vim.v.event.scrollbar,
|
||||
row = vim.v.event.row --[[@as integer]],
|
||||
col = vim.v.event.col --[[@as integer]],
|
||||
width = vim.v.event.width --[[@as integer]],
|
||||
height = vim.v.event.height --[[@as integer]],
|
||||
scrollbar = vim.v.event.scrollbar --[[@as boolean]],
|
||||
}
|
||||
|
||||
if
|
||||
client:supports_method(
|
||||
vim.lsp.protocol.Methods.completionItem_resolve
|
||||
)
|
||||
then
|
||||
if client:supports_method("completionItem/resolve") then
|
||||
popup:dispatch_resolve(
|
||||
client,
|
||||
item,
|
||||
ft,
|
||||
pum,
|
||||
completed.word,
|
||||
completed.word or "",
|
||||
ev.buf
|
||||
)
|
||||
else
|
||||
@@ -125,22 +118,27 @@ function M.setup()
|
||||
)
|
||||
end
|
||||
if raw.command then
|
||||
local method =
|
||||
vim.lsp.protocol.Methods.workspace_executeCommand
|
||||
client:request(method, {
|
||||
command = raw.command.command,
|
||||
arguments = raw.command.arguments,
|
||||
}, function(err)
|
||||
if err then
|
||||
log.warning(
|
||||
"client %d: %s failed for %s: %s",
|
||||
client.id,
|
||||
method,
|
||||
raw.command.title,
|
||||
err.message
|
||||
)
|
||||
end
|
||||
end, ev.buf)
|
||||
client:request(
|
||||
"workspace/executeCommand",
|
||||
{
|
||||
command = raw.command.command,
|
||||
arguments = raw.command.arguments,
|
||||
},
|
||||
---@param err lsp.ResponseError?
|
||||
---@param ctx lsp.HandlerContext
|
||||
function(err, _, ctx)
|
||||
if err then
|
||||
log.warning(
|
||||
"client %d: %s failed for %s: %s",
|
||||
client.id,
|
||||
ctx.method,
|
||||
raw.command.title,
|
||||
err.message
|
||||
)
|
||||
end
|
||||
end,
|
||||
ev.buf
|
||||
)
|
||||
end
|
||||
if target.snippet then
|
||||
local word = completed.word or ""
|
||||
@@ -161,32 +159,37 @@ function M.setup()
|
||||
|
||||
-- Prefer the resolved item when we have it. If we haven't cached
|
||||
-- one yet and the original is missing edits, resolve on the fly.
|
||||
local cached = popup:resolved_for(completed.word)
|
||||
local cached = popup:resolved_for(completed.word or "")
|
||||
if cached then
|
||||
apply(cached)
|
||||
elseif
|
||||
client:supports_method(
|
||||
vim.lsp.protocol.Methods.completionItem_resolve
|
||||
)
|
||||
client:supports_method("completionItem/resolve")
|
||||
and not item.raw.additionalTextEdits
|
||||
and not item.raw.command
|
||||
then
|
||||
local method = vim.lsp.protocol.Methods.completionItem_resolve
|
||||
client:request(method, item.raw, function(err, resolved)
|
||||
if err then
|
||||
log.warning(
|
||||
"client %d: %s failed: %s",
|
||||
client.id,
|
||||
method,
|
||||
err.message
|
||||
)
|
||||
end
|
||||
if err or not resolved then
|
||||
return
|
||||
end
|
||||
item:apply_resolved(resolved)
|
||||
apply(item)
|
||||
end, ev.buf)
|
||||
client:request(
|
||||
"completionItem/resolve",
|
||||
item.raw,
|
||||
---@param err lsp.ResponseError?
|
||||
---@param resolved lsp.CompletionItem?
|
||||
---@param ctx lsp.HandlerContext
|
||||
function(err, resolved, ctx)
|
||||
if err then
|
||||
log.warning(
|
||||
"client %d: %s failed: %s",
|
||||
client.id,
|
||||
ctx.method,
|
||||
err.message
|
||||
)
|
||||
end
|
||||
if err or not resolved then
|
||||
return
|
||||
end
|
||||
item:apply_resolved(resolved)
|
||||
apply(item)
|
||||
end,
|
||||
ev.buf
|
||||
)
|
||||
else
|
||||
apply(item)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user