lspeasy / client/src / NotificationWaiter
Class: NotificationWaiter<TParams>
Defined in: packages/client/src/notifications/wait.ts:63
Tracks a single wait-for-notification operation and its timeout lifecycle.
Remarks
Created internally by LSPClient.waitForNotification. Use LSPClient.waitForNotification rather than instantiating this class directly.
Use When
You need to await a specific server-to-client notification after triggering a server-side operation — for example, waiting for textDocument/publishDiagnostics after saving a document.
Avoid When
You need to listen for ongoing notifications (not a one-shot wait) — use LSPClient.onNotification for persistent subscriptions instead.
Never
NEVER create a NotificationWaiter without setting a timeout — an indefinite wait will leak the waiter permanently if the notification never arrives (e.g. the server suppresses it for certain file types).
NEVER use NotificationWaiter to wait for notifications that arrive before the waiter is registered. The waiter only sees notifications emitted after start() is called; earlier notifications are silently missed.
Example
// Wait for diagnostics after saving
const diags = await client.waitForNotification(
'textDocument/publishDiagnostics',
{
timeout: 5000,
filter: (params) => params.uri === 'file:///src/main.ts',
}
);
console.log(diags.diagnostics);Type Parameters
| Type Parameter | Description |
|---|---|
TParams | The notification params type. |
Constructors
Constructor
new NotificationWaiter<TParams>(
method,
options,
resolve,
reject,
onCleanup): NotificationWaiter<TParams>;Defined in: packages/client/src/notifications/wait.ts:68
Parameters
| Parameter | Type |
|---|---|
method | string |
options | NotificationWaitOptions<TParams> |
resolve | (params) => void |
reject | (error) => void |
onCleanup | () => void |
Returns
NotificationWaiter<TParams>
Methods
cleanup()
cleanup(): void;Defined in: packages/client/src/notifications/wait.ts:131
Clears timeout state and detaches waiter resources.
Returns
void
matches()
matches(method, params): boolean;Defined in: packages/client/src/notifications/wait.ts:100
Returns whether an incoming notification satisfies this waiter.
Parameters
| Parameter | Type | Description |
|---|---|---|
method | string | The notification method string of the incoming message. |
params | TParams | The notification params to test against the optional filter predicate. |
Returns
boolean
true when the method matches and the filter (if any) passes.
reject()
reject(error): void;Defined in: packages/client/src/notifications/wait.ts:123
Rejects the waiter and performs cleanup.
Parameters
| Parameter | Type |
|---|---|
error | Error |
Returns
void
resolve()
resolve(params): void;Defined in: packages/client/src/notifications/wait.ts:115
Resolves the waiter and performs cleanup.
Parameters
| Parameter | Type |
|---|---|
params | TParams |
Returns
void
start()
start(): void;Defined in: packages/client/src/notifications/wait.ts:82
Starts timeout tracking for the wait operation.
Returns
void