-
Notifications
You must be signed in to change notification settings - Fork 804
Exit LSP process if parent process stops existing #2478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
|
If the parent process no longer exists, won't we get an EOF on standard input or something? |
|
Yeah, I guess that's probably the case... |
|
#2499 might explain why an EOF was not sufficient for shutting down. |
| return | ||
| } | ||
| go func() { | ||
| tick := time.Tick(5 * time.Second) |
There was a problem hiding this comment.
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.
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.