Documentation
¶
Overview ¶
Package jsonrpc provides generic JSON-RPC 2.0 types and utilities that can be shared between LSP and other JSON-RPC based protocols.
Index ¶
Constants ¶
const ( CodeParseError int32 = -32700 CodeInvalidRequest int32 = -32600 CodeMethodNotFound int32 = -32601 CodeInvalidParams int32 = -32602 CodeInternalError int32 = -32603 )
Standard JSON-RPC error codes.
Variables ¶
var ( ErrInvalidHeader = errors.New("jsonrpc: invalid header") ErrInvalidContentLength = errors.New("jsonrpc: invalid content length") ErrNoContentLength = errors.New("jsonrpc: no content length") )
var ErrInvalidJSONRPCVersion = errors.New("invalid JSON-RPC version")
Functions ¶
This section is empty.
Types ¶
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID represents a JSON-RPC message ID, which can be either a string or integer.
func NewID ¶
func NewID(rawValue IntegerOrString) *ID
NewID creates an ID from an IntegerOrString value.
func (*ID) MarshalJSON ¶
func (*ID) UnmarshalJSON ¶
type IntegerOrString ¶
IntegerOrString is a helper type for creating IDs.
type JSONRPCVersion ¶
type JSONRPCVersion struct{}
JSONRPCVersion represents the JSON-RPC version field, always "2.0".
func (JSONRPCVersion) MarshalJSON ¶
func (JSONRPCVersion) MarshalJSON() ([]byte, error)
func (*JSONRPCVersion) UnmarshalJSON ¶
func (*JSONRPCVersion) UnmarshalJSON(data []byte) error
type Message ¶
type Message struct {
JSONRPC JSONRPCVersion `json:"jsonrpc"`
ID *ID `json:"id,omitzero"`
Method string `json:"method,omitzero"`
Params json.Value `json:"params,omitzero"`
Result json.Value `json:"result,omitzero"`
Error *ResponseError `json:"error,omitzero"`
}
Message represents a raw JSON-RPC message that can be a request, notification, or response. Unlike lsproto.Message, this keeps params/result as raw JSON for generic handling.
func (*Message) IsNotification ¶
IsNotification returns true if this message is a notification (has method but no ID).
func (*Message) IsRequest ¶
IsRequest returns true if this message is a request (has ID and method).
func (*Message) IsResponse ¶
IsResponse returns true if this message is a response (has ID but no method).
func (*Message) Kind ¶
func (m *Message) Kind() MessageKind
Kind returns the kind of message this is.
type MessageKind ¶
type MessageKind int
MessageKind indicates what type of message this is.
const ( MessageKindNotification MessageKind = iota MessageKindRequest MessageKindResponse )
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads JSON-RPC messages with Content-Length framing.
type RequestMessage ¶
type RequestMessage struct {
JSONRPC JSONRPCVersion `json:"jsonrpc"`
ID *ID `json:"id,omitzero"`
Method string `json:"method"`
Params any `json:"params,omitzero"`
}
RequestMessage is a convenience type for creating request/notification messages.
type ResponseError ¶
type ResponseError struct {
Code int32 `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitzero"`
}
ResponseError represents a JSON-RPC error response.
func (*ResponseError) Error ¶
func (r *ResponseError) Error() string
func (*ResponseError) String ¶
func (r *ResponseError) String() string
type ResponseMessage ¶
type ResponseMessage struct {
JSONRPC JSONRPCVersion `json:"jsonrpc"`
ID *ID `json:"id,omitzero"`
Result any `json:"result,omitzero"`
Error *ResponseError `json:"error,omitzero"`
}
ResponseMessage is a convenience type for creating response messages.