Skip to content

lspeasy / client/src / ClientCapabilityGuard

Class: ClientCapabilityGuard

Defined in: packages/client/src/capability-guard.ts:126

Validates that server-to-client handler registrations are backed by client capabilities declared in the initialize request.

Remarks

Created internally by LSPClient. In non-strict mode violations are logged as warnings; in strict mode they throw.

Never

NEVER register server-to-client handlers for capabilities not declared in the original initialize request — the server may send the corresponding requests, but without the capability declaration the client has no contract to handle them, leading to silent failures or unexpected errors.

Constructors

Constructor

ts
new ClientCapabilityGuard(
   capabilities, 
   logger, 
   strict?): ClientCapabilityGuard;

Defined in: packages/client/src/capability-guard.ts:127

Parameters

ParameterTypeDefault value
capabilitiesClientCapabilitiesundefined
loggerLoggerundefined
strictbooleanfalse

Returns

ClientCapabilityGuard

Methods

canRegisterHandler()

ts
canRegisterHandler(method): boolean;

Defined in: packages/client/src/capability-guard.ts:144

Returns true if the client has declared the capability required to handle method.

Parameters

ParameterTypeDescription
methodstringThe LSP method string to validate against client capabilities.

Returns

boolean

true if the client capability is declared; false (non-strict) if missing.

Throws

Error In strict mode, throws if method is unknown or the required client capability was not declared in the initialize request.

See

ClientCapabilityGuard for full class documentation.


getClientCapabilities()

ts
getClientCapabilities(): ClientCapabilities;

Defined in: packages/client/src/capability-guard.ts:167

Returns a defensive copy of the client capabilities this guard was built from.

Returns

ClientCapabilities

A shallow copy of the client capabilities object.

Released under the MIT License.