internal/lsp/cmd: suppress EOF errors in serve

When the client closes its connection, we get an EOF, but it's not
really an error. Suppress it so that the gopls binary doesn't exit with
an error.

In principle we should connect this to (lsp.Server).shutdown somehow,
but as far as I know a path for that doesn't exist, and this seems
pretty innocuous to me.

Fixes golang/go#40832.

Change-Id: I9dd83d26bcf5c07e03188d3829e603005d80c8c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249417
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Heschi Kreinick 2020-08-19 15:16:30 -04:00
parent d94536333c
commit d088b475e3
1 changed files with 7 additions and 1 deletions

View File

@ -6,8 +6,10 @@ package cmd
import (
"context"
"errors"
"flag"
"fmt"
"io"
"log"
"os"
"strings"
@ -105,7 +107,11 @@ func (s *Serve) Run(ctx context.Context, args ...string) error {
stream = protocol.LoggingStream(stream, di.LogWriter)
}
conn := jsonrpc2.NewConn(stream)
return ss.ServeStream(ctx, conn)
err := ss.ServeStream(ctx, conn)
if errors.Is(err, io.EOF) {
return nil
}
return err
}
// parseAddr parses the -listen flag in to a network, and address.