lspeasy / client/src / LSPClient
Type Alias: LSPClient<ClientCaps>
type LSPClient<ClientCaps> = BaseLSPClient<ClientCaps> & Transport<ClientCaps, Transport>;Defined in: packages/client/src/client.ts:1351
Typed LSP client that connects to a language server, manages the LSP handshake, and exposes capability-aware request namespaces.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
ClientCaps extends Partial<Transport> | Transport | Client capabilities shape, defaults to ClientCapabilities. |
Remarks
LSPClient handles the initialize / initialized handshake automatically on connect(). After connecting, call expect<ServerCaps>() to narrow the client type to the server's advertised capabilities, giving you typed access to namespaces like client.textDocument.hover(params).
Use When
You are embedding an LSP client inside an editor extension, a CLI tool, a test harness, or any process that connects to a language server.
Avoid When
You need to build the server end — use LSPServer from @lspeasy/server.
Never
NEVER call sendRequest before connect() completes — the transport is not attached yet and the call throws.
NEVER send requests after disconnect() is called — the transport has been closed; any pending promises will reject with a "Connection closed" error.
NEVER share one LSPClient across two separate language server processes — each process is an independent JSON-RPC peer with its own ID sequence and lifecycle state.
Throws
Error When connect() is called while already connected.
Throws
Error When sendRequest() is called before connect() completes.
See
- ClientOptions for all configuration options.
- ConnectionHealthTracker for monitoring connection liveness.
Example
import { LSPClient } from '@lspeasy/client';
import { WebSocketTransport } from '@lspeasy/core';
const client = new LSPClient({
name: 'my-editor',
capabilities: { textDocument: { hover: {} } },
});
const transport = new WebSocketTransport({ url: 'ws://localhost:2087' });
await client.connect(transport);
const typed = client.expect<{ hoverProvider: true }>();
const hover = await typed.textDocument.hover({
textDocument: { uri: 'file:///src/index.ts' },
position: { line: 0, character: 5 },
});