2019-09-16 10:16:39 -07:00
|
|
|
--- 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]
|
2016-05-12 13:25:15 -07:00
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
local StdioStream = require 'test.client.uv_stream'.StdioStream
|
|
|
|
local Session = require 'test.client.session'
|
2016-05-12 13:25:15 -07:00
|
|
|
|
|
|
|
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
|
2016-05-12 13:25:15 -07:00
|
|
|
session:stop()
|
2023-02-01 04:54:22 -07:00
|
|
|
return vim.NIL
|
2016-05-12 13:25:15 -07:00
|
|
|
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')")
|
2016-05-12 13:25:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
session:run(on_request, on_notification)
|