aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/rpc_fixture.lua
blob: 87f5a91115b6c5e93a9c30d29cde0068e511ea20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
local deps_prefix = (os.getenv('DEPS_PREFIX') and os.getenv('DEPS_PREFIX')
                     or './.deps/usr')

package.path = deps_prefix .. '/share/lua/5.1/?.lua;' ..
               deps_prefix .. '/share/lua/5.1/?/init.lua;' ..
               package.path

package.cpath = deps_prefix .. '/lib/lua/5.1/?.so;' ..
                package.cpath

local mpack = require('mpack')
local StdioStream = require('nvim.stdio_stream')
local Session = require('nvim.session')

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])
    return "done!"
  elseif method == "exit" then
    session:stop()
    return mpack.NIL
  end
end

local function on_notification(event, args)
  if event == 'ping' and #args == 0 then
    session:notify("nvim_eval", "rpcnotify(g:channel, 'pong')")
  end
end

session:run(on_request, on_notification)