snoe / node-client

Node.js client and plugin host

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

neovim-client

Build Status

Installation

npm install --global neovim-client

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.

Examples:

var cp = require('child_process');
var attach = require('neovim-client');

var nvim_proc = cp.spawn('nvim', ['-u', 'NONE', '-N', '--embed'], {});
attach(nvim_proc.stdin, nvim_proc.stdout, function(err, nvim) {

  nvim.on('request', function(method, args, resp) {
    // handle msgpack-rpc request
  });

  nvim.on('notification', function(method, args) {
    // handle msgpack-rpc notification
  });

  nvim.command('vsp', function(err, res) {
    nvim.getWindows(function(err, windows) {
      console.log(windows.length);  // 2
      console.log(windows[0] instanceof nvim.Window); // true
      console.log(windows[1] instanceof nvim.Window); // true
      nvim.setCurrentWindow(windows[1], function(err, res) {
        nvim.getCurrentWindow(function(err, win) {
          console.log(win.equals(windows[1]))  // true
          nvim.quit();
          nvim.on('disconnect', function() {
            console.log("Nvim exited!");
          });
        });
      });
    });
  });
});

Methods are attached to buffers, windows and tabpages according to the msgpack-rpc name:

nvim.getCurrentBuffer(function(err, buf) {
  console.log(buf instanceof nvim.Buffer);  // true
  buf.getLineSlice(0, -1, true, true, function(err, lines) {
    console.log(lines);  // ['']
    buf.setLineSlice(0, -1, true, true, ['line1', 'line2'], function(err) {
      buf.getLineSlice(0, -1, true, true, function(err, lines) {
        console.log(lines);  // ['line1', 'line2']
      });
    });
  });
});

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.

About

Node.js client and plugin host

License:MIT License


Languages

Language:JavaScript 96.6%Language:Makefile 3.4%