Documentation
¶
Overview ¶
Package jsonrpc implements a thin JSON-RPC 2.0 codec for communicating with Language Server child processes over Content-Length framed stdio.
Index ¶
- func ReadMessage(r *bufio.Reader) (json.RawMessage, error)
- func WriteMessage(w io.Writer, msg json.RawMessage) error
- type Conn
- func (c *Conn) Call(ctx context.Context, method string, params interface{}, result interface{}) error
- func (c *Conn) Close() error
- func (c *Conn) Listen(ctx context.Context) error
- func (c *Conn) Notify(ctx context.Context, method string, params interface{}) error
- func (c *Conn) Send(ctx context.Context, method string, params interface{}) (string, error)
- type Notification
- type NotificationFunc
- type Request
- type Response
- type ResponseError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadMessage ¶
func ReadMessage(r *bufio.Reader) (json.RawMessage, error)
ReadMessage reads a single Content-Length framed JSON-RPC message from r. It parses the Content-Length header, ignores other headers (e.g., Content-Type), and reads the exact number of body bytes specified.
func WriteMessage ¶
func WriteMessage(w io.Writer, msg json.RawMessage) error
WriteMessage writes a Content-Length framed JSON-RPC message to w. It writes "Content-Length: N\r\n\r\n" followed by the message body.
Types ¶
type Conn ¶
type Conn struct {
// OnNotification is called for incoming notifications during Listen.
OnNotification NotificationFunc
// contains filtered or unexported fields
}
Conn is a bidirectional JSON-RPC 2.0 connection over a Content-Length framed stream. It supports Call (request-response), Notify (fire-and-forget), and Listen (dispatch loop).
func NewConn ¶
NewConn creates a new JSON-RPC connection wrapping the given stream. sessionPrefix is prepended to request IDs to avoid collisions when multiple sessions share an LS worker (per Pitfall 4: sequential integer IDs).
tracer is used to emit lspool.lsp.{method} child spans on Call and lspool.lsp.notify.{method} on Notify. A nil tracer falls back to a noop tracer (Phase 55 D-01: never reach for the global tracer provider).
func (*Conn) Call ¶
func (c *Conn) Call(ctx context.Context, method string, params interface{}, result interface{}) error
Call sends a JSON-RPC request and waits for the response. The result is unmarshaled into the provided result pointer.
func (*Conn) Listen ¶
Listen reads messages from the connection and dispatches them. Responses are routed to pending Call waiters. Notifications are delivered to the OnNotification callback. Listen blocks until the context is cancelled or the connection is closed.
type Notification ¶
type Notification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Notification is a JSON-RPC 2.0 notification (no ID, no response expected).
func NewNotification ¶
func NewNotification(method string, params interface{}) (*Notification, error)
NewNotification creates a new JSON-RPC 2.0 notification.
type NotificationFunc ¶
type NotificationFunc func(method string, params json.RawMessage)
NotificationFunc is a callback for handling incoming notifications.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request is a JSON-RPC 2.0 request message.
func NewRequest ¶
NewRequest creates a new JSON-RPC 2.0 request.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *ResponseError `json:"error,omitempty"`
}
Response is a JSON-RPC 2.0 response message.
type ResponseError ¶
type ResponseError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
ResponseError is a JSON-RPC 2.0 error object.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
Error implements the error interface.