opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(lsp): Clear diagnostics and files maps on client shutdown

Open sauerdaniel opened this issue 13 hours ago • 1 comments

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:

  1. Memory retention from diagnostics data for closed files
  2. Stale data if the same LSP server reconnects
  3. Memory growth over multiple LSP reconnections

Solution

Add cleanup logic in the LSP client shutdown() method to:

  • Clear the diagnostics Map
  • Clear the files object

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.

sauerdaniel avatar Jan 17 '26 23:01 sauerdaniel