Skip to content

Commit 177d586

Browse files
committed
Move ctx up to the top where it should be
1 parent 8762147 commit 177d586

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

cmd/tsgo/lsp.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"os"
8-
"os/signal"
98
"runtime"
10-
"syscall"
119

1210
"github.com/microsoft/typescript-go/internal/bundled"
1311
"github.com/microsoft/typescript-go/internal/core"
@@ -17,7 +15,7 @@ import (
1715
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
1816
)
1917

20-
func runLSP(args []string) int {
18+
func runLSP(ctx context.Context, args []string) int {
2119
flag := flag.NewFlagSet("lsp", flag.ContinueOnError)
2220
stdio := flag.Bool("stdio", false, "use stdio for communication")
2321
pprofDir := flag.String("pprofDir", "", "Generate pprof CPU/memory profiles to the given directory.")
@@ -40,9 +38,6 @@ func runLSP(args []string) int {
4038
defer profileSession.Stop()
4139
}
4240

43-
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
44-
defer stop()
45-
4641
fs := bundled.WrapFS(osvfs.FS())
4742
defaultLibraryPath := bundled.LibPath()
4843
typingsLocation := getGlobalTypingsCacheLocation()

cmd/tsgo/main.go

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

33
import (
4+
"context"
45
"os"
6+
"os/signal"
7+
"syscall"
58

69
"github.com/microsoft/typescript-go/internal/execute"
710
)
@@ -11,11 +14,14 @@ func main() {
1114
}
1215

1316
func runMain() int {
17+
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
18+
defer cancel()
19+
1420
args := os.Args[1:]
1521
if len(args) > 0 {
1622
switch args[0] {
1723
case "--lsp":
18-
return runLSP(args[1:])
24+
return runLSP(ctx, args[1:])
1925
case "--api":
2026
return runAPI(args[1:])
2127
}

0 commit comments

Comments
 (0)