Skip to content

Commit

Permalink
test: simplify msgpack_rpc_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jan 25, 2024
1 parent 47a1e8f commit 0a2a93f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
52 changes: 11 additions & 41 deletions test/client/msgpack_rpc_stream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,6 @@
--- @field NIL userdata vim.NIL
local mpack = vim.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 Response = {}
Response.__index = Response

Expand All @@ -56,42 +37,31 @@ function Response:send(value, is_error)
self._msgpack_rpc_stream._stream:write(table.concat(data))
end

--- @class MsgpackRpcStream
--- @field _stream ProcessStream
--- @field _session unknown
--- @field _pack unknown
--- @class test.MsgpackRpcStream
--- @field private _stream ProcessStream
--- @field private _session unknown
--- @field private _pack unknown
local MsgpackRpcStream = {}
MsgpackRpcStream.__index = MsgpackRpcStream

--- @param stream ProcessStream
--- @return 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 = {
-- Buffer
[0] = function(_c, s)
return Buffer.new(mpack.decode(s))
return mpack.decode(s)
end,
-- Window
[1] = function(_c, s)
return Window.new(mpack.decode(s))
return mpack.decode(s)
end,
-- Tabpage
[2] = function(_c, s)
return Tabpage.new(mpack.decode(s))
return mpack.decode(s)
end,
},
}),
Expand Down
4 changes: 2 additions & 2 deletions test/gitdir_watcher_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ local git = helpers.git
helpers.env()

local function get_bufs()
local bufs = {}
local bufs = {} --- @type table<integer,string>
for _, b in ipairs(helpers.api.nvim_list_bufs()) do
bufs[b.id] = helpers.api.nvim_buf_get_name(b)
bufs[b] = helpers.api.nvim_buf_get_name(b)
end
return bufs
end
Expand Down

0 comments on commit 0a2a93f

Please sign in to comment.