Skip to content

Conversation

@jakebailey
Copy link
Member

The LSP spec says to exit if the parent process exits.

Add a callback to the server code to set the parent process ID, then periodically check to see if we should exit.

Might help with some of the "tsgo is staying open", but not so much in cases where "restart" is used. But, good to do what the spec says.

Copilot AI review requested due to automatic review settings January 12, 2026 19:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the LSP specification requirement to exit the language server process when the parent process (typically the editor) terminates. This helps prevent orphaned tsgo processes when editors crash or are killed unexpectedly.

Changes:

  • Added a callback mechanism to set the parent process ID during server initialization
  • Implemented a watchdog goroutine that periodically checks if the parent process is still alive
  • Integrated platform-specific process checking logic for Unix and Windows systems

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/lsp/server.go Added SetParentProcessId callback field to ServerOptions and Server struct; invokes the callback during handleInitialize when processId is provided
cmd/tsgo/lsp.go Implemented parent process watchdog with periodic polling and platform-specific process existence checking

@DanielRosenwasser
Copy link
Member

If the parent process no longer exists, won't we get an EOF on standard input or something?

@jakebailey
Copy link
Member Author

Yeah, I guess that's probably the case...

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jan 13, 2026

#2499 might explain why an EOF was not sufficient for shutting down.

return
}
go func() {
tick := time.Tick(5 * time.Second)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a random amount of time. I don't know what the right number is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants