Skip to content

lspeasy / core/src / ScopedMiddleware

Interface: ScopedMiddleware

Defined in: packages/core/src/middleware/types.ts:246

A Middleware paired with a MethodFilter so it only runs for matching messages.

Remarks

Create with createScopedMiddleware for a more ergonomic API.

Use When

You want a middleware that only fires for a specific method (e.g. only textDocument/completion) without writing the guard inside the middleware body itself.

Example

ts
import { createScopedMiddleware } from '@lspeasy/core';

const completionLogger = createScopedMiddleware(
  { methods: ['textDocument/completion'], direction: 'clientToServer' },
  async (ctx, next) => {
    console.log('completion request params:', ctx.message);
    return next();
  }
);

Properties

PropertyTypeDescriptionDefined in
filterMethodFilterThe filter predicate that determines which messages this middleware intercepts.packages/core/src/middleware/types.ts:248
middlewareMiddlewareThe middleware function to execute when the filter matches.packages/core/src/middleware/types.ts:250

Released under the MIT License.