Skip to content

lspeasy / server/src / LSPServer

Type Alias: LSPServer<ServerCaps>

ts
type LSPServer<ServerCaps> = BaseLSPServer<ServerCaps> & Transport<Transport, ServerCaps>;

Defined in: packages/server/src/server.ts:900

Full-featured LSP server with automatic lifecycle management, typed handlers, capability-aware namespaces, and pluggable middleware.

Type Parameters

Type ParameterDefault typeDescription
ServerCaps extends Partial<Transport>TransportShape of the server capabilities.

Remarks

LSPServer manages the complete LSP lifecycle (initialize / initialized / shutdown / exit) automatically. Register handlers with onRequest / onNotification, declare capabilities with registerCapabilities, then start with listen(transport).

Capability-aware namespaces

After registerCapabilities({ hoverProvider: true }), TypeScript exposes server.textDocument.onHover(handler) — methods absent unless the corresponding capability is declared.

Use When

You are building an LSP language server that editors and language-client tooling will connect to.

Avoid When

You need a bare JSON-RPC layer without LSP semantics — use the transport and framing utilities from @lspeasy/core directly.

Never

NEVER call server.shutdown() or server.close() from inside a request or notification handler — doing so attempts to close the transport while it is actively dispatching, causing a deadlock.

NEVER mutate ServerCapabilities after initialized has been received. The client cached the InitializeResult at handshake time; runtime changes are invisible to it.

NEVER share one LSPServer instance across multiple transports or connections. Each connection requires its own server instance to maintain independent state.

Example

ts
import { LSPServer } from '@lspeasy/server';
import { StdioTransport } from '@lspeasy/core/node';

const server = new LSPServer({ name: 'my-lsp', version: '1.0.0' })
  .registerCapabilities({ hoverProvider: true });

server.textDocument.onHover(async (params, token) => {
  if (token.isCancellationRequested) return null;
  return { contents: { kind: 'plaintext', value: 'Hello from my-lsp' } };
});

await server.listen(new StdioTransport());

Released under the MIT License.