Skip to content

Ensure LSP server exits on stdin close #936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cmd/tsgo/lsp.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package main

import (
"errors"
"flag"
"fmt"
"io"
"os"

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

if err := s.Run(); err != nil && !errors.Is(err, io.EOF) {
if err := s.Run(); err != nil {
return 1
}
return 0
Expand Down
9 changes: 5 additions & 4 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,17 @@ func (s *Server) Run() error {
g.Go(func() error { return s.dispatchLoop(ctx) })
g.Go(func() error { return s.writeLoop(ctx) })
g.Go(func() error { return s.readLoop(ctx) })
return g.Wait()

if err := g.Wait(); err != nil && !errors.Is(err, io.EOF) {
return err
}
return nil
}

func (s *Server) readLoop(ctx context.Context) error {
for {
msg, err := s.read()
if err != nil {
if errors.Is(err, io.EOF) {
return nil
}
if errors.Is(err, lsproto.ErrInvalidRequest) {
s.sendError(nil, err)
continue
Expand Down