-
-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
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:
- Store the
jsonrpc2.Conn
when creating the server and callNotifiy
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 (yamllsConnector Connector) 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"))
return ctx, conn, server
}
func (yamllsConnector Connector) CustomHandler(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error {
switch req.Method() {
case "custom/schema/request":
return reply(ctx, nil, nil)
}
return jsonrpc2.MethodNotFoundHandler(ctx, reply, req)
}
Metadata
Metadata
Assignees
Labels
No labels