You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One thing I'm currently missing is the ability to use protocol extensions.
One can already call custom server methods with the Request(ctx context.Context, method string, params interface{}) (result interface{}, err error) function. But custom Notifications are not supported by the server interface.
Also the client implementation (NewClient) does not allow adding a custom fallback handler but will just use jsonrpc2.MethodNotFoundHandler.
My current workaround is:
Store the jsonrpc2.Conn when creating the server and call Notifiy directly on it.
A custom NewClient method, that includes a custom handler:
// CustomNewClient returns the context in which Client is embedded, jsonrpc2.Conn, and the Server.func (yamllsConnectorConnector) CustomNewClient(ctx context.Context, client protocol.Client, stream jsonrpc2.Stream, logger*zap.Logger) (context.Context, jsonrpc2.Conn, protocol.Server) {
ctx=protocol.WithClient(ctx, client)
conn:=jsonrpc2.NewConn(stream)
conn.Go(ctx,
protocol.Handlers(
protocol.ClientHandler(client, yamllsConnector.CustomHandler),
),
)
server:=protocol.ServerDispatcher(conn, logger.Named("server"))
returnctx, conn, server
}
func (yamllsConnectorConnector) CustomHandler(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error {
switchreq.Method() {
case"custom/schema/request":
returnreply(ctx, nil, nil)
}
returnjsonrpc2.MethodNotFoundHandler(ctx, reply, req)
}
The text was updated successfully, but these errors were encountered:
Thanks for this awesome package.
One thing I'm currently missing is the ability to use protocol extensions.
One can already call custom server methods with the
Request(ctx context.Context, method string, params interface{}) (result interface{}, err error)
function. But custom Notifications are not supported by the server interface.Also the client implementation (
NewClient
) does not allow adding a custom fallback handler but will just usejsonrpc2.MethodNotFoundHandler
.My current workaround is:
jsonrpc2.Conn
when creating the server and callNotifiy
directly on it.NewClient
method, that includes a custom handler:The text was updated successfully, but these errors were encountered: