lspeasy / server/src / MessageDispatcher
Class: MessageDispatcher
Defined in: packages/server/src/dispatcher.ts:45
Routes incoming JSON-RPC requests and notifications to their registered handlers.
Remarks
MessageDispatcher is an internal component of LSPServer. It maintains separate handler registries for requests (which require a response) and notifications (fire-and-forget), and handles cancellation via AbortController.
Most users should interact with LSPServer.onRequest / LSPServer.onNotification instead of using MessageDispatcher directly.
Never
NEVER register the same method in both the request and notification handler registries — the dispatcher uses separate lookup tables and the method will only match one path, silently ignoring the other.
NEVER call dispatch before calling setClientCapabilities if your handler reads context.clientCapabilities — the value will be undefined until the initialize request is processed.
Constructors
Constructor
new MessageDispatcher(logger): MessageDispatcher;Defined in: packages/server/src/dispatcher.ts:55
Parameters
| Parameter | Type |
|---|---|
logger | Logger |
Returns
MessageDispatcher
Methods
cancelRequest()
cancelRequest(id): void;Defined in: packages/server/src/dispatcher.ts:238
Cancel a pending request.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | number | The request ID to cancel. |
Returns
void
clear()
clear(): void;Defined in: packages/server/src/dispatcher.ts:250
Clear all handlers
Returns
void
dispatch()
dispatch(
message,
transport,
cancellationTokens): Promise<void>;Defined in: packages/server/src/dispatcher.ts:117
Dispatch an incoming message to the registered handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | Message | The incoming JSON-RPC message to route. |
transport | Transport | The transport to send the response or error on. |
cancellationTokens | Map<string | number, AbortController> | Map of pending request IDs to their AbortControllers. |
Returns
Promise<void>
registerNotification()
registerNotification<Params>(method, handler): void;Defined in: packages/server/src/dispatcher.ts:78
Register a typed notification handler for the given LSP method.
Type Parameters
| Type Parameter |
|---|
Params |
Parameters
| Parameter | Type | Description |
|---|---|---|
method | string | The LSP method string (e.g. 'textDocument/didOpen'). |
handler | NotificationHandler<Params> | The handler function to invoke for matching notifications. |
Returns
void
See
NotificationHandler for the handler signature.
registerRequest()
registerRequest<Params, Result>(method, handler): void;Defined in: packages/server/src/dispatcher.ts:65
Register a typed request handler for the given LSP method.
Type Parameters
| Type Parameter |
|---|
Params |
Result |
Parameters
| Parameter | Type | Description |
|---|---|---|
method | string | The LSP method string (e.g. 'textDocument/hover'). |
handler | RequestHandler<Params, Result> | The handler function to invoke for matching requests. |
Returns
void
See
RequestHandler for the handler signature.
setClientCapabilities()
setClientCapabilities(capabilities): void;Defined in: packages/server/src/dispatcher.ts:106
Set client capabilities (from initialize request)
Parameters
| Parameter | Type |
|---|---|
capabilities | ClientCapabilities |
Returns
void
unregisterNotification()
unregisterNotification(method): void;Defined in: packages/server/src/dispatcher.ts:98
Unregister a notification handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
method | string | The LSP method string whose handler should be removed. |
Returns
void
unregisterRequest()
unregisterRequest(method): void;Defined in: packages/server/src/dispatcher.ts:88
Unregister a request handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
method | string | The LSP method string whose handler should be removed. |
Returns
void