Skip to main content

Module framing

Module framing 

Source
Expand description

LSP Content-Length header framing (Microsoft LSP base protocol). Pure parser – no IO, no allocations beyond the returned FrameHeader.

Content-Length: 47\r\n
Content-Type: application/vscode-jsonrpc; charset=utf-8\r\n
\r\n
{"jsonrpc":"2.0","method":"initialized","params":{}}

The header block is ASCII; the body is UTF-8 JSON. Content-Length is mandatory. Any other header – including the optional Content-Type – is captured but not interpreted.

§Error model

Returns FrameError for ill-formed headers; the codec propagates these as ProtocolError and tears down the transport. A misbehaving server cannot wedge the editor: the actor restarts the server with backoff (§5.4 crash recovery).

Structs§

FrameHeader
One parsed LSP message header.

Enums§

FrameError
Header-parse failures.

Constants§

MAX_MESSAGE_BYTES
Per-message size ceiling. 64 MiB is comfortably above the largest realistic LSP payload (workspace symbol indices on huge monorepos sit in the few-megabyte range) while bounding memory pressure from a runaway server.

Functions§

encode_header
Encode a frame header for an outgoing message body of body_len bytes. Returns the ASCII header bytes including the trailing \r\n\r\n terminator – ready to be written before the body. Allocation-light: one String of bounded size.
parse_header_block
Parse the bytes of one header block (everything BEFORE the \r\n\r\n terminator) into a FrameHeader.
parse_header_block_with_limit
parse_header_block with an explicit ceiling. Tests use this to verify the bound is enforced; production paths go through the public wrapper.