Skip to content

Commit f9431be

Browse files
authored
Ensure LSP server exits on stdin close (#936)
1 parent 1b88303 commit f9431be

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

cmd/tsgo/lsp.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package main
22

33
import (
4-
"errors"
54
"flag"
65
"fmt"
7-
"io"
86
"os"
97

108
"github.com/microsoft/typescript-go/internal/bundled"
@@ -49,7 +47,7 @@ func runLSP(args []string) int {
4947
DefaultLibraryPath: defaultLibraryPath,
5048
})
5149

52-
if err := s.Run(); err != nil && !errors.Is(err, io.EOF) {
50+
if err := s.Run(); err != nil {
5351
return 1
5452
}
5553
return 0

internal/lsp/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,17 @@ func (s *Server) Run() error {
187187
g.Go(func() error { return s.dispatchLoop(ctx) })
188188
g.Go(func() error { return s.writeLoop(ctx) })
189189
g.Go(func() error { return s.readLoop(ctx) })
190-
return g.Wait()
190+
191+
if err := g.Wait(); err != nil && !errors.Is(err, io.EOF) {
192+
return err
193+
}
194+
return nil
191195
}
192196

193197
func (s *Server) readLoop(ctx context.Context) error {
194198
for {
195199
msg, err := s.read()
196200
if err != nil {
197-
if errors.Is(err, io.EOF) {
198-
return nil
199-
}
200201
if errors.Is(err, lsproto.ErrInvalidRequest) {
201202
s.sendError(nil, err)
202203
continue

0 commit comments

Comments
 (0)