File: rpc_fixture.lua

package info (click to toggle)
neovim 0.11.4-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 64,136 kB
  • sloc: ansic: 263,156; python: 1,472; lisp: 1,237; sh: 1,138; makefile: 378; xml: 83; ruby: 6
file content (31 lines) | stat: -rw-r--r-- 797 bytes parent folder | download | duplicates (2)
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
--- RPC server fixture.
--
-- Lua's paths are passed as arguments to reflect the path in the test itself.
package.path = arg[1]
package.cpath = arg[2]

local StdioStream = require 'test.client.uv_stream'.StdioStream
local Session = require 'test.client.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 vim.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)