diff --git a/internal/jsonrpc2/jsonrpc2_test.go b/internal/jsonrpc2/jsonrpc2_test.go index d9cc307b5..072f1d5fa 100644 --- a/internal/jsonrpc2/jsonrpc2_test.go +++ b/internal/jsonrpc2/jsonrpc2_test.go @@ -111,7 +111,7 @@ func run(ctx context.Context, t *testing.T, withHeaders bool, r io.ReadCloser, w if withHeaders { stream = jsonrpc2.NewHeaderStream(r, w) } else { - stream = jsonrpc2.NewStream(r, w) + stream = jsonrpc2.NewRawStream(r, w) } conn := jsonrpc2.NewConn(stream) wg.Add(1) diff --git a/internal/jsonrpc2/servertest/servertest.go b/internal/jsonrpc2/servertest/servertest.go index 13815e0cb..ee27c8cc9 100644 --- a/internal/jsonrpc2/servertest/servertest.go +++ b/internal/jsonrpc2/servertest/servertest.go @@ -86,10 +86,10 @@ func (s *PipeServer) Connect(ctx context.Context) *jsonrpc2.Conn { cReader.Close() cWriter.Close() }) - serverStream := jsonrpc2.NewStream(sReader, cWriter) + serverStream := jsonrpc2.NewRawStream(sReader, cWriter) go s.server.ServeStream(ctx, serverStream) - clientStream := jsonrpc2.NewStream(cReader, sWriter) + clientStream := jsonrpc2.NewRawStream(cReader, sWriter) return jsonrpc2.NewConn(clientStream) } diff --git a/internal/jsonrpc2/stream.go b/internal/jsonrpc2/stream.go index c7d73f727..c12eb003b 100644 --- a/internal/jsonrpc2/stream.go +++ b/internal/jsonrpc2/stream.go @@ -28,23 +28,23 @@ type Stream interface { Write(context.Context, Message) (int64, error) } -// NewStream returns a Stream built on top of an io.Reader and io.Writer +// NewRawStream returns a Stream built on top of an io.Reader and io.Writer. // The messages are sent with no wrapping, and rely on json decode consistency // to determine message boundaries. -func NewStream(in io.Reader, out io.Writer) Stream { - return &plainStream{ +func NewRawStream(in io.Reader, out io.Writer) Stream { + return &rawStream{ in: json.NewDecoder(in), out: out, } } -type plainStream struct { +type rawStream struct { in *json.Decoder outMu sync.Mutex out io.Writer } -func (s *plainStream) Read(ctx context.Context) (Message, int64, error) { +func (s *rawStream) Read(ctx context.Context) (Message, int64, error) { select { case <-ctx.Done(): return nil, 0, ctx.Err() @@ -58,7 +58,7 @@ func (s *plainStream) Read(ctx context.Context) (Message, int64, error) { return msg, int64(len(raw)), err } -func (s *plainStream) Write(ctx context.Context, msg Message) (int64, error) { +func (s *rawStream) Write(ctx context.Context, msg Message) (int64, error) { select { case <-ctx.Done(): return 0, ctx.Err() @@ -74,7 +74,7 @@ func (s *plainStream) Write(ctx context.Context, msg Message) (int64, error) { return int64(n), err } -// NewHeaderStream returns a Stream built on top of an io.Reader and io.Writer +// NewHeaderStream returns a Stream built on top of an io.Reader and io.Writer. // The messages are sent with HTTP content length and MIME type headers. // This is the format used by LSP and others. func NewHeaderStream(in io.Reader, out io.Writer) Stream {