fix(lsp): cleanup orphan LSP servers on process exit
Implement cross-platform process cleanup handlers for LSP servers. Added registerProcessCleanup() method to LSPServerManager that: - Kills all spawned LSP server processes on process.exit - Handles SIGINT (Ctrl+C) - all platforms - Handles SIGTERM (kill signal) - Unix/macOS/Linux - Handles SIGBREAK (Ctrl+Break) - Windows specific This prevents LSP servers from becoming orphan processes when opencode terminates unexpectedly. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -21,6 +21,45 @@ class LSPServerManager {
|
|||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
this.startCleanupTimer()
|
this.startCleanupTimer()
|
||||||
|
this.registerProcessCleanup()
|
||||||
|
}
|
||||||
|
|
||||||
|
private registerProcessCleanup(): void {
|
||||||
|
const cleanup = () => {
|
||||||
|
for (const [, managed] of this.clients) {
|
||||||
|
try {
|
||||||
|
managed.client.stop()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
this.clients.clear()
|
||||||
|
if (this.cleanupInterval) {
|
||||||
|
clearInterval(this.cleanupInterval)
|
||||||
|
this.cleanupInterval = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Works on all platforms
|
||||||
|
process.on("exit", cleanup)
|
||||||
|
|
||||||
|
// Ctrl+C - works on all platforms
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
cleanup()
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Kill signal - Unix/macOS
|
||||||
|
process.on("SIGTERM", () => {
|
||||||
|
cleanup()
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Ctrl+Break - Windows specific
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
process.on("SIGBREAK", () => {
|
||||||
|
cleanup()
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getInstance(): LSPServerManager {
|
static getInstance(): LSPServerManager {
|
||||||
|
|||||||
Reference in New Issue
Block a user