Skip to content

lspeasy / server/src / RequestHandler

Type Alias: RequestHandler<Params, Result>

ts
type RequestHandler<Params, Result> = (params, token, context) => Promise<Result> | Result;

Defined in: packages/server/src/types.ts:178

Signature for LSP request handlers registered via LSPServer.onRequest.

Type Parameters

Type ParameterDefault typeDescription
ParamsunknownThe request params type, inferred from the method name.
ResultunknownThe response result type, inferred from the method name.

Parameters

ParameterType
paramsParams
tokenTransport
contextRequestContext

Returns

Promise<Result> | Result

Remarks

Handlers are async by default — returning Promise<Result> is fine. Throw a ResponseError to send a structured JSON-RPC error response. Throw any other Error to send a generic -32603 InternalError response.

Check token.isCancellationRequested at async yield points to stop early when the client sends $/cancelRequest.

Never

NEVER call server.close() or server.shutdown() from inside a handler — the server is processing messages on the transport at that point, and closing the transport from within a handler causes a deadlock: the handler awaits the close, but the close waits for all handlers to finish.

NEVER mutate server capabilities inside a handler. Capabilities are negotiated once during initialize; changing them at runtime has no effect on the client, which cached the InitializeResult at startup.

Throws

ResponseError A structured JSON-RPC error (preferred for protocol errors).

Throws

Error Any Error subclass is converted to a -32603 InternalError response.

See

Released under the MIT License.