Skip to content

Commit e624abe

Browse files
committed
Use test context
1 parent 2d65be3 commit e624abe

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

cmd/tsgo/lsp.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package main
22

33
import (
4+
"context"
45
"flag"
56
"fmt"
67
"os"
8+
"os/signal"
79
"runtime"
10+
"syscall"
811

912
"github.com/microsoft/typescript-go/internal/bundled"
1013
"github.com/microsoft/typescript-go/internal/core"
@@ -37,6 +40,9 @@ func runLSP(args []string) int {
3740
defer profileSession.Stop()
3841
}
3942

43+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
44+
defer stop()
45+
4046
fs := bundled.WrapFS(osvfs.FS())
4147
defaultLibraryPath := bundled.LibPath()
4248
typingsLocation := getGlobalTypingsCacheLocation()
@@ -51,7 +57,7 @@ func runLSP(args []string) int {
5157
TypingsLocation: typingsLocation,
5258
})
5359

54-
if err := s.Run(); err != nil {
60+
if err := s.Run(ctx); err != nil {
5561
return 1
5662
}
5763
return 0

internal/fourslash/fourslash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
175175
defer func() {
176176
outputWriter.Close()
177177
}()
178-
err := server.Run()
178+
err := server.Run(t.Context())
179179
if err != nil {
180180
t.Error("server error:", err)
181181
}

internal/lsp/server.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"os"
9-
"os/signal"
108
"runtime/debug"
119
"slices"
1210
"sync"
1311
"sync/atomic"
14-
"syscall"
1512

1613
"github.com/go-json-experiment/json"
1714
"github.com/microsoft/typescript-go/internal/collections"
@@ -249,10 +246,7 @@ func (s *Server) RefreshDiagnostics(ctx context.Context) error {
249246
return nil
250247
}
251248

252-
func (s *Server) Run() error {
253-
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
254-
defer stop()
255-
249+
func (s *Server) Run(ctx context.Context) error {
256250
g, ctx := errgroup.WithContext(ctx)
257251
g.Go(func() error { return s.dispatchLoop(ctx) })
258252
g.Go(func() error { return s.writeLoop(ctx) })

0 commit comments

Comments
 (0)