Skip to content

Commit 48e2953

Browse files
authored
Don't even start process alive check if platform does not support it (#3762)
1 parent ed6cf5d commit 48e2953

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

cmd/tsgo/isprocessalive_other.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
package main
44

5-
// isProcessAlive on unsupported platforms always returns true,
6-
// meaning the watchdog will never fire. This is safe: the server
7-
// simply won't detect a dead parent on these platforms.
5+
const processAliveSupported = false
6+
87
func isProcessAlive(pid int) bool {
9-
return true
8+
panic("isProcessAlive is not supported on this platform")
109
}

cmd/tsgo/isprocessalive_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"syscall"
99
)
1010

11+
const processAliveSupported = true
12+
1113
// isProcessAlive checks if a process with the given PID is still running.
1214
// On Unix, FindProcess always succeeds, so we send signal 0 to probe the
1315
// process. If the signal returns nil or EPERM, the process exists (EPERM

cmd/tsgo/isprocessalive_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package main
44

55
import "syscall"
66

7+
const processAliveSupported = true
8+
79
// isProcessAlive checks if a process with the given PID is still running.
810
// On Windows, we open the process with SYNCHRONIZE access and use
911
// WaitForSingleObject with a zero timeout. If the wait times out, the

cmd/tsgo/lsp.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ func runLSP(args []string) int {
6060
cmd.Dir = cwd
6161
return cmd.Output()
6262
},
63-
ProgressDelay: 250 * time.Millisecond,
64-
SetParentProcessID: func(parentPID int) {
65-
startParentProcessWatchdog(ctx, stop, parentPID)
66-
},
63+
ProgressDelay: 250 * time.Millisecond,
64+
SetParentProcessID: newParentProcessWatchdog(ctx, stop),
6765
})
6866

6967
if err := s.Run(ctx); err != nil {
@@ -73,6 +71,17 @@ func runLSP(args []string) int {
7371
return 0
7472
}
7573

74+
// newParentProcessWatchdog returns a SetParentProcessID callback if the platform
75+
// supports process-alive checking, or nil otherwise.
76+
func newParentProcessWatchdog(ctx context.Context, stop context.CancelFunc) func(int) {
77+
if !processAliveSupported {
78+
return nil
79+
}
80+
return func(parentPID int) {
81+
startParentProcessWatchdog(ctx, stop, parentPID)
82+
}
83+
}
84+
7685
// startParentProcessWatchdog starts a goroutine that monitors the parent process
7786
// and cancels the context if the parent dies. This prevents orphaned language
7887
// server processes when the editor crashes or is killed.

0 commit comments

Comments
 (0)