Skip to content

lspeasy / client/src

client/src

LSP client package for connecting to language servers.

Remarks

Use @lspeasy/client when you need to build the consumer side of the Language Server Protocol — an editor extension, a CLI analysis tool, a test harness, or any process that speaks to a language server process.

The primary entry point is LSPClient. Construct it with ClientOptions, call connect(transport) to complete the LSP handshake, then use expect<ServerCaps>() to get typed access to capability-aware namespaces (e.g. client.textDocument.hover(params)).

Transport Decision Tree

Stdio (StdioTransport from @lspeasy/core/node) — Use when: spawning the language server as a child process (the canonical editor extension pattern). Zero network overhead; server and client share a lifespan. Failure mode: server process dies silently → stdout EOF fires onClose; pair with HeartbeatMonitor on long-lived processes.

WebSocket (WebSocketTransport from @lspeasy/core) — Use when: the language server runs remotely (CI, container, cloud dev env) or must be browser-accessible. Supports reconnect with exponential back-off. Failure mode: network partition → onError fires without onClose; enable enableReconnect and subscribe to ConnectionHealthTracker events.

TCP (TcpTransport from @lspeasy/core/node) — Use when: you need a persistent local socket and control both ends (e.g. a test harness or a daemon that outlives the client process). Failure mode: port conflict at startup; use mode: 'client' only after confirming the server is listening, or wrap in a retry loop.

DedicatedWorkerTransport (DedicatedWorkerTransport from @lspeasy/core) — Use when: running the language server in a Web Worker for browser isolation. Zero latency (shared memory), no WebSocket overhead. Failure mode: worker uncaught exception terminates silently; subscribe to worker.onerror.

Connection health

Use ConnectionHealthTracker and HeartbeatMonitor to detect silent transport failures. Subscribe to state-change events via ConnectionState.

Dynamic registration

The client handles client/registerCapability and client/unregisterCapability requests from the server automatically, updating the typed namespaces at runtime.

Client

NameDescription
ConnectionStateLifecycle state of an LSPClient connection.
CapabilityGuardValidates outgoing client requests and notifications against the server's declared capabilities.
ClientCapabilityGuardValidates that server-to-client handler registrations are backed by client capabilities declared in the initialize request.
ConnectionHealthTrackerTracks connection state transitions and message activity timestamps.
HeartbeatMonitorRuns interval-based heartbeat checks for active transports.
NotificationWaiterTracks a single wait-for-notification operation and its timeout lifecycle.
CancellableRequestReturn value of LSPClient.sendCancellableRequest.
ClientOptionsConfiguration for an LSPClient instance.
ConnectionHealthAggregated connection health snapshot returned by LSPClient.getConnectionHealth().
HeartbeatConfigConfiguration for optional heartbeat monitoring.
HeartbeatStatusSnapshot of the current heartbeat monitoring status.
InitializeResultInitialize result from server.
NotebookDocumentNamespaceNamespace for sending notebook-document lifecycle notifications to a server.
NotificationWaitOptionsOptions for NotificationWaiter and LSPClient.waitForNotification.
PartialRequestOptionsOptions for LSPClient.sendRequestWithPartialResults.
StateChangeEventPayload emitted when the connection state changes. Subscribe via LSPClient.onConnectionStateChange().
LSPClientTyped LSP client that connects to a language server, manages the LSP handshake, and exposes capability-aware request namespaces.
LSPClientConstructs an LSPClient instance.

Other

Disposable

Renames and re-exports Transport


Logger

Renames and re-exports Transport


LogLevel

Renames and re-exports Transport

Released under the MIT License.