lsptestutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendNotification

func SendNotification[Params any](t *testing.T, c *LSPClient, info lsproto.NotificationInfo[Params], params Params)

SendNotification sends a typed notification.

func SendRequest

func SendRequest[Params, Resp any](t *testing.T, c *LSPClient, info lsproto.RequestInfo[Params, Resp], params Params) (*lsproto.Message, Resp, bool)

SendRequest sends a typed request and waits for the response.

func SendRequestAsync

func SendRequestAsync[Params, Resp any](t *testing.T, c *LSPClient, info lsproto.RequestInfo[Params, Resp], params Params) func() (*lsproto.Message, Resp, bool)

SendRequestAsync sends a typed request and returns a waiter for its response.

Types

type LSPClient

type LSPClient struct {
	Server *lsp.Server

	// OnServerNotification handles server-initiated notifications (e.g., $/progress).
	// If nil, notifications are ignored.
	OnServerNotification ServerNotificationHandler
	// contains filtered or unexported fields
}

LSPClient provides infrastructure for communicating with an LSP server in tests.

func NewLSPClient

func NewLSPClient(t *testing.T, serverOpts lsp.ServerOptions, onServerRequest ServerRequestHandler) (*LSPClient, func() error)

NewLSPClient creates an LSPClient wrapping the given server and pipes.

func (*LSPClient) MessageRouter

func (c *LSPClient) MessageRouter(ctx context.Context) error

MessageRouter runs in a goroutine and routes incoming messages from the server. It handles responses to client requests and server-initiated requests. It continues draining the output channel until it is closed (EOF), even after context cancellation, to prevent the server's writeLoop from blocking on a send.

func (*LSPClient) NextID

func (c *LSPClient) NextID() int32

NextID returns the next request ID.

func (*LSPClient) SendRequestWorker

func (c *LSPClient) SendRequestWorker(t *testing.T, req *lsproto.RequestMessage, reqID *jsonrpc.ID) (*lsproto.ResponseMessage, bool)

This is an untyped version of SendRequest. Prefer to use SendRequest when possible.

func (*LSPClient) SetCompilerOptionsForInferredProjects

func (c *LSPClient) SetCompilerOptionsForInferredProjects(options *core.CompilerOptions)

func (*LSPClient) WriteMsg

func (c *LSPClient) WriteMsg(t *testing.T, msg *lsproto.Message)

WriteMsg validates and sends a message to the server. This is an untyped low-level method; prefer SendRequest and SendNotification for typed interactions.

type LSPReader

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

LSPReader reads LSP messages from a channel.

func (*LSPReader) Read

func (r *LSPReader) Read() (*lsproto.Message, error)

type LSPWriter

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

LSPWriter writes LSP messages to a channel.

func (*LSPWriter) Close

func (w *LSPWriter) Close()

func (*LSPWriter) Write

func (w *LSPWriter) Write(msg *lsproto.Message) error

type ServerNotificationHandler

type ServerNotificationHandler func(ctx context.Context, req *lsproto.RequestMessage)

ServerNotificationHandler handles server-initiated notifications (e.g., $/progress).

type ServerRequestHandler

type ServerRequestHandler func(ctx context.Context, req *lsproto.RequestMessage) *lsproto.ResponseMessage

ServerRequestHandler handles server-initiated requests and returns the response to send back.

Jump to

Keyboard shortcuts

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