fix(lsp.completion): add logging for request failures
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
local Item = require("lsp.completion.item")
|
||||
local kind = require("lsp.kind")
|
||||
local log = require("log")
|
||||
local util = require("util")
|
||||
|
||||
local REQUEST_DEBOUNCE_MS = 50
|
||||
@@ -198,53 +199,56 @@ function Session:dispatch(trigger_kind, trigger_char, manual)
|
||||
triggerKind = trigger_kind,
|
||||
triggerCharacter = trigger_char,
|
||||
}
|
||||
self.cancel = vim.lsp.buf_request_all(
|
||||
buf,
|
||||
vim.lsp.protocol.Methods.textDocument_completion,
|
||||
params,
|
||||
function(result)
|
||||
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.
|
||||
if self.generation ~= gen then
|
||||
return
|
||||
end
|
||||
vim.schedule(function()
|
||||
-- Re-check: another dispatch may have fired between response
|
||||
-- and the scheduled callback running.
|
||||
if self.generation ~= gen then
|
||||
return
|
||||
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
|
||||
)
|
||||
end
|
||||
if vim.fn.mode() ~= "i" then
|
||||
return
|
||||
local r = response.result
|
||||
if type(r) == "table" and r.isIncomplete then
|
||||
self.is_incomplete = true
|
||||
break
|
||||
end
|
||||
local word_start, cursor = word_bounds()
|
||||
if
|
||||
not self.manual
|
||||
and not self.trigger_char
|
||||
and word_start == cursor
|
||||
then
|
||||
return
|
||||
end
|
||||
local start = word_start
|
||||
for _, response in pairs(result) do
|
||||
local pos = edit_start(response)
|
||||
if pos then
|
||||
start = pos.character
|
||||
break
|
||||
end
|
||||
self.is_incomplete = false
|
||||
for _, response in pairs(result) do
|
||||
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 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()
|
||||
@@ -284,7 +288,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:call(nil, kind_num, is_trigger and char or nil)
|
||||
dispatcher(kind_num, is_trigger and char or nil)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user