Plugins in other languages #
A plugin is any program that speaks the protocol on its standard input and output. That takes a MessagePack library (or a small codec of your own) and four things:
Framing. Every message is a 4-byte big-endian length, then that many bytes of MessagePack.
Messages. A request is
[0, id, method, [params]], its response[1, id, error, result](erroris nil on success), a notification[2, method, [params]]. Params are always wrapped in an array.The handshake. Answer the
initializerequest with the protocol version, your plugin's name and version, and its capabilities:The phases your capabilities claim: here, answer each
parserequest ({"source", "text"}) with{"document": ...}. Answershutdownwith nil, and exit on theexitnotification or when stdin closes.
Keep stdout for the protocol: write logs to stderr.
A complete example #
examples/plugins/txt-parser/txt_parser.py in the
lsdocs repository is a
parser for .txt files in about 200 lines of standard-library Python,
MessagePack codec included, written from the
specification alone. The
test suite builds a site with it.
Checking your implementation #
- The JSON Schemas in
schema/describe every message and the document tree, for generating types. fixtures/has an encoded example of each message, with a JSON twin: decoding the.msgpackfile must give the.jsonone.lsdocs build --trace-rpclogs every message exchanged, as JSON.