neovim/test/functional/api/rpc_fixture.lua

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
797 B
Lua
Raw Normal View History

--- RPC server fixture.
--
-- Lua's paths are passed as arguments to reflect the path in the test itself.
package.path = arg[1]
package.cpath = arg[2]
2024-01-02 18:09:18 -07:00
local StdioStream = require 'test.client.uv_stream'.StdioStream
local Session = require 'test.client.session'
local stdio_stream = StdioStream.open()
local session = Session.new(stdio_stream)
local function on_request(method, args)
if method == 'poll' then
return 'ok'
elseif method == 'write_stderr' then
io.stderr:write(args[1])
2024-01-02 18:09:18 -07:00
return 'done!'
elseif method == 'exit' then
session:stop()
return vim.NIL
end
end
local function on_notification(event, args)
if event == 'ping' and #args == 0 then
2024-01-02 18:09:18 -07:00
session:notify('nvim_eval', "rpcnotify(g:channel, 'pong')")
end
end
session:run(on_request, on_notification)