Skip to content

Complete LSP server implementation with lifecycle and crash recovery #8

Description

@dollfins

Description

The LSP server integration (src/server.ts) is a stub with several issues:

  1. Memory leakhandleServerMessage creates a new DiagnosticCollection on every message instead of reusing a single collection
  2. No proper LSP protocol handling — Only handles publishDiagnostics but ignores initialization, capabilities, shutdown, etc.
  3. No lifecycle management — The server is never started or stopped; it is defined but not used in extension.ts
  4. No error recovery — If the server process crashes, there is no restart logic

Required Changes

Fix diagnostic collection leak

  • Create the diagnostic collection once in the constructor
  • Reuse it across all publishDiagnostics messages

Implement basic LSP lifecycle

  • Handle initialize request with capabilities response
  • Handle shutdown and exit notifications
  • Properly track client-server state

Wire server into extension lifecycle

  • Start the server in activate() when configured
  • Stop the server in deactivate()
  • Add a configuration option to enable/disable LSP mode

Add crash recovery

  • Restart the server process if it exits unexpectedly
  • Limit restart attempts to avoid infinite loops
  • Log restart events to output channel

Acceptance Criteria

  • No diagnostic collection leak (single collection reused)
  • LSP server handles initialize/shutdown/exit correctly
  • Server starts on extension activation when enabled
  • Server stops on extension deactivation
  • Server auto-restarts on crash (with limit)
  • Tests verify basic LSP handshake

Complexity

High — requires understanding of LSP protocol, child process management, and integration with VS Code diagnostic APIs.

Points

200

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions