rpc_fixture.lua 809 B

123456789101112131415161718192021222324252627282930313233
  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. local mpack = require('mpack')
  7. local StdioStream = require('nvim.stdio_stream')
  8. local Session = require('nvim.session')
  9. local stdio_stream = StdioStream.open()
  10. local session = Session.new(stdio_stream)
  11. local function on_request(method, args)
  12. if method == 'poll' then
  13. return 'ok'
  14. elseif method == 'write_stderr' then
  15. io.stderr:write(args[1])
  16. return "done!"
  17. elseif method == "exit" then
  18. session:stop()
  19. return mpack.NIL
  20. end
  21. end
  22. local function on_notification(event, args)
  23. if event == 'ping' and #args == 0 then
  24. session:notify("nvim_eval", "rpcnotify(g:channel, 'pong')")
  25. end
  26. end
  27. session:run(on_request, on_notification)