fix(lsp): Clear diagnostics and files maps on client shutdown
Summary
Properly clean up LSP client resources when the underlying LSP server process disconnects or exits.
Fixes #9143 Relates to #5363
Problem
When an LSP client shuts down, the diagnostics Map and files object are not cleared. This can cause:
- Memory retention from diagnostics data for closed files
- Stale data if the same LSP server reconnects
- Memory growth over multiple LSP reconnections
Solution
Add cleanup logic in the LSP client shutdown() method to:
- Clear the
diagnosticsMap - Clear the
filesobject
Changes
-
packages/opencode/src/lsp/client.ts- Add cleanup in shutdown() method
Testing
- [x] TypeScript compilation passes (
bun turbo typecheck) - [x] Unit tests pass (725 tests, 0 failures)
- [x] LSP client tests pass (3 tests)
Note: Manual LSP server disconnect testing was not performed.
The following comment was made by an LLM, it may be inaccurate:
Potential Duplicate Found
PR #7050: "fix: add LRU eviction to LSP client file and diagnostics tracking"
- https://github.com/anomalyco/opencode/pull/7050
Why it's related: This PR also addresses memory management issues with the LSP client's diagnostics and files tracking. While PR #9144 takes a shutdown-based cleanup approach, PR #7050 implements LRU (Least Recently Used) eviction as a solution to the same underlying problem of memory retention in the LSP client. They may be addressing overlapping concerns about the diagnostics Map and files object accumulation.
You may want to check if PR #7050 was merged and whether it already resolves the issues mentioned in #9143 and #5363.