ocamlformat-rpc

ocamlformat-rpc is a RPC mode for OCamlFormat, a tool to format OCaml code.

ocamlformat-rpc listens to RPC requests, provided on the standard input, and prints the response on the standard output. See the manpage for options.

Agreeing on a RPC version

Before the client and the server agree on a common version to use the following commands are available:

If the server agrees upon the version he will send the reply Version v and the protocol version is set to v, to use another version later the client has to close the connexion and start a new one. If the server cannot use version v he might propose another version w by sending the reply Version w that the client can accept by sending the same request for version w, or propose another version. If the server cannot propose another version it will close the connection. Unknown commands are ignored.

Once the client and the server agree on a common version, the requests you can send may differ from one version to another.

Commands

ocamlformat-rpc accepts different commands depending on the version agreed upon.

Version 1

Version 2

  1. (Path p) sets the path to the formatted file.
  2. (Config config) sets the formatting options. config is a list of options, for example: ((profile default) (parse-docstrings true)) See this page for the available formatting options.

Unknown commands are ignored.

All the commands take canonical s-expressions. To build your RPC client to interact with ocamlformat-rpc please refer to the library ocamlformat-rpc-lib.