| 🛟 Updated. 28d5985 k33g 18h ago | 1 | package lsp |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | |
| 📦 Turbo Core f3ade8d k33g 11h ago | 6 | "rickub.com/turbo-editors/turbo-core/jsonrpc" |
| 🛟 Updated. 28d5985 k33g 18h ago | 7 | ) |
| 8 | |
| 9 | // The JSON-RPC layer this client talks over is jsonrpc's, which the Agent |
| 10 | // Client Protocol client shares. The names below are kept so that a language |
| 11 | // server's error still reads as an lsp one at the call site. |
| 12 | |
| 13 | // Conn is a JSON-RPC 2.0 connection over an LSP-framed stream. |
| 14 | type Conn = jsonrpc.Conn |
| 15 | |
| 16 | // ResponseError is the error object a response may carry. |
| 17 | type ResponseError = jsonrpc.ResponseError |
| 18 | |
| 19 | // NotificationFunc handles a notification the server sent, such as a batch of |
| 20 | // diagnostics. It is called from the connection's read loop, so it must not |
| 21 | // block for long. |
| 22 | type NotificationFunc = jsonrpc.NotificationFunc |
| 23 | |
| 24 | // ErrClosed is returned once the connection has been closed or its peer has |
| 25 | // gone away. |
| 26 | var ErrClosed = jsonrpc.ErrClosed |
| 27 | |
| 28 | // The JSON-RPC error codes this client uses. |
| 29 | const ( |
| 30 | CodeMethodNotFound = jsonrpc.CodeMethodNotFound |
| 31 | CodeInternalError = jsonrpc.CodeInternalError |
| 32 | ) |
| 33 | |
| 34 | // NewConn returns a connection to a language server over stream. Call Run in a |
| 35 | // goroutine of its own to start reading. |
| 36 | // |
| 37 | // It is NewConn with this package's framing already chosen, which is the only |
| 38 | // thing a language server connection adds to a plain JSON-RPC one. |
| 39 | // |
| 40 | // conn := lsp.NewConn(stream, client.handleNotification, client.answerRequest) |
| 41 | // go conn.Run() |
| 42 | func NewConn(stream io.ReadWriteCloser, onNotify jsonrpc.NotificationFunc, onRequest jsonrpc.RequestFunc) *Conn { |
| 43 | return jsonrpc.NewConn(stream, Framing{}, onNotify, onRequest) |
| 44 | } |