diff --git a/src/index.ts b/src/index.ts index 79c631af9..0db253849 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,6 +63,7 @@ import { createSisyphusTask, interactive_bash, startTmuxCheck, + lspManager, } from "./tools"; import { BackgroundManager } from "./features/background-agent"; import { SkillMcpManager } from "./features/skill-mcp-manager"; @@ -427,6 +428,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { } if (sessionInfo?.id) { await skillMcpManager.disconnectSession(sessionInfo.id); + await lspManager.cleanupTempDirectoryClients(); } } diff --git a/src/tools/index.ts b/src/tools/index.ts index b02117b23..3ec21b0a3 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -10,8 +10,11 @@ import { lsp_rename, lsp_code_actions, lsp_code_action_resolve, + lspManager, } from "./lsp" +export { lspManager } + import { ast_grep_search, ast_grep_replace, diff --git a/src/tools/lsp/client.ts b/src/tools/lsp/client.ts index d72458990..725594bee 100644 --- a/src/tools/lsp/client.ts +++ b/src/tools/lsp/client.ts @@ -182,6 +182,26 @@ class LSPServerManager { this.cleanupInterval = null } } + + async cleanupTempDirectoryClients(): Promise { + const keysToRemove: string[] = [] + for (const [key, managed] of this.clients.entries()) { + const isTempDir = key.startsWith("/tmp/") || key.startsWith("/var/folders/") + const isIdle = managed.refCount === 0 + if (isTempDir && isIdle) { + keysToRemove.push(key) + } + } + for (const key of keysToRemove) { + const managed = this.clients.get(key) + if (managed) { + this.clients.delete(key) + try { + await managed.client.stop() + } catch {} + } + } + } } export const lspManager = LSPServerManager.getInstance()