aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/rpc.lua
diff options
context:
space:
mode:
authorMathias Fussenegger <f.mathias@zignar.net>2024-01-02 10:19:22 +0100
committerMathias Fußenegger <mfussenegger@users.noreply.github.com>2024-01-02 10:49:14 +0100
commite0112aa1d21aa01eca867f28f77bcca28aae3b39 (patch)
tree5a67bcb82639826db0f6984ee53f17419d9ef77a /runtime/lua/vim/lsp/rpc.lua
parent3f788e73b34521f093846d362bf51e68bc9a3827 (diff)
downloadrneovim-e0112aa1d21aa01eca867f28f77bcca28aae3b39.tar.gz
rneovim-e0112aa1d21aa01eca867f28f77bcca28aae3b39.tar.bz2
rneovim-e0112aa1d21aa01eca867f28f77bcca28aae3b39.zip
refactor(lsp): fix remaining luals warnings in lsp.rpc
Diffstat (limited to 'runtime/lua/vim/lsp/rpc.lua')
-rw-r--r--runtime/lua/vim/lsp/rpc.lua44
1 files changed, 18 insertions, 26 deletions
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index b0d98829a6..51d6bf4f9f 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -226,6 +226,7 @@ end
---@return vim.lsp.rpc.Error
function M.rpc_response_error(code, message, data)
-- 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')
return setmetatable({
code = code,
@@ -473,6 +474,7 @@ function Client:handle_body(body)
type(err) == 'table',
'err must be a table. Use rpc_response_error to help format errors.'
)
+ ---@type string
local code_name = assert(
protocol.ErrorCodes[err.code],
'Errors must use protocol.ErrorCodes. Use rpc_response_error to help format errors.'
@@ -620,34 +622,24 @@ end
---@param dispatchers? vim.lsp.rpc.Dispatchers
---@return vim.lsp.rpc.Dispatchers
local function merge_dispatchers(dispatchers)
- if dispatchers then
- local user_dispatchers = 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
- --- @diagnostic disable-next-line:no-unknown
- dispatchers[dispatch_name] = user_dispatcher
- else
- --- @diagnostic disable-next-line:no-unknown
- dispatchers[dispatch_name] = default_dispatch
- end
+ if not dispatchers then
+ return default_dispatchers
+ end
+ ---@diagnostic disable-next-line: no-unknown
+ for name, fn in pairs(dispatchers) do
+ if type(fn) ~= 'function' then
+ error(string.format('dispatcher.%s must be a function', name))
end
- else
- dispatchers = default_dispatchers
end
- return dispatchers
+ return {
+ notification = dispatchers.notification and vim.schedule_wrap(dispatchers.notification)
+ or default_dispatchers.notification,
+ 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
--- Create a LSP RPC client factory that connects via TCP to the given host