Skip to main content

Module serve

Module serve 

Source
Expand description

ktrs serve: a long-lived formatter for build tools (the Java shim in java/), so a build pays for process startup once instead of once per file.

Protocol v1, over stdin/stdout. Every message is a frame: a 4-byte big-endian length, then that many bytes. The server sends one frame on start, ktrs-serve 1 <version>, then answers each request frame with one response frame, in order, until stdin closes (exit 0).

A request is UTF-8 key=value header lines, an empty line, then the source code:

keyvaluesdefault
stylemeta, google, kotlinlangmeta
max-width, block-indent, continuation-indentpositive integersthe style’s
remove-unused-importstrue, falsetrue
trailing-commasnone, only_add, completethe style’s
paththe file’s path, for .editorconfig and to prefix messagesnone
editorconfigtrue, false: apply .editorconfig at path over the abovefalse

A response is status=ok or status=error, changed=true|false (ok only), an empty line, then the formatted code or the error message (ktfmt’s CLI wording, one line per diagnostic). Unknown keys and bad values are errors for that request only; a broken frame ends the server (exit 2).

Constants§

PROTOCOL_VERSION

Functions§

run