~/bend-docscommunity

src/lsp/transport/stdio.bend relies on unsafe/foreign

raw source on the hub · import bolt@1.53.0.0/src/lsp/transport/stdio.bend as Stdio

transport/stdio: LSP's base protocol over stdin and stdout. Reads bytes (a read may end inside a UTF-8 char, and Content-Length counts bytes), keeps what is past the current message in buf. A read asks for exactly what the message in hand lacks (Frame.next): File.read_bytes waits until it has all it was asked for (bend 2.0.40), so asking for more than the editor has sent is a server that never answers.

Trusted, not proved: the transport effect (fd.c, fd.js) delivers stdin bytes in order and writes stdout bytes whole; it is foreign code over descriptors 0 and 1.

3 imports
import Base
import ./service.bend as S
import ../frame.bend as Frame

Types

type Stdio source · line 16 · raw

Type

the process's stdin and stdout, and the bytes read but not yet framed

Definitions

def recv.grown source · line 20 · raw

@bytes:List<&2, U32> -> @inp:File -> @out:File -> @buf:List<&2, U32> -> @rest:(@_:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))) -> IO(Pair(Stdio, Maybe<&2, String>))

no bytes means the peer closed the pipe

def recv.fed source · line 33 · raw

@rr:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @inp:File -> @out:File -> @buf:List<&2, U32> -> @rest:(@_:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))) -> IO(Pair(Stdio, Maybe<&2, String>))

def recv.read source · line 46 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), List<&2, U32>>) -> @out:File -> @buf:List<&2, U32> -> @rest:(@_:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))) -> IO(Pair(Stdio, Maybe<&2, String>))

def recv.lined source · line 55 · raw

@rr:Result<&1, &1, Pair(U32, String), String> -> @inp:File -> @out:File -> @buf:List<&2, U32> -> @rest:(@_:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))) -> IO(Pair(Stdio, Maybe<&2, String>))

def recv.line source · line 68 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> @out:File -> @buf:List<&2, U32> -> @rest:(@_:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))) -> IO(Pair(Stdio, Maybe<&2, String>))

def recv.more source · line 79 · raw

@nn:0xb2e58a591ad27179e8a01dfbb0974cf3/src/lsp/frame.Next -> @inp:File -> @out:File -> @buf:List<&2, U32> -> @rest:(@_:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))) -> IO(Pair(Stdio, Maybe<&2, String>))

what the buffer lacks, read: a header line, or the bytes the body is short of, never more than the message in hand

def recv.on source · line 98 · raw

@cc:0xb2e58a591ad27179e8a01dfbb0974cf3/src/lsp/frame.Cut -> @inp:File -> @out:File -> @+buf:List<&2, U32> -> @rest:(@_:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))) -> IO(Pair(Stdio, Maybe<&2, String>))

a whole message is cut off the buffer; short of one, read what it lacks and look again

def recv.loop source · line 111 · raw

@fuel:Nat -> @h2:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))

def recv source · line 120 · raw

@h2:Stdio -> IO(Pair(Stdio, Maybe<&2, String>))

the fuel bounds the reads one message may take

def send.done source · line 123 · raw

@ww:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> @inp:File -> @buf:List<&2, U32> -> IO(Stdio)

def send source · line 128 · raw

@h2:Stdio -> @body:String -> IO(Stdio)

a body, framed and written

def open source · line 141 · raw

IO(Stdio)

the process's descriptors 0 and 1, wrapped

def new source · line 148 · raw

0xb2e58a591ad27179e8a01dfbb0974cf3/src/lsp/transport/service.Transport<Stdio>

the transport over stdio

Effects (foreign code)

effect stdio.fd source · line 136 · raw

@nn:U32 -> IO(File)

a File for a descriptor the process already holds. Not File.open on /dev/stdin: an editor may hand the server sockets, which no path opens

foreign: src/lsp/transport/fd.c, src/lsp/transport/fd.js