diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-09-12 03:04:33 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2025-01-03 19:24:04 +0100 |
commit | a1ba655dee0f89230ea09712e4df981cc3b15bea (patch) | |
tree | 190940a08a1886cd3eab005ed409f56897f1201f /test/client/msgpack_rpc_stream.lua | |
parent | fe87656f29e933b63f5d4dd03b3c0be3ed4ecf5f (diff) | |
download | rneovim-a1ba655dee0f89230ea09712e4df981cc3b15bea.tar.gz rneovim-a1ba655dee0f89230ea09712e4df981cc3b15bea.tar.bz2 rneovim-a1ba655dee0f89230ea09712e4df981cc3b15bea.zip |
test: spawn_wait() starts a non-RPC Nvim process
Problem:
Can't use `n.clear()` to test non-RPC `nvim` invocations. So tests end
up creating ad-hoc wrappers around `system()` or `jobstart()`.
Solution:
- Introduce `n.spawn_wait()`
- TODO (followup PR): Rename `n.spawn()` and `n.spawn_wait()`.
It's misleading that `n.spawn()` returns a RPC session...
Diffstat (limited to 'test/client/msgpack_rpc_stream.lua')
-rw-r--r-- | test/client/msgpack_rpc_stream.lua | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/test/client/msgpack_rpc_stream.lua b/test/client/msgpack_rpc_stream.lua deleted file mode 100644 index 7131940a58..0000000000 --- a/test/client/msgpack_rpc_stream.lua +++ /dev/null @@ -1,105 +0,0 @@ -local mpack = vim.mpack - -local Response = {} -Response.__index = Response - -function Response.new(msgpack_rpc_stream, request_id) - return setmetatable({ - _msgpack_rpc_stream = msgpack_rpc_stream, - _request_id = request_id, - }, Response) -end - -function Response:send(value, is_error) - local data = self._msgpack_rpc_stream._session:reply(self._request_id) - if is_error then - data = data .. self._msgpack_rpc_stream._pack(value) - data = data .. self._msgpack_rpc_stream._pack(mpack.NIL) - else - data = data .. self._msgpack_rpc_stream._pack(mpack.NIL) - data = data .. self._msgpack_rpc_stream._pack(value) - end - self._msgpack_rpc_stream._stream:write(data) -end - ---- @class test.MsgpackRpcStream ---- @field private _stream test.Stream ---- @field private __pack table -local MsgpackRpcStream = {} -MsgpackRpcStream.__index = MsgpackRpcStream - -function MsgpackRpcStream.new(stream) - return setmetatable({ - _stream = stream, - _pack = mpack.Packer(), - _session = mpack.Session({ - unpack = mpack.Unpacker({ - ext = { - -- Buffer - [0] = function(_c, s) - return mpack.decode(s) - end, - -- Window - [1] = function(_c, s) - return mpack.decode(s) - end, - -- Tabpage - [2] = function(_c, s) - return mpack.decode(s) - end, - }, - }), - }), - }, MsgpackRpcStream) -end - -function MsgpackRpcStream:write(method, args, response_cb) - local data - if response_cb then - assert(type(response_cb) == 'function') - data = self._session:request(response_cb) - else - data = self._session:notify() - end - - data = data .. self._pack(method) .. self._pack(args) - self._stream:write(data) -end - -function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb) - self._stream:read_start(function(data) - if not data then - return eof_cb() - end - local type, id_or_cb, method_or_error, args_or_result - local pos = 1 - local len = #data - while pos <= len do - type, id_or_cb, method_or_error, args_or_result, pos = self._session:receive(data, pos) - if type == 'request' or type == 'notification' then - if type == 'request' then - request_cb(method_or_error, args_or_result, Response.new(self, id_or_cb)) - else - notification_cb(method_or_error, args_or_result) - end - elseif type == 'response' then - if method_or_error == mpack.NIL then - method_or_error = nil - else - args_or_result = nil - end - id_or_cb(method_or_error, args_or_result) - end - end - end) -end - -function MsgpackRpcStream:read_stop() - self._stream:read_stop() -end - -function MsgpackRpcStream:close(signal) - self._stream:close(signal) -end - -return MsgpackRpcStream |