package lsp import ( "io" "codeberg.org/turbo-editors/turbo-core/jsonrpc" ) // The JSON-RPC layer this client talks over is jsonrpc's, which the Agent // Client Protocol client shares. The names below are kept so that a language // server's error still reads as an lsp one at the call site. // Conn is a JSON-RPC 2.0 connection over an LSP-framed stream. type Conn = jsonrpc.Conn // ResponseError is the error object a response may carry. type ResponseError = jsonrpc.ResponseError // NotificationFunc handles a notification the server sent, such as a batch of // diagnostics. It is called from the connection's read loop, so it must not // block for long. type NotificationFunc = jsonrpc.NotificationFunc // ErrClosed is returned once the connection has been closed or its peer has // gone away. var ErrClosed = jsonrpc.ErrClosed // The JSON-RPC error codes this client uses. const ( CodeMethodNotFound = jsonrpc.CodeMethodNotFound CodeInternalError = jsonrpc.CodeInternalError ) // NewConn returns a connection to a language server over stream. Call Run in a // goroutine of its own to start reading. // // It is NewConn with this package's framing already chosen, which is the only // thing a language server connection adds to a plain JSON-RPC one. // // conn := lsp.NewConn(stream, client.handleNotification, client.answerRequest) // go conn.Run() func NewConn(stream io.ReadWriteCloser, onNotify jsonrpc.NotificationFunc, onRequest jsonrpc.RequestFunc) *Conn { return jsonrpc.NewConn(stream, Framing{}, onNotify, onRequest) }