aboutsummaryrefslogtreecommitdiff
path: root/test/client/session.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/client/session.lua')
-rw-r--r--test/client/session.lua44
1 files changed, 30 insertions, 14 deletions
diff --git a/test/client/session.lua b/test/client/session.lua
index b1bf5ea75e..cf3d8c4f25 100644
--- a/test/client/session.lua
+++ b/test/client/session.lua
@@ -1,13 +1,19 @@
-local uv = require('luv')
+local uv = vim.uv
local MsgpackRpcStream = require('test.client.msgpack_rpc_stream')
+--- @class test.Session
+--- @field private _pending_messages string[]
+--- @field private _msgpack_rpc_stream test.MsgpackRpcStream
+--- @field private _prepare uv.uv_prepare_t
+--- @field private _timer uv.uv_timer_t
+--- @field private _is_running boolean
local Session = {}
Session.__index = Session
if package.loaded['jit'] then
-- luajit pcall is already coroutine safe
Session.safe_pcall = pcall
else
- Session.safe_pcall = require'coxpcall'.pcall
+ Session.safe_pcall = require 'coxpcall'.pcall
end
local function resume(co, ...)
@@ -25,8 +31,8 @@ local function resume(co, ...)
end
local function coroutine_exec(func, ...)
- local args = {...}
- local on_complete
+ local args = { ... }
+ local on_complete --- @type function?
if #args > 0 and type(args[#args]) == 'function' then
-- completion callback
@@ -50,18 +56,20 @@ function Session.new(stream)
_pending_messages = {},
_prepare = uv.new_prepare(),
_timer = uv.new_timer(),
- _is_running = false
+ _is_running = false,
}, Session)
end
+--- @param timeout integer?
+--- @return string?
function Session:next_message(timeout)
local function on_request(method, args, response)
- table.insert(self._pending_messages, {'request', method, args, response})
+ table.insert(self._pending_messages, { 'request', method, args, response })
uv.stop()
end
local function on_notification(method, args)
- table.insert(self._pending_messages, {'notification', method, args})
+ table.insert(self._pending_messages, { 'notification', method, args })
uv.stop()
end
@@ -83,11 +91,15 @@ function Session:next_message(timeout)
end
function Session:notify(method, ...)
- self._msgpack_rpc_stream:write(method, {...})
+ self._msgpack_rpc_stream:write(method, { ... })
end
+--- @param method string
+--- @param ... any
+--- @return boolean
+--- @return table
function Session:request(method, ...)
- local args = {...}
+ local args = { ... }
local err, result
if self._is_running then
err, result = self:_yielding_request(method, args)
@@ -141,8 +153,12 @@ function Session:stop()
end
function Session:close(signal)
- if not self._timer:is_closing() then self._timer:close() end
- if not self._prepare:is_closing() then self._prepare:close() end
+ if not self._timer:is_closing() then
+ self._timer:close()
+ end
+ if not self._prepare:is_closing() then
+ self._prepare:close()
+ end
self._msgpack_rpc_stream:close(signal)
self.closed = true
end
@@ -159,11 +175,11 @@ function Session:_blocking_request(method, args)
local err, result
local function on_request(method_, args_, response)
- table.insert(self._pending_messages, {'request', method_, args_, response})
+ table.insert(self._pending_messages, { 'request', method_, args_, response })
end
local function on_notification(method_, args_)
- table.insert(self._pending_messages, {'notification', method_, args_})
+ table.insert(self._pending_messages, { 'notification', method_, args_ })
end
self._msgpack_rpc_stream:write(method, args, function(e, r)
@@ -187,7 +203,7 @@ function Session:_run(request_cb, notification_cb, timeout)
end
self._msgpack_rpc_stream:read_start(request_cb, notification_cb, function()
uv.stop()
- self.eof_err = {1, "EOF was received from Nvim. Likely the Nvim process crashed."}
+ self.eof_err = { 1, 'EOF was received from Nvim. Likely the Nvim process crashed.' }
end)
uv.run()
self._prepare:stop()