neovim-java

Neovim Java client


Project maintained by esensar Hosted on GitHub Pages — Theme by mattgraham

neovim-java - Java Client for Neovim API

Build Status Maven Central

Neovim Java is a Java Client for Neovim RPC API. Currently it is best suited for creating a GUI using Java and either an embedded Neovim instance or connecting to an exisitng instance either using Unix domain sockets or TCP sockets. Plugin development may be possible as well, but it was not tested.

This library consists of multiple modules and you may choose which one you want to use (depending on preferences and level of abstraction needed):

Core RPC

Core of the library with a basic interface for RPC communication through a RPCConnection. This implements basic Neovim API definition, without any specific types or functions. It can be used if functions to be used may not be known beforehand. All of the classes in this module may be replaced with a different implementation if special behaviour is required.

Basic usage:

// Get an instance of RPCStreamer
RPCStreamer client = RPCClient.getDefaultAsyncInstance();

// Prepare a connection to neovim
ProcessBuilder pb = new ProcessBuilder("nvim", "--embed");
Process neovim = pb.start(); // Start embedded neovim instance

RPCConnection neovimConnection = new ProcessRPCConnection(neovim, true); // true to kill neovim once connection is closed

// Connect to neovim
client.attach(neovimConnection);

// Send feed keys call
client.send(new RequestMessage.Builder("nvim_feedkeys").addArgument("jjjj").addArgument("").addArgument(false));

// Send get current line call and print out the response
client.send(new RequestMessage.Builder("nvim_get_current_line"), (id, response) -> System.out.println(response));

Customizations

By default, RPCClient will use a sequential message id generator, meaning every new message will have its id increased by one. This makes it possible to match up response for given request. If you need a different behaviour, you may implement MessageIdGenerator interface and provide a custom RPCStreamer to RPCClient which will use that generator.

MessageIdGenerator customGenerator = createCustomGenerator();

RPCStreamer customStreamer = new PackStream(sender, listener, customGenerator);
RPCStreamer client = new RPCClient.Builder()
    .withRPCStreamer(customStreamer)
    .build();

Similar to this, different parts of RPCClient can be changed using the builder:

  1. ExecutorService used to listen for requests
  2. ObjectMapper used for parsing requests and responses
  3. RPCSender used to send messages
  4. RPCListener used to listen for requests

Info

If you wish to include this module (and not some other module), you may add it as your dependency:
Maven:

<dependency>
  <groupId>com.ensarsarajcic.neovim.java</groupId>
  <artifactId>core-rpc</artifactId>
  <version>${neovimjava.version}</version>
</dependency>

Gradle:

compile 'com.ensarsarajcic.neovim.java:core-rpc:${neovimjava.version}'

Reactive Core RPC

Unix Socket Connection

Neovim API

Neovim RX API

Handler annotations

Neovim notifications

API Explorer