rpc_fixture.lua 797 B

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