Skip to main content

Crate lsdocs_rpc

Crate lsdocs_rpc 

Source
Expand description

MessagePack RPC envelope, framing, codec, peer and transports.

  • message: the msgpack-rpc envelope ([0, id, method, params] etc.).
  • transport: length-prefixed framing and the stdio, pipe and in-memory transports, including stdout protection for plugins.
  • Peer and Connection: a symmetric endpoint. Either side can send requests and notifications; incoming ones are dispatched through a Router.

The wire format is specified in spec/wire.md.

use lsdocs_protocol::{notification, request};
use lsdocs_rpc::{Options, Router, transport};

let router = Router::new()
    .notification::<notification::Log, _>(|params, _peer| {
        eprintln!("plugin says: {}", params.message);
    });
let (peer, connection) = lsdocs_rpc::connect(transport::memory().0, router, Options::default());
tokio::spawn(connection.run());
peer.request::<request::Shutdown>(&()).await?;

Modules§

message
The msgpack-rpc envelope.
trace
Logs every frame as JSON when the lsdocs_rpc::wire tracing target is enabled at TRACE level (what --trace-rpc turns on).
transport
Byte streams a Peer runs over, and how frames are cut from them.

Structs§

Connection
Drives a connection: reads and dispatches incoming messages and writes outgoing ones. Created by connect.
ErrorCode
Error codes used in RpcError::code. They follow JSON-RPC and LSP.
Options
Settings for a connection.
Peer
One end of a connection. Cheap to clone; all clones share the connection.
Router
Handlers for incoming requests and notifications, keyed by method.
RpcError
An error sent in a response.

Enums§

Error
Why a call on a Peer failed.

Functions§

connect
Creates a connection over transport. Returns the Peer for sending and the Connection that must be run (usually spawned) for anything to happen.