transport

package
v0.0.0-...-f58d88c Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

Connection represents a managed connection to a language server.

func NewConnection

func NewConnection(ctx context.Context, stream io.ReadWriteCloser, logger *slog.Logger) (*Connection, error)

NewConnection creates a new managed connection.

func (*Connection) Call

func (c *Connection) Call(ctx context.Context, method string, params any, result any) error

Call makes a request to the language server and waits for a response.

func (*Connection) Close

func (c *Connection) Close() error

Close closes the connection.

func (*Connection) IsConnected

func (c *Connection) IsConnected() bool

IsConnected returns true if the connection is still active.

func (*Connection) Notify

func (c *Connection) Notify(ctx context.Context, method string, params any) error

Notify sends a notification to the language server.

func (*Connection) RegisterHandler

func (c *Connection) RegisterHandler(method string, handler Handler)

RegisterHandler registers a handler for a specific method.

func (*Connection) RegisterNotificationHandler

func (c *Connection) RegisterNotificationHandler(method string, handler NotificationHandler)

RegisterNotificationHandler registers a notification handler.

type Handler

type Handler func(ctx context.Context, method string, params json.RawMessage) (any, error)

Handler is a function that handles incoming messages.

type Message

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      *jsonrpc2.ID    `json:"id,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *jsonrpc2.Error `json:"error,omitempty"`
}

Message represents a JSON-RPC message.

type MessageType

type MessageType int

MessageType represents the type of a JSON-RPC message.

const (
	// RequestMessage is a request that expects a response.
	RequestMessage MessageType = iota
	// NotificationMessage is a notification that doesn't expect a response.
	NotificationMessage
	// ResponseMessage is a response to a request.
	ResponseMessage
	// ErrorMessage is an error response.
	ErrorMessage
)

func ParseMessageType

func ParseMessageType(msg *Message) MessageType

ParseMessageType determines the type of a JSON-RPC message.

type NotificationHandler

type NotificationHandler func(ctx context.Context, method string, params json.RawMessage)

NotificationHandler is a function that handles incoming notifications.

type Router

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

Router routes incoming messages to appropriate handlers.

func NewRouter

func NewRouter() *Router

NewRouter creates a new message router.

func (*Router) Handle

func (r *Router) Handle(method string, handler Handler)

Handle registers a handler for a specific method.

func (*Router) HandleNotification

func (r *Router) HandleNotification(method string, handler NotificationHandler)

HandleNotification registers a notification handler for a specific method.

func (*Router) Route

func (r *Router) Route(ctx context.Context, req *jsonrpc2.Request) (any, error)

Route routes a message to the appropriate handler.

func (*Router) SetDefaultHandler

func (r *Router) SetDefaultHandler(handler Handler)

SetDefaultHandler sets the default handler for unregistered methods.

type StreamTransport

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

StreamTransport provides a bidirectional stream for JSON-RPC communication.

func NewStreamTransport

func NewStreamTransport(reader io.Reader, writer io.Writer, closer io.Closer) *StreamTransport

NewStreamTransport creates a new stream transport.

func (*StreamTransport) Close

func (s *StreamTransport) Close() error

Close implements io.Closer.

func (*StreamTransport) ObjectStream

func (s *StreamTransport) ObjectStream() jsonrpc2.ObjectStream

ObjectStream creates a jsonrpc2.ObjectStream from the transport.

func (*StreamTransport) Read

func (s *StreamTransport) Read(p []byte) (n int, err error)

Read implements io.Reader.

func (*StreamTransport) Write

func (s *StreamTransport) Write(p []byte) (n int, err error)

Write implements io.Writer.

type Transport

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

Transport handles the low-level communication with the language server.

func New

func New(reader io.Reader, writer io.Writer, logger *slog.Logger) *Transport

New creates a new transport.

func NewWithConn

func NewWithConn(conn jsonrpc2.JSONRPC2) *Transport

NewWithConn creates a new transport with an existing JSON-RPC connection.

func (*Transport) Close

func (t *Transport) Close() error

Close closes the transport.

func (*Transport) Receive

func (t *Transport) Receive(ctx context.Context) (*Message, error)

Receive receives a message from the language server.

func (*Transport) Send

func (t *Transport) Send(ctx context.Context, msg *Message) error

Send sends a message to the language server.

Jump to

Keyboard shortcuts

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