rpc_fixture.lua (797B)
1 --- RPC server fixture. 2 -- 3 -- Lua's paths are passed as arguments to reflect the path in the test itself. 4 package.path = arg[1] 5 package.cpath = arg[2] 6 7 local StdioStream = require 'test.client.uv_stream'.StdioStream 8 local Session = require 'test.client.session' 9 10 local stdio_stream = StdioStream.open() 11 local session = Session.new(stdio_stream) 12 13 local function on_request(method, args) 14 if method == 'poll' then 15 return 'ok' 16 elseif method == 'write_stderr' then 17 io.stderr:write(args[1]) 18 return 'done!' 19 elseif method == 'exit' then 20 session:stop() 21 return vim.NIL 22 end 23 end 24 25 local function on_notification(event, args) 26 if event == 'ping' and #args == 0 then 27 session:notify('nvim_eval', "rpcnotify(g:channel, 'pong')") 28 end 29 end 30 31 session:run(on_request, on_notification)