neovim-client
WIP: Currently only works on node 8
Installation
npm install --global neovim2
Usage
This package exports a single attach()
function which takes a pair of
write/read streams and invokes a callback with a Nvim API object. This is
similar to node-msgpack5rpc, but
it provides an automatically generated API.
attach
:
Example const cp = ;const attach = attach; const nvim_proc = cp; // Attach to neovim processconst nvim = await ;await nvimapiPromise;nvim;nvim;nvim;const windows = await nvim; // expect(windows.length).toEqual(4);// expect(windows[0] instanceof nvim.Window).toEqual(true);// expect(windows[1] instanceof nvim.Window).toEqual(true); await nvim;const win = await nvim; // expect(win).not.toEqual(windows[0]);// expect(win).toEqual(windows[2]); const buf = await nvim;// expect(buf instanceof nvim.Buffer).toEqual(true); const lines = await buf;// expect(lines).toEqual(['']); await buf;const newLines = await buf;// expect(newLines).toEqual(['line1', 'line2']); nvim;nvim_proc;
A typescript declaration file is available as documentation of the API and also for typescript users that seek to use this library. Note that the interfaces are automatically generated at a certain point in time, and may not correspond exactly to the API of your installed Nvim.
Debugging / troubleshooting
Here are a few env vars you can set while starting neovim
, that can help debugging and configuring logging:
NVIM_NODE_HOST_DEBUG
Will spawn the node process that calls neovim-client-host
with --inspect-brk
so you can have a debugger. Pair that with this Node Inspector Manager Chrome plugin
Logging
Logging is done using winston
through the logger
module. Plugins have console
replaced with this interface.
NVIM_NODE_DEBUG_LEVEL
Sets the logging level for winston. Default is info
, available levels are { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
NVIM_NODE_LOG_FILE
Sets the log file path
Usage through node REPL
NVIM_LISTEN_ADDRESS
First, start Nvim with a known address (or use the $NVIM_LISTEN_ADDRESS of a running instance):
$ NVIM_LISTEN_ADDRESS=/tmp/nvim nvim In another terminal, connect a node REPL to Nvim
let nvim;// `scripts/nvim` will detect if `NVIM_LISTEN_ADDRESS` is set and use that unix socket// Otherwise will create an embedded `nvim` instance; nvim;
The tests and scripts
can be consulted for more examples.