jsonrpc

package
v0.0.0-...-5af948b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package jsonrpc provides a JSON-RPC 2.0 server implementation for the version of the protocol defined at https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#baseProtocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewError

func NewError(code ErrorCode, message string, data any) error

NewError returns an error which can be encoded as a JSON-RPC error response.

func NewInvalidRequestError

func NewInvalidRequestError(errorMsg string) error

NewInvalidRequestError returns an error indicating that the provided request is invalid.

func NewMethodNotFoundError

func NewMethodNotFoundError(method string) error

NewMethodNotFoundError returns an error indicating that the requested method was not found.

func Serve

func Serve(in io.Reader, out io.Writer, handler Handler) error

Serve reads JSON-RPC messages from in, passes them to handler, and writes the responses to out.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a JSON-RPC client.

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

Notify sends a notification to the server.

type ErrorCode

type ErrorCode int

ErrorCode is a number indicating the error type that occurred.

const (
	ParseError     ErrorCode = -32700
	InvalidRequest ErrorCode = -32600
	MethodNotFound ErrorCode = -32601
	InvalidParams  ErrorCode = -32602
	InternalError  ErrorCode = -32603
)

JSON-RPC error codes

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#errorCodes

type Handler

type Handler interface {
	// HandleRequest responds to a JSON-RPC request.
	HandleRequest(method string, params *json.RawMessage) (any, error)
	// HandleNotification handles a JSON-RPC notification.
	HandleNotification(method string, params *json.RawMessage)
	// SetClient sets the client that the handler can use to send requests and notifications to the server's client.
	SetClient(*Client)
}

Handler handles JSON-RPC requests and notifications.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL