mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(lsp): fix remaining luals warnings in lsp.rpc
This commit is contained in:
parent
3f788e73b3
commit
e0112aa1d2
@ -226,6 +226,7 @@ end
|
|||||||
---@return vim.lsp.rpc.Error
|
---@return vim.lsp.rpc.Error
|
||||||
function M.rpc_response_error(code, message, data)
|
function M.rpc_response_error(code, message, data)
|
||||||
-- TODO should this error or just pick a sane error (like InternalError)?
|
-- TODO should this error or just pick a sane error (like InternalError)?
|
||||||
|
---@type string
|
||||||
local code_name = assert(protocol.ErrorCodes[code], 'Invalid RPC error code')
|
local code_name = assert(protocol.ErrorCodes[code], 'Invalid RPC error code')
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
code = code,
|
code = code,
|
||||||
@ -473,6 +474,7 @@ function Client:handle_body(body)
|
|||||||
type(err) == 'table',
|
type(err) == 'table',
|
||||||
'err must be a table. Use rpc_response_error to help format errors.'
|
'err must be a table. Use rpc_response_error to help format errors.'
|
||||||
)
|
)
|
||||||
|
---@type string
|
||||||
local code_name = assert(
|
local code_name = assert(
|
||||||
protocol.ErrorCodes[err.code],
|
protocol.ErrorCodes[err.code],
|
||||||
'Errors must use protocol.ErrorCodes. Use rpc_response_error to help format errors.'
|
'Errors must use protocol.ErrorCodes. Use rpc_response_error to help format errors.'
|
||||||
@ -620,34 +622,24 @@ end
|
|||||||
---@param dispatchers? vim.lsp.rpc.Dispatchers
|
---@param dispatchers? vim.lsp.rpc.Dispatchers
|
||||||
---@return vim.lsp.rpc.Dispatchers
|
---@return vim.lsp.rpc.Dispatchers
|
||||||
local function merge_dispatchers(dispatchers)
|
local function merge_dispatchers(dispatchers)
|
||||||
if dispatchers then
|
if not dispatchers then
|
||||||
local user_dispatchers = dispatchers
|
return default_dispatchers
|
||||||
dispatchers = {}
|
|
||||||
for dispatch_name, default_dispatch in pairs(default_dispatchers) do
|
|
||||||
---@cast dispatch_name string
|
|
||||||
---@cast default_dispatch function
|
|
||||||
local user_dispatcher = user_dispatchers[dispatch_name] --- @type function
|
|
||||||
if user_dispatcher then
|
|
||||||
if type(user_dispatcher) ~= 'function' then
|
|
||||||
error(string.format('dispatcher.%s must be a function', dispatch_name))
|
|
||||||
end
|
|
||||||
-- server_request is wrapped elsewhere.
|
|
||||||
if
|
|
||||||
not (dispatch_name == 'server_request' or dispatch_name == 'on_exit') -- TODO this blocks the loop exiting for some reason.
|
|
||||||
then
|
|
||||||
user_dispatcher = schedule_wrap(user_dispatcher)
|
|
||||||
end
|
end
|
||||||
---@diagnostic disable-next-line: no-unknown
|
---@diagnostic disable-next-line: no-unknown
|
||||||
dispatchers[dispatch_name] = user_dispatcher
|
for name, fn in pairs(dispatchers) do
|
||||||
else
|
if type(fn) ~= 'function' then
|
||||||
--- @diagnostic disable-next-line:no-unknown
|
error(string.format('dispatcher.%s must be a function', name))
|
||||||
dispatchers[dispatch_name] = default_dispatch
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
return {
|
||||||
dispatchers = default_dispatchers
|
notification = dispatchers.notification and vim.schedule_wrap(dispatchers.notification)
|
||||||
end
|
or default_dispatchers.notification,
|
||||||
return dispatchers
|
on_error = dispatchers.on_error and vim.schedule_wrap(dispatchers.on_error)
|
||||||
|
or default_dispatchers.on_error,
|
||||||
|
|
||||||
|
on_exit = dispatchers.on_exit or default_dispatchers.on_exit,
|
||||||
|
server_request = dispatchers.server_request or default_dispatchers.server_request,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a LSP RPC client factory that connects via TCP to the given host
|
--- Create a LSP RPC client factory that connects via TCP to the given host
|
||||||
|
Loading…
Reference in New Issue
Block a user