Skip to content

lspeasy / client/src / CapabilityGuard

Class: CapabilityGuard ​

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

Validates outgoing client requests and notifications against the server's declared capabilities.

Remarks ​

Created internally by LSPClient after a successful initialize handshake. In non-strict mode (default) violations are logged as warnings; in strict mode they throw.

Use When ​

You are implementing a custom client layer and need the same validation behaviour that LSPClient uses. Otherwise this is an internal detail.

See ​

ClientCapabilityGuard for the companion guard that validates server-to-client handler registrations against client capabilities.

Throws ​

Error When strict is true and a method is not in the known method set or the required server capability has not been declared.

Never ​

NEVER construct CapabilityGuard before the initialize handshake completes. Server capabilities are only known after the InitializeResult is received; instantiating the guard too early will treat all methods as unsupported.

Constructors ​

Constructor ​

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

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

Parameters ​

ParameterTypeDefault value
capabilitiesServerCapabilitiesundefined
loggerLoggerundefined
strictbooleanfalse

Returns ​

CapabilityGuard

Methods ​

canSendNotification() ​

ts
canSendNotification(method): boolean;

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

Returns true if the server capability for method is declared.

Parameters ​

ParameterTypeDescription
methodstringThe LSP notification method string to check.

Returns ​

boolean

true if allowed; false (or throws in strict mode) if the required server capability is missing.


canSendRequest() ​

ts
canSendRequest(method): boolean;

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

Returns true if the server capability for method is declared.

Parameters ​

ParameterTypeDescription
methodstringThe LSP request method string to check (e.g. 'textDocument/hover').

Returns ​

boolean

true if allowed; false (non-strict) if the required server capability is missing.

Throws ​

Error In strict mode, throws if method is unknown or its required server capability has not been declared.

See ​

CapabilityGuard for full class documentation.


getServerCapabilities() ​

ts
getServerCapabilities(): ServerCapabilities;

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

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

Returns ​

ServerCapabilities

A shallow copy of the server capabilities object.

Released under the MIT License.