Skip to content

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 ​

ts
// 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 ParameterDescription
TParamsThe notification params type.

Constructors ​

Constructor ​

ts
new NotificationWaiter<TParams>(
   method, 
   options, 
   resolve, 
   reject, 
   onCleanup
): NotificationWaiter<TParams>;

Defined in: packages/client/src/notifications/wait.ts:68

Parameters ​

ParameterType
methodstring
optionsNotificationWaitOptions<TParams>
resolve(params) => void
reject(error) => void
onCleanup() => void

Returns ​

NotificationWaiter<TParams>

Methods ​

cleanup() ​

ts
cleanup(): void;

Defined in: packages/client/src/notifications/wait.ts:131

Clears timeout state and detaches waiter resources.

Returns ​

void


matches() ​

ts
matches(method, params): boolean;

Defined in: packages/client/src/notifications/wait.ts:100

Returns whether an incoming notification satisfies this waiter.

Parameters ​

ParameterTypeDescription
methodstringThe notification method string of the incoming message.
paramsTParamsThe notification params to test against the optional filter predicate.

Returns ​

boolean

true when the method matches and the filter (if any) passes.


reject() ​

ts
reject(error): void;

Defined in: packages/client/src/notifications/wait.ts:123

Rejects the waiter and performs cleanup.

Parameters ​

ParameterType
errorError

Returns ​

void


resolve() ​

ts
resolve(params): void;

Defined in: packages/client/src/notifications/wait.ts:115

Resolves the waiter and performs cleanup.

Parameters ​

ParameterType
paramsTParams

Returns ​

void


start() ​

ts
start(): void;

Defined in: packages/client/src/notifications/wait.ts:82

Starts timeout tracking for the wait operation.

Returns ​

void

Released under the MIT License.