Documentation
¶
Overview ¶
Package jsonrpc is an implementation of a Language Server Protocol JSON-RPC protocol.
Index ¶
- Variables
- type CancelParams
- type Connection
- func (c *Connection) Close()
- func (c *Connection) Run()
- func (c *Connection) SendNotification(method string, params json.RawMessage) error
- func (c *Connection) SendRequest(ctx context.Context, method string, params json.RawMessage) (json.RawMessage, *ResponseError, error)
- func (c *Connection) SetLogger(l Logger)
- type ErrorCode
- type FunctionLogger
- type Logger
- type NotificationHandler
- type NotificationMessage
- type NullFunctionLogger
- type NullLogger
- func (NullLogger) LogIncomingCancelRequest(id string)
- func (NullLogger) LogIncomingDataDelay(time.Duration)
- func (NullLogger) LogIncomingNotification(method string, params json.RawMessage) FunctionLogger
- func (NullLogger) LogIncomingRequest(id string, method string, params json.RawMessage) FunctionLogger
- func (NullLogger) LogIncomingResponse(id string, method string, resp json.RawMessage, respErr *ResponseError)
- func (NullLogger) LogOutgoingCancelRequest(id string)
- func (NullLogger) LogOutgoingDataDelay(time.Duration)
- func (NullLogger) LogOutgoingNotification(method string, params json.RawMessage)
- func (NullLogger) LogOutgoingRequest(id string, method string, params json.RawMessage)
- func (NullLogger) LogOutgoingResponse(id string, method string, resp json.RawMessage, respErr *ResponseError)
- type ProgressParams
- type ProgressToken
- type RequestHandler
- type RequestID
- type RequestMessage
- type ResponseError
- type ResponseMessage
Constants ¶
This section is empty.
Variables ¶
var NullResult json.RawMessage = []byte("null")
Functions ¶
This section is empty.
Types ¶
type CancelParams ¶
type CancelParams struct { // ID The request id to cancel. ID json.RawMessage `json:"id,required"` }
CancelParams The base protocol offers support for request cancellation. To cancel a request, a notification message with the following properties is sent. A request that got canceled still needs to return from the server and send a response back. It can not be left open / hanging. This is in line with the JSON RPC protocol that requires that every request sends a response back. In addition it allows for returning partial results on cancel. If the request returns an error response on cancellation it is advised to set the error code to ErrorCodesRequestCancelled.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is a JSON RPC connection for LSP protocol
func NewConnection ¶
func NewConnection(in io.Reader, out io.Writer, requestHandler RequestHandler, notificationHandler NotificationHandler, errorHandler func(error)) *Connection
NewConnection starts a new
func (*Connection) Close ¶
func (c *Connection) Close()
func (*Connection) Run ¶
func (c *Connection) Run()
func (*Connection) SendNotification ¶
func (c *Connection) SendNotification(method string, params json.RawMessage) error
func (*Connection) SendRequest ¶
func (c *Connection) SendRequest(ctx context.Context, method string, params json.RawMessage) (json.RawMessage, *ResponseError, error)
func (*Connection) SetLogger ¶
func (c *Connection) SetLogger(l Logger)
type ErrorCode ¶
type ErrorCode int
const ( ErrorCodesParseError ErrorCode = -32700 ErrorCodesInvalidRequest ErrorCode = -32600 ErrorCodesMethodNotFound ErrorCode = -32601 ErrorCodesInvalidParams ErrorCode = -32602 ErrorCodesInternalError ErrorCode = -32603 // This is the start range of JSON RPC reserved error codes. // It doesn't denote a real error code. No LSP error codes should // be defined between the start and end range. For backwards // compatibility the `ServerNotInitialized` and the `UnknownErrorCode` // are left in the range. // // @since 3.16.0 ErrorCodesJsonrpcReservedErrorRangeStart ErrorCode = -32099 ErrorCodesServerNotInitialized ErrorCode = -32002 ErrorCodesUnknownErrorCode ErrorCode = -32001 // This is the start range of JSON RPC reserved error codes. // It doesn't denote a real error code. ErrorCodesJsonrpcReservedErrorRangeEnd ErrorCode = -32000 // This is the start range of LSP reserved error codes. // It doesn't denote a real error code. // // @since 3.16.0 ErrorCodesLspReservedErrorRangeStart ErrorCode = -32899 ErrorCodesContentModified ErrorCode = -32801 ErrorCodesRequestCancelled ErrorCode = -32800 // This is the end range of LSP reserved error codes. // It doesn't denote a real error code. // // @since 3.16.0 ErrorCodesLspReservedErrorRangeEnd ErrorCode = -32800 )
type FunctionLogger ¶
type FunctionLogger interface {
Logf(format string, a ...interface{})
}
type Logger ¶
type Logger interface { LogOutgoingRequest(id string, method string, params json.RawMessage) LogIncomingRequest(id string, method string, params json.RawMessage) FunctionLogger LogOutgoingResponse(id string, method string, resp json.RawMessage, respErr *ResponseError) LogIncomingResponse(id string, method string, resp json.RawMessage, respErr *ResponseError) LogOutgoingNotification(method string, params json.RawMessage) LogIncomingNotification(method string, params json.RawMessage) FunctionLogger LogIncomingCancelRequest(id string) LogOutgoingCancelRequest(id string) LogIncomingDataDelay(time.Duration) LogOutgoingDataDelay(time.Duration) }
type NotificationHandler ¶
type NotificationHandler func(logger FunctionLogger, method string, params json.RawMessage)
NotificationHandler handles notifications from a jsonrpc Connection.
type NotificationMessage ¶
type NotificationMessage struct { // The language server protocol always uses “2.0” as the jsonrpc version. JSONRPC string `json:"jsonrpc,required"` // The method to be invoked. Method string `json:"method,required"` // The notification's params. Params json.RawMessage `json:"params,omitempty"` }
NotificationMessage A processed notification message must not send a response back. They work like events.
type NullFunctionLogger ¶
type NullFunctionLogger struct{}
func (NullFunctionLogger) Logf ¶
func (NullFunctionLogger) Logf(format string, a ...interface{})
type NullLogger ¶
type NullLogger struct{}
func (NullLogger) LogIncomingCancelRequest ¶
func (NullLogger) LogIncomingCancelRequest(id string)
func (NullLogger) LogIncomingDataDelay ¶
func (NullLogger) LogIncomingDataDelay(time.Duration)
func (NullLogger) LogIncomingNotification ¶
func (NullLogger) LogIncomingNotification(method string, params json.RawMessage) FunctionLogger
func (NullLogger) LogIncomingRequest ¶
func (NullLogger) LogIncomingRequest(id string, method string, params json.RawMessage) FunctionLogger
func (NullLogger) LogIncomingResponse ¶
func (NullLogger) LogIncomingResponse(id string, method string, resp json.RawMessage, respErr *ResponseError)
func (NullLogger) LogOutgoingCancelRequest ¶
func (NullLogger) LogOutgoingCancelRequest(id string)
func (NullLogger) LogOutgoingDataDelay ¶
func (NullLogger) LogOutgoingDataDelay(time.Duration)
func (NullLogger) LogOutgoingNotification ¶
func (NullLogger) LogOutgoingNotification(method string, params json.RawMessage)
func (NullLogger) LogOutgoingRequest ¶
func (NullLogger) LogOutgoingRequest(id string, method string, params json.RawMessage)
func (NullLogger) LogOutgoingResponse ¶
func (NullLogger) LogOutgoingResponse(id string, method string, resp json.RawMessage, respErr *ResponseError)
type ProgressParams ¶
type ProgressParams struct { // Token The progress token provided by the client or server. Token ProgressToken `json:"token,required"` // The progress data. Value json.RawMessage `json:"value,required"` }
ProgressParams The base protocol offers also support to report progress in a generic fashion. This mechanism can be used to report any kind of progress including work done progress (usually used to report progress in the user interface using a progress bar) and partial result progress to support streaming of results. Progress is reported against a token. The token is different than the request ID which allows to report progress out of band and also for notification.
type RequestHandler ¶
type RequestHandler func(ctx context.Context, logger FunctionLogger, method string, params json.RawMessage, respCallback func(result json.RawMessage, err *ResponseError))
RequestHandler handles requests from a jsonrpc Connection.
type RequestID ¶
type RequestID json.RawMessage
type RequestMessage ¶
type RequestMessage struct { // The language server protocol always uses “2.0” as the jsonrpc version. JSONRPC string `json:"jsonrpc,required"` // The request id. ID json.RawMessage `json:"id,required"` // The method to be invoked. Method string `json:"method,required"` // The method's params. Params json.RawMessage `json:"params,omitempty"` }
A RequestMessage to describe a request between the client and the server. Every processed request must send a response back to the sender of the request.
type ResponseError ¶
type ResponseError struct { // A number indicating the error type that occurred. Code ErrorCode `json:"code,required"` // A string providing a short description of the error. Message string `json:"message"` // A primitive or structured value that contains additional // information about the error. Can be omitted. Data json.RawMessage `json:"data,omitempty"` }
ResponseError is the error object in case a request fails.
func (*ResponseError) AsError ¶
func (r *ResponseError) AsError() error
type ResponseMessage ¶
type ResponseMessage struct { // The language server protocol always uses “2.0” as the jsonrpc version. JSONRPC string `json:"jsonrpc,required"` // The request id. ID json.RawMessage `json:"id,required"` // The result of a request. This member is REQUIRED on success. // This member MUST NOT exist if there was an error invoking the method. Result json.RawMessage `json:"result,omitempty"` // The error object in case a request fails. Error *ResponseError `json:"error,omitempty"` }
A ResponseMessage sent as a result of a request. If a request doesn’t provide a result value the receiver of a request still needs to return a response message to conform to the JSON RPC specification. The result property of the ResponseMessageSuccess should be set to null in this case to signal a successful request.