Skip to content
Draft
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
9 changes: 0 additions & 9 deletions cmd/tsgo/isprocessalive_other.go

This file was deleted.

25 changes: 0 additions & 25 deletions cmd/tsgo/isprocessalive_unix.go

This file was deleted.

26 changes: 0 additions & 26 deletions cmd/tsgo/isprocessalive_windows.go

This file was deleted.

39 changes: 1 addition & 38 deletions cmd/tsgo/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func runLSP(args []string) int {
cmd.Dir = cwd
return cmd.Output()
},
ProgressDelay: 250 * time.Millisecond,
SetParentProcessID: newParentProcessWatchdog(ctx, stop),
ProgressDelay: 250 * time.Millisecond,
})

if err := s.Run(ctx); err != nil {
Expand All @@ -70,39 +69,3 @@ func runLSP(args []string) int {
}
return 0
}

// newParentProcessWatchdog returns a SetParentProcessID callback if the platform
// supports process-alive checking, or nil otherwise.
func newParentProcessWatchdog(ctx context.Context, stop context.CancelFunc) func(int) {
if !processAliveSupported {
return nil
}
return func(parentPID int) {
startParentProcessWatchdog(ctx, stop, parentPID)
}
}

// startParentProcessWatchdog starts a goroutine that monitors the parent process
// and cancels the context if the parent dies. This prevents orphaned language
// server processes when the editor crashes or is killed.
func startParentProcessWatchdog(ctx context.Context, stop context.CancelFunc, parentPID int) {
if parentPID <= 0 {
return
}
go func() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if !isProcessAlive(parentPID) {
fmt.Fprintf(os.Stderr, "Parent process %d has exited, shutting down.\n", parentPID)
stop()
return
}
}
}
}()
}
8 changes: 0 additions & 8 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type ServerOptions struct {
ParseCache *project.ParseCache
NpmInstall func(cwd string, args []string) ([]byte, error)
ProgressDelay time.Duration // delay before showing progress UI; 0 means no delay
SetParentProcessID func(parentPID int)
}

func NewServer(opts *ServerOptions) *Server {
Expand All @@ -70,7 +69,6 @@ func NewServer(opts *ServerOptions) *Server {
typingsLocation: opts.TypingsLocation,
parseCache: opts.ParseCache,
npmInstall: opts.NpmInstall,
startWatchdog: opts.SetParentProcessID,
initComplete: make(chan struct{}),
progressDelay: opts.ProgressDelay,
}
Expand Down Expand Up @@ -221,8 +219,6 @@ type Server struct {
progressDelay time.Duration
projectProgress *projectLoadingProgress

startWatchdog func(parentPID int)

flakeLogging lsproto.DiagnosticFlakeLogLevel
}

Expand Down Expand Up @@ -1091,10 +1087,6 @@ func (s *Server) handleInitialize(ctx context.Context, params *lsproto.Initializ
}
s.initLocale = s.locale

if s.startWatchdog != nil && params.ProcessId.Integer != nil {
s.startWatchdog(int(*params.ProcessId.Integer))
}

response := &lsproto.InitializeResult{
ServerInfo: &lsproto.ServerInfo{
Name: "typescript-go",
Expand Down