aboutsummaryrefslogtreecommitdiff
path: root/test/client/msgpack_rpc_stream.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/client/msgpack_rpc_stream.lua')
-rw-r--r--test/client/msgpack_rpc_stream.lua53
1 files changed, 23 insertions, 30 deletions
diff --git a/test/client/msgpack_rpc_stream.lua b/test/client/msgpack_rpc_stream.lua
index 5711616b17..7131940a58 100644
--- a/test/client/msgpack_rpc_stream.lua
+++ b/test/client/msgpack_rpc_stream.lua
@@ -1,15 +1,4 @@
-local mpack = require('mpack')
-
--- temporary hack to be able to manipulate buffer/window/tabpage
-local Buffer = {}
-Buffer.__index = Buffer
-function Buffer.new(id) return setmetatable({id=id}, Buffer) end
-local Window = {}
-Window.__index = Window
-function Window.new(id) return setmetatable({id=id}, Window) end
-local Tabpage = {}
-Tabpage.__index = Tabpage
-function Tabpage.new(id) return setmetatable({id=id}, Tabpage) end
+local mpack = vim.mpack
local Response = {}
Response.__index = Response
@@ -17,7 +6,7 @@ Response.__index = Response
function Response.new(msgpack_rpc_stream, request_id)
return setmetatable({
_msgpack_rpc_stream = msgpack_rpc_stream,
- _request_id = request_id
+ _request_id = request_id,
}, Response)
end
@@ -33,27 +22,33 @@ function Response:send(value, is_error)
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({
- ext = {
- [Buffer] = function(o) return 0, mpack.encode(o.id) end,
- [Window] = function(o) return 1, mpack.encode(o.id) end,
- [Tabpage] = function(o) return 2, mpack.encode(o.id) end
- }
- }),
+ _pack = mpack.Packer(),
_session = mpack.Session({
unpack = mpack.Unpacker({
ext = {
- [0] = function(_c, s) return Buffer.new(mpack.decode(s)) end,
- [1] = function(_c, s) return Window.new(mpack.decode(s)) end,
- [2] = function(_c, s) return Tabpage.new(mpack.decode(s)) end
- }
- })
+ -- 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
@@ -67,7 +62,7 @@ function MsgpackRpcStream:write(method, args, response_cb)
data = self._session:notify()
end
- data = data .. self._pack(method) .. self._pack(args)
+ data = data .. self._pack(method) .. self._pack(args)
self._stream:write(data)
end
@@ -80,12 +75,10 @@ function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb)
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)
+ 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))
+ request_cb(method_or_error, args_or_result, Response.new(self, id_or_cb))
else
notification_cb(method_or_error, args_or_result)
end