Documentation ¶
Overview ¶
Package lsprpc implements a jsonrpc2.StreamServer that may be used to serve the LSP on a jsonrpc2 channel.
Index ¶
- Constants
- func ConnectToRemote(ctx context.Context, addr string) (net.Conn, error)
- func ExecuteCommand(ctx context.Context, addr string, id string, request, result interface{}) error
- func ParseAddr(listen string) (network string, address string)
- type AutoDialer
- type BinderFunc
- type ClientBinder
- type ClientFunc
- type ClientSession
- type ForwardBinder
- type Forwarder
- type HandlerMiddleware
- type Handshaker
- type Metadata
- type Middleware
- type PeerInfo
- type ServerBinder
- type ServerFunc
- type ServerState
- type StreamServer
Constants ¶
const AutoNetwork = "auto"
AutoNetwork is the pseudo network type used to signal that gopls should use automatic discovery to resolve a remote address.
Variables ¶
This section is empty.
Functions ¶
func ExecuteCommand ¶ added in v0.1.1
Types ¶
type AutoDialer ¶ added in v0.1.5
type AutoDialer struct {
// contains filtered or unexported fields
}
An AutoDialer is a jsonrpc2 dialer that understands the 'auto' network.
func NewAutoDialer ¶ added in v0.1.5
func NewAutoDialer(rawAddr string, argFunc func(network, addr string) []string) (*AutoDialer, error)
func (*AutoDialer) Dial ¶ added in v0.1.5
func (d *AutoDialer) Dial(ctx context.Context) (io.ReadWriteCloser, error)
Dial implements the jsonrpc2.Dialer interface.
type BinderFunc ¶ added in v0.1.5
type BinderFunc func(ctx context.Context, conn *jsonrpc2_v2.Connection) (jsonrpc2_v2.ConnectionOptions, error)
The BinderFunc type adapts a bind function to implement the jsonrpc2.Binder interface.
func (BinderFunc) Bind ¶ added in v0.1.5
func (f BinderFunc) Bind(ctx context.Context, conn *jsonrpc2_v2.Connection) (jsonrpc2_v2.ConnectionOptions, error)
type ClientBinder ¶ added in v0.1.2
type ClientBinder struct {
// contains filtered or unexported fields
}
ClientBinder binds an LSP client to an incoming connection.
func NewClientBinder ¶ added in v0.1.2
func NewClientBinder(newClient ClientFunc) *ClientBinder
func (*ClientBinder) Bind ¶ added in v0.1.2
func (b *ClientBinder) Bind(ctx context.Context, conn *jsonrpc2_v2.Connection) (jsonrpc2_v2.ConnectionOptions, error)
type ClientFunc ¶ added in v0.1.2
A ClientFunc is used to construct an LSP client for a given server.
type ClientSession ¶
type ClientSession struct { SessionID string `json:"sessionID"` Logfile string `json:"logfile"` DebugAddr string `json:"debugAddr"` }
ClientSession identifies a current client LSP session on the server. Note that it looks similar to handshakeResposne, but in fact 'Logfile' and 'DebugAddr' now refer to the client.
type ForwardBinder ¶ added in v0.1.2
type ForwardBinder struct {
// contains filtered or unexported fields
}
func NewForwardBinder ¶ added in v0.1.2
func NewForwardBinder(dialer jsonrpc2_v2.Dialer) *ForwardBinder
func (*ForwardBinder) Bind ¶ added in v0.1.2
func (b *ForwardBinder) Bind(ctx context.Context, conn *jsonrpc2_v2.Connection) (opts jsonrpc2_v2.ConnectionOptions, _ error)
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
A Forwarder is a jsonrpc2.StreamServer that handles an LSP stream by forwarding it to a remote. This is used when the gopls process started by the editor is in the `-remote` mode, which means it finds and connects to a separate gopls daemon. In these cases, we still want the forwarder gopls to be instrumented with telemetry, and want to be able to in some cases hijack the jsonrpc2 connection with the daemon.
func NewForwarder ¶
func NewForwarder(rawAddr string, argFunc func(network, address string) []string) (*Forwarder, error)
NewForwarder creates a new Forwarder, ready to forward connections to the remote server specified by rawAddr. If provided and rawAddr indicates an 'automatic' address (starting with 'auto;'), argFunc may be used to start a remote server for the auto-discovered address.
type HandlerMiddleware ¶ added in v0.1.5
type HandlerMiddleware func(jsonrpc2_v2.Handler) jsonrpc2_v2.Handler
HandlerMiddleware is a middleware that only modifies the jsonrpc2 handler.
type Handshaker ¶ added in v0.1.5
type Handshaker struct { // Metadata will be shared with peers via handshaking. Metadata Metadata // contains filtered or unexported fields }
Handshaker handles both server and client handshaking over jsonrpc2. To instrument server-side handshaking, use Handshaker.Middleware. To instrument client-side handshaking, call Handshaker.ClientHandshake for any new client-side connections.
func (*Handshaker) ClientHandshake ¶ added in v0.1.5
func (h *Handshaker) ClientHandshake(ctx context.Context, conn *jsonrpc2_v2.Connection)
ClientHandshake performs a client-side handshake with the server at the other end of conn, recording the server's peer info and watching for conn's disconnection.
func (*Handshaker) Middleware ¶ added in v0.1.5
func (h *Handshaker) Middleware(inner jsonrpc2_v2.Binder) jsonrpc2_v2.Binder
Middleware is a jsonrpc2 middleware function to augment connection binding to handle the handshake method, and record disconnections.
func (*Handshaker) Peers ¶ added in v0.1.5
func (h *Handshaker) Peers() []PeerInfo
Peers returns the peer info this handshaker knows about by way of either the server-side handshake middleware, or client-side handshakes.
type Metadata ¶ added in v0.1.5
type Metadata map[string]interface{}
Metadata holds arbitrary data transferred between jsonrpc2 peers.
type Middleware ¶ added in v0.1.5
type Middleware func(jsonrpc2_v2.Binder) jsonrpc2_v2.Binder
Middleware defines a transformation of jsonrpc2 Binders, that may be composed to build jsonrpc2 servers.
func BindHandler ¶ added in v0.1.5
func BindHandler(hmw HandlerMiddleware) Middleware
BindHandler transforms a HandlerMiddleware into a Middleware.
func CommandInterceptor ¶ added in v0.1.5
func CommandInterceptor(command string, run func(*protocol.ExecuteCommandParams) (interface{}, error)) Middleware
func GoEnvMiddleware ¶ added in v0.1.5
func GoEnvMiddleware() (Middleware, error)
type PeerInfo ¶ added in v0.1.5
type PeerInfo struct { // RemoteID is the identity of the current server on its peer. RemoteID int64 // LocalID is the identity of the peer on the server. LocalID int64 // IsClient reports whether the peer is a client. If false, the peer is a // server. IsClient bool // Metadata holds arbitrary information provided by the peer. Metadata Metadata }
PeerInfo holds information about a peering between jsonrpc2 servers.
type ServerBinder ¶ added in v0.1.2
type ServerBinder struct {
// contains filtered or unexported fields
}
ServerBinder binds incoming connections to a new server.
func NewServerBinder ¶ added in v0.1.2
func NewServerBinder(newServer ServerFunc) *ServerBinder
func (*ServerBinder) Bind ¶ added in v0.1.2
func (b *ServerBinder) Bind(ctx context.Context, conn *jsonrpc2_v2.Connection) (jsonrpc2_v2.ConnectionOptions, error)
type ServerFunc ¶ added in v0.1.2
A ServerFunc is used to construct an LSP server for a given client.
type ServerState ¶
type ServerState struct { Logfile string `json:"logfile"` DebugAddr string `json:"debugAddr"` GoplsPath string `json:"goplsPath"` CurrentClientID string `json:"currentClientID"` Clients []ClientSession `json:"clients"` }
ServerState holds information about the gopls daemon process, including its debug information and debug information of all of its current connected clients.
func QueryServerState ¶
func QueryServerState(ctx context.Context, addr string) (*ServerState, error)
QueryServerState queries the server state of the current server.
type StreamServer ¶
type StreamServer struct {
// contains filtered or unexported fields
}
The StreamServer type is a jsonrpc2.StreamServer that handles incoming streams as a new LSP session, using a shared cache.
func NewStreamServer ¶
func NewStreamServer(cache *cache.Cache, daemon bool) *StreamServer
NewStreamServer creates a StreamServer using the shared cache. If withTelemetry is true, each session is instrumented with telemetry that records RPC statistics.
func (*StreamServer) Binder ¶ added in v0.1.2
func (s *StreamServer) Binder() *ServerBinder
func (*StreamServer) ServeStream ¶
ServeStream implements the jsonrpc2.StreamServer interface, by handling incoming streams using a new lsp server.