rpc_fixture.lua 1004 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. local deps_prefix = './.deps/usr'
  2. if os.getenv('DEPS_PREFIX') then
  3. deps_prefix = os.getenv('DEPS_PREFIX')
  4. end
  5. package.path = deps_prefix .. '/share/lua/5.1/?.lua;' ..
  6. deps_prefix .. '/share/lua/5.1/?/init.lua;' ..
  7. package.path
  8. package.cpath = deps_prefix .. '/lib/lua/5.1/?.so;' ..
  9. package.cpath
  10. local mpack = require('mpack')
  11. local StdioStream = require('nvim.stdio_stream')
  12. local Session = require('nvim.session')
  13. local stdio_stream = StdioStream.open()
  14. local session = Session.new(stdio_stream)
  15. local function on_request(method, args)
  16. if method == 'poll' then
  17. return 'ok'
  18. elseif method == 'write_stderr' then
  19. io.stderr:write(args[1])
  20. return "done!"
  21. elseif method == "exit" then
  22. session:stop()
  23. return mpack.NIL
  24. end
  25. end
  26. local function on_notification(event, args)
  27. if event == 'ping' and #args == 0 then
  28. session:notify("nvim_eval", "rpcnotify(g:channel, 'pong')")
  29. end
  30. end
  31. session:run(on_request, on_notification)