fix(lsp.completion): add logging for request failures
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
local Item = require("lsp.completion.item")
|
local Item = require("lsp.completion.item")
|
||||||
local Popup = require("lsp.completion.popup")
|
local Popup = require("lsp.completion.popup")
|
||||||
|
local log = require("log")
|
||||||
local session = require("lsp.completion.session")
|
local session = require("lsp.completion.session")
|
||||||
|
|
||||||
local GROUP = vim.api.nvim_create_augroup("ow.lsp.completion", { clear = true })
|
local GROUP = vim.api.nvim_create_augroup("ow.lsp.completion", { clear = true })
|
||||||
@@ -113,6 +114,7 @@ function M.setup()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param target ow.lsp.completion.Item
|
||||||
local function apply(target)
|
local function apply(target)
|
||||||
local raw = target.raw
|
local raw = target.raw
|
||||||
if raw.additionalTextEdits then
|
if raw.additionalTextEdits then
|
||||||
@@ -123,10 +125,22 @@ function M.setup()
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
if raw.command then
|
if raw.command then
|
||||||
client:request("workspace/executeCommand", {
|
local method =
|
||||||
|
vim.lsp.protocol.Methods.workspace_executeCommand
|
||||||
|
client:request(method, {
|
||||||
command = raw.command.command,
|
command = raw.command.command,
|
||||||
arguments = raw.command.arguments,
|
arguments = raw.command.arguments,
|
||||||
}, nil, ev.buf)
|
}, 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)
|
||||||
end
|
end
|
||||||
if target.snippet then
|
if target.snippet then
|
||||||
local word = completed.word or ""
|
local word = completed.word or ""
|
||||||
@@ -157,18 +171,22 @@ function M.setup()
|
|||||||
and not item.raw.additionalTextEdits
|
and not item.raw.additionalTextEdits
|
||||||
and not item.raw.command
|
and not item.raw.command
|
||||||
then
|
then
|
||||||
client:request(
|
local method = vim.lsp.protocol.Methods.completionItem_resolve
|
||||||
vim.lsp.protocol.Methods.completionItem_resolve,
|
client:request(method, item.raw, function(err, resolved)
|
||||||
item.raw,
|
if err then
|
||||||
function(err, resolved)
|
log.warning(
|
||||||
|
"client %d: %s failed: %s",
|
||||||
|
client.id,
|
||||||
|
method,
|
||||||
|
err.message
|
||||||
|
)
|
||||||
|
end
|
||||||
if err or not resolved then
|
if err or not resolved then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
item:apply_resolved(resolved)
|
item:apply_resolved(resolved)
|
||||||
apply(item)
|
apply(item)
|
||||||
end,
|
end, ev.buf)
|
||||||
ev.buf
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
apply(item)
|
apply(item)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
local log = require("log")
|
||||||
local MAX_WIDTH = 80
|
local MAX_WIDTH = 80
|
||||||
local MAX_HEIGHT = 20
|
local MAX_HEIGHT = 20
|
||||||
local HALF_HEIGHT = math.floor(MAX_HEIGHT / 2)
|
local HALF_HEIGHT = math.floor(MAX_HEIGHT / 2)
|
||||||
@@ -114,10 +115,16 @@ end
|
|||||||
function Popup:dispatch_resolve(client, item, ft, pum, word, buf)
|
function Popup:dispatch_resolve(client, item, ft, pum, word, buf)
|
||||||
self:cancel_pending()
|
self:cancel_pending()
|
||||||
self.resolved = nil
|
self.resolved = nil
|
||||||
local _, request_id = client:request(
|
local method = vim.lsp.protocol.Methods.completionItem_resolve
|
||||||
vim.lsp.protocol.Methods.completionItem_resolve,
|
local _, request_id = client:request(method, item.raw, function(err, result)
|
||||||
item.raw,
|
if err then
|
||||||
function(err, result)
|
log.warning(
|
||||||
|
"client %d: %s failed: %s",
|
||||||
|
client.id,
|
||||||
|
method,
|
||||||
|
err.message
|
||||||
|
)
|
||||||
|
end
|
||||||
self.pending = nil
|
self.pending = nil
|
||||||
if err or not result then
|
if err or not result then
|
||||||
return
|
return
|
||||||
@@ -129,9 +136,7 @@ function Popup:dispatch_resolve(client, item, ft, pum, word, buf)
|
|||||||
item:apply_resolved(result)
|
item:apply_resolved(result)
|
||||||
self.resolved = { word = word, item = item }
|
self.resolved = { word = word, item = item }
|
||||||
self:show(item, ft, pum)
|
self:show(item, ft, pum)
|
||||||
end,
|
end, buf)
|
||||||
buf
|
|
||||||
)
|
|
||||||
if request_id then
|
if request_id then
|
||||||
self.pending = { client = client, id = request_id }
|
self.pending = { client = client, id = request_id }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
local Item = require("lsp.completion.item")
|
local Item = require("lsp.completion.item")
|
||||||
local kind = require("lsp.kind")
|
local kind = require("lsp.kind")
|
||||||
|
local log = require("log")
|
||||||
local util = require("util")
|
local util = require("util")
|
||||||
|
|
||||||
local REQUEST_DEBOUNCE_MS = 50
|
local REQUEST_DEBOUNCE_MS = 50
|
||||||
@@ -198,11 +199,8 @@ function Session:dispatch(trigger_kind, trigger_char, manual)
|
|||||||
triggerKind = trigger_kind,
|
triggerKind = trigger_kind,
|
||||||
triggerCharacter = trigger_char,
|
triggerCharacter = trigger_char,
|
||||||
}
|
}
|
||||||
self.cancel = vim.lsp.buf_request_all(
|
local method = vim.lsp.protocol.Methods.textDocument_completion
|
||||||
buf,
|
self.cancel = vim.lsp.buf_request_all(buf, method, params, function(result)
|
||||||
vim.lsp.protocol.Methods.textDocument_completion,
|
|
||||||
params,
|
|
||||||
function(result)
|
|
||||||
if self.generation ~= gen then
|
if self.generation ~= gen then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -224,7 +222,15 @@ function Session:dispatch(trigger_kind, trigger_char, manual)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.is_incomplete = false
|
self.is_incomplete = false
|
||||||
for _, response in pairs(result) do
|
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
|
||||||
|
)
|
||||||
|
end
|
||||||
local r = response.result
|
local r = response.result
|
||||||
if type(r) == "table" and r.isIncomplete then
|
if type(r) == "table" and r.isIncomplete then
|
||||||
self.is_incomplete = true
|
self.is_incomplete = true
|
||||||
@@ -239,12 +245,10 @@ function Session:dispatch(trigger_kind, trigger_char, manual)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local base =
|
local base = vim.api.nvim_get_current_line():sub(start + 1, cursor)
|
||||||
vim.api.nvim_get_current_line():sub(start + 1, cursor)
|
|
||||||
vim.fn.complete(start + 1, build_items(result, base))
|
vim.fn.complete(start + 1, build_items(result, base))
|
||||||
end)
|
end)
|
||||||
end
|
end)
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local session = Session.new()
|
local session = Session.new()
|
||||||
@@ -284,7 +288,7 @@ function M.on_insert_char_pre()
|
|||||||
local kind_num = is_trigger
|
local kind_num = is_trigger
|
||||||
and vim.lsp.protocol.CompletionTriggerKind.TriggerCharacter
|
and vim.lsp.protocol.CompletionTriggerKind.TriggerCharacter
|
||||||
or vim.lsp.protocol.CompletionTriggerKind.Invoked
|
or vim.lsp.protocol.CompletionTriggerKind.Invoked
|
||||||
dispatcher:call(nil, kind_num, is_trigger and char or nil)
|
dispatcher(kind_num, is_trigger and char or nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user