From b619c1cc78ded28139151173e89aa8e343665ce1 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Tue, 18 May 2021 13:33:26 -0400 Subject: [PATCH] internal/lsp/lsprpc: partial integration of the jsonrpc_v2 library Update the protocol package to allow wrapping the jsonrpc2 API, and add wrappers for v1 and v2 of the API, so that we may switch between them. Add simple bindings for the lsprpc package for jsonrpc2_v2 package, and get them working well enough to pass a version TestClientLogging test. This seemed like a reasonable checkpoint. Also add some type safety to client closing: all LSP clients must implement io.Closer. Change-Id: Ib2e6906e0db0c94102a7e794de932d6b61d54670 Reviewed-on: https://go-review.googlesource.com/c/tools/+/320850 Trust: Robert Findley Trust: Ian Cottrell Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Ian Cottrell --- internal/jsonrpc2/jsonrpc2.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/jsonrpc2/jsonrpc2.go b/internal/jsonrpc2/jsonrpc2.go index d459055..66bd5a3 100644 --- a/internal/jsonrpc2/jsonrpc2.go +++ b/internal/jsonrpc2/jsonrpc2.go @@ -51,6 +51,12 @@ func (defaultHandler) Handle(context.Context, *Request) (interface{}, error) { return nil, ErrNotHandled } +type HandlerFunc func(ctx context.Context, req *Request) (interface{}, error) + +func (f HandlerFunc) Handle(ctx context.Context, req *Request) (interface{}, error) { + return f(ctx, req) +} + // async is a small helper for things with an asynchronous result that you can // wait for. type async struct {