@lspeasy/core 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +44 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -1
- package/dist/index.js.map +1 -1
- package/dist/jsonrpc/framing.d.ts +28 -3
- package/dist/jsonrpc/framing.d.ts.map +1 -1
- package/dist/jsonrpc/framing.js +28 -3
- package/dist/jsonrpc/framing.js.map +1 -1
- package/dist/jsonrpc/messages.d.ts +105 -8
- package/dist/jsonrpc/messages.d.ts.map +1 -1
- package/dist/jsonrpc/messages.js +36 -0
- package/dist/jsonrpc/messages.js.map +1 -1
- package/dist/jsonrpc/reader.js.map +1 -1
- package/dist/jsonrpc/writer.js.map +1 -1
- package/dist/middleware/compose.d.ts +22 -0
- package/dist/middleware/compose.d.ts.map +1 -1
- package/dist/middleware/compose.js +22 -0
- package/dist/middleware/compose.js.map +1 -1
- package/dist/middleware/pipeline.d.ts +22 -0
- package/dist/middleware/pipeline.d.ts.map +1 -1
- package/dist/middleware/pipeline.js +22 -0
- package/dist/middleware/pipeline.js.map +1 -1
- package/dist/middleware/scoped.d.ts +28 -0
- package/dist/middleware/scoped.d.ts.map +1 -1
- package/dist/middleware/scoped.js +28 -0
- package/dist/middleware/scoped.js.map +1 -1
- package/dist/middleware/typed.d.ts +30 -0
- package/dist/middleware/typed.d.ts.map +1 -1
- package/dist/middleware/typed.js +30 -0
- package/dist/middleware/typed.js.map +1 -1
- package/dist/middleware/types.d.ts +173 -0
- package/dist/middleware/types.d.ts.map +1 -1
- package/dist/protocol/capabilities.d.ts +78 -12
- package/dist/protocol/capabilities.d.ts.map +1 -1
- package/dist/protocol/capabilities.js +78 -12
- package/dist/protocol/capabilities.js.map +1 -1
- package/dist/protocol/capability-methods.d.ts +70 -2
- package/dist/protocol/capability-methods.d.ts.map +1 -1
- package/dist/protocol/capability-methods.js +8 -0
- package/dist/protocol/capability-methods.js.map +1 -1
- package/dist/protocol/dynamic-registration.d.ts +34 -2
- package/dist/protocol/dynamic-registration.d.ts.map +1 -1
- package/dist/protocol/dynamic-registration.js +16 -2
- package/dist/protocol/dynamic-registration.js.map +1 -1
- package/dist/protocol/enums.js +40 -80
- package/dist/protocol/enums.js.map +1 -1
- package/dist/protocol/infer.d.ts +92 -4
- package/dist/protocol/infer.d.ts.map +1 -1
- package/dist/protocol/infer.js +46 -4
- package/dist/protocol/infer.js.map +1 -1
- package/dist/protocol/namespaces.d.ts +327 -327
- package/dist/protocol/namespaces.d.ts.map +1 -1
- package/dist/protocol/partial-results.d.ts +6 -0
- package/dist/protocol/partial-results.d.ts.map +1 -1
- package/dist/protocol/partial.d.ts +12 -3
- package/dist/protocol/partial.d.ts.map +1 -1
- package/dist/protocol/partial.js +12 -3
- package/dist/protocol/partial.js.map +1 -1
- package/dist/protocol/progress.d.ts +34 -4
- package/dist/protocol/progress.d.ts.map +1 -1
- package/dist/protocol/progress.js +34 -4
- package/dist/protocol/progress.js.map +1 -1
- package/dist/protocol/schemas.d.ts +4 -1
- package/dist/protocol/schemas.d.ts.map +1 -1
- package/dist/protocol/schemas.js +4 -1
- package/dist/protocol/schemas.js.map +1 -1
- package/dist/protocol/watching.d.ts +18 -7
- package/dist/protocol/watching.d.ts.map +1 -1
- package/dist/protocol/watching.js +14 -3
- package/dist/protocol/watching.js.map +1 -1
- package/dist/protocol/workspace.d.ts +10 -2
- package/dist/protocol/workspace.d.ts.map +1 -1
- package/dist/protocol/workspace.js +10 -2
- package/dist/protocol/workspace.js.map +1 -1
- package/dist/transport/dedicated-worker.js.map +1 -1
- package/dist/transport/events.js.map +1 -1
- package/dist/transport/ipc.js.map +1 -1
- package/dist/transport/shared-worker.js.map +1 -1
- package/dist/transport/stdio.js.map +1 -1
- package/dist/transport/tcp.js.map +1 -1
- package/dist/transport/transport.d.ts +91 -10
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/transport/websocket.d.ts +120 -19
- package/dist/transport/websocket.d.ts.map +1 -1
- package/dist/transport/websocket.js +95 -8
- package/dist/transport/websocket.js.map +1 -1
- package/dist/transport/worker-types.d.ts +16 -2
- package/dist/transport/worker-types.d.ts.map +1 -1
- package/dist/transport/worker-types.js +12 -2
- package/dist/transport/worker-types.js.map +1 -1
- package/dist/utils/cancellation.d.ts +75 -5
- package/dist/utils/cancellation.d.ts.map +1 -1
- package/dist/utils/cancellation.js +29 -1
- package/dist/utils/cancellation.js.map +1 -1
- package/dist/utils/capability-guard.d.ts +32 -1
- package/dist/utils/capability-guard.d.ts.map +1 -1
- package/dist/utils/capability-guard.js +32 -1
- package/dist/utils/capability-guard.js.map +1 -1
- package/dist/utils/disposable-event-emitter.d.ts +11 -0
- package/dist/utils/disposable-event-emitter.d.ts.map +1 -1
- package/dist/utils/disposable-event-emitter.js +11 -0
- package/dist/utils/disposable-event-emitter.js.map +1 -1
- package/dist/utils/disposable.d.ts +42 -3
- package/dist/utils/disposable.d.ts.map +1 -1
- package/dist/utils/disposable.js +34 -2
- package/dist/utils/disposable.js.map +1 -1
- package/dist/utils/document.d.ts +78 -3
- package/dist/utils/document.d.ts.map +1 -1
- package/dist/utils/document.js +73 -3
- package/dist/utils/document.js.map +1 -1
- package/dist/utils/errors.d.ts +87 -10
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +87 -10
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/handler-registry.js.map +1 -1
- package/dist/utils/logger.d.ts +79 -4
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +64 -5
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/pending-request-tracker.d.ts.map +1 -1
- package/dist/utils/pending-request-tracker.js.map +1 -1
- package/dist/utils/transport-attachment.js.map +1 -1
- package/package.json +5 -6
|
@@ -27,6 +27,28 @@ function shouldRun(registration, context) {
|
|
|
27
27
|
messageType: context.messageType
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Runs the registered middleware chain for a single JSON-RPC message, then
|
|
32
|
+
* calls `finalHandler` if no middleware short-circuits.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* This is the core dispatch loop used by `LSPClient` and `LSPServer`. Each
|
|
36
|
+
* middleware receives `context` and a `next` callback; calling `next()` hands
|
|
37
|
+
* control to the following middleware. If a middleware returns a result with
|
|
38
|
+
* `shortCircuit: true` the remaining middleware and `finalHandler` are skipped.
|
|
39
|
+
*
|
|
40
|
+
* Scoped middleware (created with `createScopedMiddleware`) is automatically
|
|
41
|
+
* filtered: it only executes when `matchesFilter` returns `true` for the
|
|
42
|
+
* current message.
|
|
43
|
+
*
|
|
44
|
+
* @param registrations - The list of middleware or scoped-middleware to run.
|
|
45
|
+
* @param context - The shared context for the current message.
|
|
46
|
+
* @param finalHandler - The handler to call after all middleware have run.
|
|
47
|
+
* @returns The result of the first short-circuiting middleware, or the result
|
|
48
|
+
* of `finalHandler`.
|
|
49
|
+
*
|
|
50
|
+
* @category Middleware
|
|
51
|
+
*/
|
|
30
52
|
export async function executeMiddlewarePipeline(registrations, context, finalHandler) {
|
|
31
53
|
const entries = registrations ?? [];
|
|
32
54
|
if (entries.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/middleware/pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIhE,SAAS,YAAY,CAAC,OAAqC
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/middleware/pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIhE,SAAS,YAAY,CAAC,OAAqC;IACzD,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;QACpB,OAAO,OAAO,CAAC,EAAE,CAAC;IACpB,CAAC;IACD,OAAO,SAAS,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AAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,CAAC;YACvD,OAAO,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC7B,CAAC;QAED,MAAM,UAAU,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;QAC/C,MAAM,eAAe,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QACpE,wBAAwB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAEnD,IAAI,MAAM,EAAE,YAAY,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
import type { MethodFilter, Middleware, MiddlewareMessageType, ScopedMiddleware } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a middleware with a filter so it only runs for matching LSP messages.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Prefer this over putting an `if (context.method === '...')` guard inside
|
|
7
|
+
* your middleware — scoped middleware is skipped before the function is even
|
|
8
|
+
* called, which keeps the pipeline overhead low.
|
|
9
|
+
*
|
|
10
|
+
* @param filter - A {@link MethodFilter} describing which messages to intercept.
|
|
11
|
+
* @param middleware - The middleware function to run when the filter matches.
|
|
12
|
+
* @returns A {@link ScopedMiddleware} object ready to pass to `ServerOptions.middleware`
|
|
13
|
+
* or `ClientOptions.middleware`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { createScopedMiddleware } from '@lspeasy/core';
|
|
18
|
+
*
|
|
19
|
+
* const hoverLogger = createScopedMiddleware(
|
|
20
|
+
* { methods: ['textDocument/hover'], direction: 'clientToServer' },
|
|
21
|
+
* async (ctx, next) => {
|
|
22
|
+
* console.log('hover params:', ctx.message);
|
|
23
|
+
* return next();
|
|
24
|
+
* }
|
|
25
|
+
* );
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @category Middleware
|
|
29
|
+
*/
|
|
2
30
|
export declare function createScopedMiddleware(filter: MethodFilter, middleware: Middleware): ScopedMiddleware;
|
|
3
31
|
export declare function isScopedMiddleware(value: Middleware | ScopedMiddleware): value is ScopedMiddleware;
|
|
4
32
|
export declare function matchesFilter(filter: MethodFilter, context: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped.d.ts","sourceRoot":"","sources":["../../src/middleware/scoped.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpG,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,gBAAgB,CAElB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,UAAU,GAAG,gBAAgB,GACnC,KAAK,IAAI,gBAAgB,CAE3B;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IAC/C,WAAW,EAAE,qBAAqB,CAAC;CACpC,GACA,OAAO,CAeT"}
|
|
1
|
+
{"version":3,"file":"scoped.d.ts","sourceRoot":"","sources":["../../src/middleware/scoped.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,gBAAgB,CAElB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,UAAU,GAAG,gBAAgB,GACnC,KAAK,IAAI,gBAAgB,CAE3B;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IAC/C,WAAW,EAAE,qBAAqB,CAAC;CACpC,GACA,OAAO,CAeT"}
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a middleware with a filter so it only runs for matching LSP messages.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Prefer this over putting an `if (context.method === '...')` guard inside
|
|
6
|
+
* your middleware — scoped middleware is skipped before the function is even
|
|
7
|
+
* called, which keeps the pipeline overhead low.
|
|
8
|
+
*
|
|
9
|
+
* @param filter - A {@link MethodFilter} describing which messages to intercept.
|
|
10
|
+
* @param middleware - The middleware function to run when the filter matches.
|
|
11
|
+
* @returns A {@link ScopedMiddleware} object ready to pass to `ServerOptions.middleware`
|
|
12
|
+
* or `ClientOptions.middleware`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { createScopedMiddleware } from '@lspeasy/core';
|
|
17
|
+
*
|
|
18
|
+
* const hoverLogger = createScopedMiddleware(
|
|
19
|
+
* { methods: ['textDocument/hover'], direction: 'clientToServer' },
|
|
20
|
+
* async (ctx, next) => {
|
|
21
|
+
* console.log('hover params:', ctx.message);
|
|
22
|
+
* return next();
|
|
23
|
+
* }
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @category Middleware
|
|
28
|
+
*/
|
|
1
29
|
export function createScopedMiddleware(filter, middleware) {
|
|
2
30
|
return { filter, middleware };
|
|
3
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped.js","sourceRoot":"","sources":["../../src/middleware/scoped.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,sBAAsB,CACpC,MAAoB,EACpB,UAAsB
|
|
1
|
+
{"version":3,"file":"scoped.js","sourceRoot":"","sources":["../../src/middleware/scoped.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAAoB,EACpB,UAAsB;IAEtB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,KAAoC;IAEpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,YAAY,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,MAAoB,EACpB,OAIC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC;IAC7C,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -1,3 +1,33 @@
|
|
|
1
1
|
import type { LSPMethod, ScopedMiddleware, TypedMiddleware } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed, method-scoped middleware with full TypeScript inference for
|
|
4
|
+
* the message params and result.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* `createTypedMiddleware` is the ergonomic alternative to `createScopedMiddleware`
|
|
8
|
+
* when you want both method filtering and typed access to `context.params` and
|
|
9
|
+
* `context.result`. The method literal is used at the type level to narrow the
|
|
10
|
+
* context object, so no casting is required inside the middleware body.
|
|
11
|
+
*
|
|
12
|
+
* @param method - The exact LSP method string to intercept (e.g. `'textDocument/hover'`).
|
|
13
|
+
* @param middleware - The typed middleware function to run for that method.
|
|
14
|
+
* @returns A {@link ScopedMiddleware} filtered to the given method.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createTypedMiddleware } from '@lspeasy/core';
|
|
19
|
+
*
|
|
20
|
+
* const hoverMiddleware = createTypedMiddleware(
|
|
21
|
+
* 'textDocument/hover',
|
|
22
|
+
* async (ctx, next) => {
|
|
23
|
+
* // ctx.params is typed as HoverParams
|
|
24
|
+
* console.log('hover at', ctx.params.position);
|
|
25
|
+
* return next();
|
|
26
|
+
* }
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @category Middleware
|
|
31
|
+
*/
|
|
2
32
|
export declare function createTypedMiddleware<M extends LSPMethod>(method: M, middleware: TypedMiddleware<M>): ScopedMiddleware;
|
|
3
33
|
//# sourceMappingURL=typed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed.d.ts","sourceRoot":"","sources":["../../src/middleware/typed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,eAAe,EAIhB,MAAM,YAAY,CAAC;AAGpB,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,SAAS,EACvD,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAC7B,gBAAgB,CAkBlB"}
|
|
1
|
+
{"version":3,"file":"typed.d.ts","sourceRoot":"","sources":["../../src/middleware/typed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,eAAe,EAIhB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,SAAS,EACvD,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAC7B,gBAAgB,CAkBlB"}
|
package/dist/middleware/typed.js
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
import { createScopedMiddleware } from './scoped.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed, method-scoped middleware with full TypeScript inference for
|
|
4
|
+
* the message params and result.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* `createTypedMiddleware` is the ergonomic alternative to `createScopedMiddleware`
|
|
8
|
+
* when you want both method filtering and typed access to `context.params` and
|
|
9
|
+
* `context.result`. The method literal is used at the type level to narrow the
|
|
10
|
+
* context object, so no casting is required inside the middleware body.
|
|
11
|
+
*
|
|
12
|
+
* @param method - The exact LSP method string to intercept (e.g. `'textDocument/hover'`).
|
|
13
|
+
* @param middleware - The typed middleware function to run for that method.
|
|
14
|
+
* @returns A {@link ScopedMiddleware} filtered to the given method.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createTypedMiddleware } from '@lspeasy/core';
|
|
19
|
+
*
|
|
20
|
+
* const hoverMiddleware = createTypedMiddleware(
|
|
21
|
+
* 'textDocument/hover',
|
|
22
|
+
* async (ctx, next) => {
|
|
23
|
+
* // ctx.params is typed as HoverParams
|
|
24
|
+
* console.log('hover at', ctx.params.position);
|
|
25
|
+
* return next();
|
|
26
|
+
* }
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @category Middleware
|
|
31
|
+
*/
|
|
2
32
|
export function createTypedMiddleware(method, middleware) {
|
|
3
33
|
return createScopedMiddleware({ methods: [method] }, async (context, next) => {
|
|
4
34
|
const typedContextBase = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed.js","sourceRoot":"","sources":["../../src/middleware/typed.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,UAAU,qBAAqB,CACnC,MAAS,EACT,UAA8B
|
|
1
|
+
{"version":3,"file":"typed.js","sourceRoot":"","sources":["../../src/middleware/typed.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAS,EACT,UAA8B;IAE9B,OAAO,sBAAsB,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC3E,MAAM,gBAAgB,GAAG;YACvB,GAAG,OAAO;YACV,MAAM;YACN,MAAM,EAAE,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAmB;SAC7F,CAAC;QAEF,MAAM,YAAY,GAChB,QAAQ,IAAI,OAAO,CAAC,OAAO;YACzB,CAAC,CAAC;gBACE,GAAG,gBAAgB;gBACnB,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,MAAwB;aACjD;YACH,CAAC,CAAC,gBAAgB,CAAC;QAEvB,OAAO,UAAU,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,44 +1,217 @@
|
|
|
1
1
|
import type { ErrorResponseMessage, Message, NotificationMessage, RequestMessage, ResponseMessage } from '../jsonrpc/messages.js';
|
|
2
2
|
import type { LSPNotificationMethod, LSPRequestMethod, ParamsForNotification, ParamsForRequest, ResultForRequest } from '../protocol/infer.js';
|
|
3
|
+
/**
|
|
4
|
+
* Direction of a JSON-RPC message in the middleware pipeline.
|
|
5
|
+
*
|
|
6
|
+
* @category Middleware
|
|
7
|
+
*/
|
|
3
8
|
export type MiddlewareDirection = 'clientToServer' | 'serverToClient';
|
|
9
|
+
/**
|
|
10
|
+
* Kind of JSON-RPC message flowing through middleware.
|
|
11
|
+
*
|
|
12
|
+
* @category Middleware
|
|
13
|
+
*/
|
|
4
14
|
export type MiddlewareMessageType = 'request' | 'response' | 'notification' | 'error';
|
|
5
15
|
type ImmutableId<T> = T extends {
|
|
6
16
|
id: infer I;
|
|
7
17
|
} ? Omit<T, 'id'> & {
|
|
8
18
|
readonly id: I;
|
|
9
19
|
} : T;
|
|
20
|
+
/**
|
|
21
|
+
* The JSON-RPC message exposed to middleware, with `id` made read-only to
|
|
22
|
+
* prevent accidental mutation that would break response correlation.
|
|
23
|
+
*
|
|
24
|
+
* @category Middleware
|
|
25
|
+
*/
|
|
10
26
|
export type MiddlewareMessage = ImmutableId<Message>;
|
|
27
|
+
/**
|
|
28
|
+
* Execution context passed to every middleware function in the pipeline.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* `metadata` is a mutable bag-of-properties that middleware can use to pass
|
|
32
|
+
* data to downstream middleware or to the final handler. It is scoped to a
|
|
33
|
+
* single message and discarded after the pipeline completes.
|
|
34
|
+
*
|
|
35
|
+
* @category Middleware
|
|
36
|
+
*/
|
|
11
37
|
export interface MiddlewareContext {
|
|
38
|
+
/** Whether this message travels from client-to-server or server-to-client. */
|
|
12
39
|
direction: MiddlewareDirection;
|
|
40
|
+
/** The kind of JSON-RPC message. */
|
|
13
41
|
messageType: MiddlewareMessageType;
|
|
42
|
+
/** The LSP method string, e.g. `'textDocument/hover'`. */
|
|
14
43
|
method: string;
|
|
44
|
+
/** The raw JSON-RPC message (id is read-only). */
|
|
15
45
|
message: MiddlewareMessage;
|
|
46
|
+
/** Arbitrary key-value pairs for cross-middleware communication. */
|
|
16
47
|
metadata: Record<string, unknown>;
|
|
48
|
+
/** Constructor name of the active transport, e.g. `'StdioTransport'`. */
|
|
17
49
|
transport: string;
|
|
18
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Union of all LSP request and notification method strings.
|
|
53
|
+
*
|
|
54
|
+
* @category Middleware
|
|
55
|
+
*/
|
|
19
56
|
export type LSPMethod = LSPRequestMethod | LSPNotificationMethod;
|
|
57
|
+
/**
|
|
58
|
+
* Infers the params type for a given LSP method.
|
|
59
|
+
*
|
|
60
|
+
* @typeParam M - An LSP request or notification method string.
|
|
61
|
+
* @category Middleware
|
|
62
|
+
*/
|
|
20
63
|
export type TypedParams<M extends LSPMethod> = M extends LSPRequestMethod ? ParamsForRequest<M> : M extends LSPNotificationMethod ? ParamsForNotification<M> : never;
|
|
64
|
+
/**
|
|
65
|
+
* Infers the result type for a given LSP method (void for notifications).
|
|
66
|
+
*
|
|
67
|
+
* @typeParam M - An LSP request or notification method string.
|
|
68
|
+
* @category Middleware
|
|
69
|
+
*/
|
|
21
70
|
export type TypedResult<M extends LSPMethod> = M extends LSPRequestMethod ? ResultForRequest<M> : void;
|
|
71
|
+
/**
|
|
72
|
+
* Typed middleware context narrowed to a specific LSP method.
|
|
73
|
+
* Use with `createTypedMiddleware` for full type inference.
|
|
74
|
+
*
|
|
75
|
+
* @typeParam M - The specific LSP method this middleware handles.
|
|
76
|
+
* @category Middleware
|
|
77
|
+
*/
|
|
22
78
|
export interface TypedMiddlewareContext<M extends LSPMethod> extends MiddlewareContext {
|
|
79
|
+
/** The specific LSP method string this middleware context is scoped to. */
|
|
23
80
|
method: M;
|
|
81
|
+
/** Typed parameters inferred from the LSP method signature. */
|
|
24
82
|
params: TypedParams<M>;
|
|
83
|
+
/** Typed result, populated after `next()` resolves for request middleware. */
|
|
25
84
|
result?: TypedResult<M>;
|
|
26
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The return value from a middleware function.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* Return `undefined` or `void` to continue the pipeline normally.
|
|
91
|
+
* Set `shortCircuit: true` (plus `response` or `error`) to bypass all
|
|
92
|
+
* remaining middleware and the final handler.
|
|
93
|
+
*
|
|
94
|
+
* @never
|
|
95
|
+
* NEVER short-circuit a request without providing a valid `response` or
|
|
96
|
+
* `error` — the pending request will never resolve and the client will time
|
|
97
|
+
* out with no recourse.
|
|
98
|
+
*
|
|
99
|
+
* @category Middleware
|
|
100
|
+
*/
|
|
27
101
|
export interface MiddlewareResult {
|
|
102
|
+
/** When `true`, all remaining middleware and the final handler are bypassed. */
|
|
28
103
|
shortCircuit?: boolean;
|
|
104
|
+
/** The response to return when short-circuiting a request. */
|
|
29
105
|
response?: ResponseMessage | RequestMessage | NotificationMessage;
|
|
106
|
+
/** The error response to return when short-circuiting with a failure. */
|
|
30
107
|
error?: ErrorResponseMessage;
|
|
31
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Calls the next middleware (or final handler) in the pipeline.
|
|
111
|
+
*
|
|
112
|
+
* @category Middleware
|
|
113
|
+
*/
|
|
32
114
|
export type MiddlewareNext = () => Promise<void | MiddlewareResult>;
|
|
115
|
+
/**
|
|
116
|
+
* A function that intercepts JSON-RPC messages flowing through `LSPServer`
|
|
117
|
+
* or `LSPClient`.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* Middleware follows the `async (context, next) => result` pattern familiar
|
|
121
|
+
* from Express / Koa. Call `next()` to continue the pipeline; return a
|
|
122
|
+
* `MiddlewareResult` with `shortCircuit: true` to bypass remaining handlers.
|
|
123
|
+
*
|
|
124
|
+
* @useWhen
|
|
125
|
+
* You need cross-cutting behavior across all (or a subset of) LSP messages:
|
|
126
|
+
* logging, tracing, authentication, rate-limiting, schema validation, or
|
|
127
|
+
* request mocking in tests.
|
|
128
|
+
*
|
|
129
|
+
* @avoidWhen
|
|
130
|
+
* You need to handle only a single method — register a dedicated
|
|
131
|
+
* `onRequest` / `onNotification` handler instead. Middleware adds overhead
|
|
132
|
+
* for every message regardless of method.
|
|
133
|
+
*
|
|
134
|
+
* @never
|
|
135
|
+
* NEVER mutate `context.message.id` — it is read-only by design. Response
|
|
136
|
+
* correlation depends on the ID remaining stable through the pipeline.
|
|
137
|
+
*
|
|
138
|
+
* NEVER `await next()` more than once per middleware invocation. The pipeline
|
|
139
|
+
* is not re-entrant; calling `next()` twice dispatches the underlying handler
|
|
140
|
+
* twice, producing duplicate responses or side effects.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import type { Middleware } from '@lspeasy/core';
|
|
145
|
+
*
|
|
146
|
+
* const timingMiddleware: Middleware = async (context, next) => {
|
|
147
|
+
* const start = Date.now();
|
|
148
|
+
* const result = await next();
|
|
149
|
+
* console.log(`${context.method} took ${Date.now() - start}ms`);
|
|
150
|
+
* return result;
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* const server = new LSPServer({ middleware: [timingMiddleware] });
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @category Middleware
|
|
157
|
+
*/
|
|
33
158
|
export type Middleware = (context: MiddlewareContext, next: MiddlewareNext) => Promise<void | MiddlewareResult>;
|
|
159
|
+
/**
|
|
160
|
+
* A middleware function narrowed to a specific LSP method with full type
|
|
161
|
+
* inference for `params` and `result`.
|
|
162
|
+
*
|
|
163
|
+
* @remarks
|
|
164
|
+
* Create with `createTypedMiddleware` to avoid manual generic parameters.
|
|
165
|
+
*
|
|
166
|
+
* @typeParam M - The LSP method string this middleware is scoped to.
|
|
167
|
+
* @category Middleware
|
|
168
|
+
*/
|
|
34
169
|
export type TypedMiddleware<M extends LSPMethod> = (context: TypedMiddlewareContext<M>, next: MiddlewareNext) => Promise<void | MiddlewareResult>;
|
|
170
|
+
/**
|
|
171
|
+
* Filter predicate used by `ScopedMiddleware` to select which messages
|
|
172
|
+
* a middleware should intercept.
|
|
173
|
+
*
|
|
174
|
+
* @category Middleware
|
|
175
|
+
*/
|
|
35
176
|
export interface MethodFilter {
|
|
177
|
+
/** Method names or a regex to match against `context.method`. */
|
|
36
178
|
methods: string[] | RegExp;
|
|
179
|
+
/** Limit to a specific direction, or `'both'` (default). */
|
|
37
180
|
direction?: MiddlewareDirection | 'both';
|
|
181
|
+
/** Limit to specific message kinds. */
|
|
38
182
|
messageType?: MiddlewareMessageType[];
|
|
39
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* A `Middleware` paired with a `MethodFilter` so it only runs for matching
|
|
186
|
+
* messages.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* Create with `createScopedMiddleware` for a more ergonomic API.
|
|
190
|
+
*
|
|
191
|
+
* @useWhen
|
|
192
|
+
* You want a middleware that only fires for a specific method (e.g. only
|
|
193
|
+
* `textDocument/completion`) without writing the guard inside the middleware
|
|
194
|
+
* body itself.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { createScopedMiddleware } from '@lspeasy/core';
|
|
199
|
+
*
|
|
200
|
+
* const completionLogger = createScopedMiddleware(
|
|
201
|
+
* { methods: ['textDocument/completion'], direction: 'clientToServer' },
|
|
202
|
+
* async (ctx, next) => {
|
|
203
|
+
* console.log('completion request params:', ctx.message);
|
|
204
|
+
* return next();
|
|
205
|
+
* }
|
|
206
|
+
* );
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @category Middleware
|
|
210
|
+
*/
|
|
40
211
|
export interface ScopedMiddleware {
|
|
212
|
+
/** The filter predicate that determines which messages this middleware intercepts. */
|
|
41
213
|
filter: MethodFilter;
|
|
214
|
+
/** The middleware function to execute when the filter matches. */
|
|
42
215
|
middleware: Middleware;
|
|
43
216
|
}
|
|
44
217
|
export {};
|
|
@@ -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C;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,iEAAiE;IACjE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC3B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;IACzC,uCAAuC;IACvC,WAAW,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sFAAsF;IACtF,MAAM,EAAE,YAAY,CAAC;IACrB,kEAAkE;IAClE,UAAU,EAAE,UAAU,CAAC;CACxB"}
|
|
@@ -15,55 +15,109 @@ export type { ServerCapabilities, ClientCapabilities };
|
|
|
15
15
|
* Get the capability key for a given method at runtime
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Type-guarding predicate that narrows `capabilities` to include the specific
|
|
19
|
+
* server capability key required for the given client-to-server request method.
|
|
20
|
+
*
|
|
21
|
+
* @param method - The LSP request method string (e.g. `'textDocument/hover'`).
|
|
22
|
+
* @param capabilities - The `ServerCapabilities` object to test.
|
|
23
|
+
* @returns `true` when the server has declared support for the method.
|
|
19
24
|
*/
|
|
20
25
|
export declare function serverSupportsRequest<M extends LSPRequestMethod<'clientToServer'>>(method: M, capabilities: ServerCapabilities): capabilities is ServerCapabilities & PickDeep<ServerCapabilities, ServerCapabilityForRequest<M>>;
|
|
26
|
+
/**
|
|
27
|
+
* Type-guarding predicate that narrows `capabilities` to include the specific
|
|
28
|
+
* server capability key required for the given client-to-server notification method.
|
|
29
|
+
*
|
|
30
|
+
* @param method - The LSP notification method string (e.g. `'textDocument/didOpen'`).
|
|
31
|
+
* @param capabilities - The `ServerCapabilities` object to test.
|
|
32
|
+
* @returns `true` when the server has declared support for the method.
|
|
33
|
+
*/
|
|
21
34
|
export declare function serverSupportsNotification<M extends LSPNotificationMethod<'clientToServer'>, T extends Partial<ServerCapabilities>>(method: M, capabilities: T): capabilities is T & PickDeep<ServerCapabilities, ServerCapabilityForNotification<M>>;
|
|
22
35
|
/**
|
|
23
|
-
*
|
|
36
|
+
* Type-guarding predicate that narrows `capabilities` to include the specific
|
|
37
|
+
* client capability key required for the given server-to-client request method.
|
|
38
|
+
*
|
|
39
|
+
* @param method - The LSP request method string (e.g. `'client/registerCapability'`).
|
|
40
|
+
* @param capabilities - The `ClientCapabilities` object to test.
|
|
41
|
+
* @returns `true` when the client has declared support for the method.
|
|
24
42
|
*/
|
|
25
43
|
export declare function clientSupportsRequest<M extends LSPRequestMethod<'serverToClient'>, T extends Partial<ClientCapabilities>>(method: M, capabilities: T): capabilities is T & PickDeep<ClientCapabilities, ClientCapabilityForRequest<M>>;
|
|
44
|
+
/**
|
|
45
|
+
* Type-guarding predicate that narrows `capabilities` to include the specific
|
|
46
|
+
* client capability key required for the given server-to-client notification method.
|
|
47
|
+
*
|
|
48
|
+
* @param method - The LSP notification method string (e.g. `'window/logMessage'`).
|
|
49
|
+
* @param capabilities - The `ClientCapabilities` object to test.
|
|
50
|
+
* @returns `true` when the client has declared support for the method.
|
|
51
|
+
*/
|
|
26
52
|
export declare function clientSupportsNotification<M extends LSPNotificationMethod<'serverToClient'>, T extends Partial<ClientCapabilities>>(method: M, capabilities: T): capabilities is T & PickDeep<ClientCapabilities, ClientCapabilityForNotification<M>>;
|
|
27
53
|
/**
|
|
28
|
-
*
|
|
54
|
+
* Type-guarding predicate that narrows `capabilities` to confirm a specific server capability
|
|
55
|
+
* is enabled at a deep dot-notation path.
|
|
56
|
+
*
|
|
57
|
+
* @param capabilities - The server capabilities to check.
|
|
58
|
+
* @param capability - Dot-notation path of the capability (e.g. `'hoverProvider'`).
|
|
59
|
+
* @returns `true` when the capability at the given path is truthy.
|
|
29
60
|
*/
|
|
30
61
|
export declare function hasServerCapability<K extends Paths<ServerCapabilities>, T extends Partial<ServerCapabilities>>(capabilities: T, capability: K): capabilities is T & PickDeep<ServerCapabilities, K>;
|
|
31
62
|
/**
|
|
32
|
-
*
|
|
63
|
+
* Type-guarding predicate that narrows `capabilities` to confirm a specific client capability
|
|
64
|
+
* is enabled at a deep dot-notation path.
|
|
65
|
+
*
|
|
66
|
+
* @param capabilities - The client capabilities to check.
|
|
67
|
+
* @param capability - Dot-notation path of the capability (e.g. `'window.workDoneProgress'`).
|
|
68
|
+
* @returns `true` when the capability at the given path is truthy.
|
|
33
69
|
*/
|
|
34
70
|
export declare function hasClientCapability<K extends Paths<ClientCapabilities>, T extends Partial<ClientCapabilities>>(capabilities: T, capability: K): capabilities is T & PickDeep<ClientCapabilities, K>;
|
|
35
71
|
/**
|
|
36
|
-
*
|
|
72
|
+
* Returns `true` when `hoverProvider` is declared in the server capabilities.
|
|
73
|
+
*
|
|
74
|
+
* @param capabilities - The server capabilities to check.
|
|
75
|
+
* @returns `true` when hover is supported.
|
|
37
76
|
*/
|
|
38
77
|
export declare function supportsHover(capabilities: ServerCapabilities): capabilities is ServerCapabilities & {
|
|
39
78
|
hoverProvider: NonNullable<ServerCapabilities['hoverProvider']>;
|
|
40
79
|
};
|
|
41
80
|
/**
|
|
42
|
-
*
|
|
81
|
+
* Returns `true` when `completionProvider` is declared in the server capabilities.
|
|
82
|
+
*
|
|
83
|
+
* @param capabilities - The server capabilities to check.
|
|
84
|
+
* @returns `true` when completion is supported.
|
|
43
85
|
*/
|
|
44
86
|
export declare function supportsCompletion(capabilities: ServerCapabilities): capabilities is ServerCapabilities & {
|
|
45
87
|
completionProvider: NonNullable<ServerCapabilities['completionProvider']>;
|
|
46
88
|
};
|
|
47
89
|
/**
|
|
48
|
-
*
|
|
90
|
+
* Returns `true` when `definitionProvider` is declared in the server capabilities.
|
|
91
|
+
*
|
|
92
|
+
* @param capabilities - The server capabilities to check.
|
|
93
|
+
* @returns `true` when go-to-definition is supported.
|
|
49
94
|
*/
|
|
50
95
|
export declare function supportsDefinition(capabilities: ServerCapabilities): capabilities is ServerCapabilities & {
|
|
51
96
|
definitionProvider: NonNullable<ServerCapabilities['definitionProvider']>;
|
|
52
97
|
};
|
|
53
98
|
/**
|
|
54
|
-
*
|
|
99
|
+
* Returns `true` when `referencesProvider` is declared in the server capabilities.
|
|
100
|
+
*
|
|
101
|
+
* @param capabilities - The server capabilities to check.
|
|
102
|
+
* @returns `true` when find-references is supported.
|
|
55
103
|
*/
|
|
56
104
|
export declare function supportsReferences(capabilities: ServerCapabilities): capabilities is ServerCapabilities & {
|
|
57
105
|
referencesProvider: NonNullable<ServerCapabilities['referencesProvider']>;
|
|
58
106
|
};
|
|
59
107
|
/**
|
|
60
|
-
*
|
|
108
|
+
* Returns `true` when `documentSymbolProvider` is declared in the server capabilities.
|
|
109
|
+
*
|
|
110
|
+
* @param capabilities - The server capabilities to check.
|
|
111
|
+
* @returns `true` when document symbols are supported.
|
|
61
112
|
*/
|
|
62
113
|
export declare function supportsDocumentSymbol(capabilities: ServerCapabilities): capabilities is ServerCapabilities & {
|
|
63
114
|
documentSymbolProvider: NonNullable<ServerCapabilities['documentSymbolProvider']>;
|
|
64
115
|
};
|
|
65
116
|
/**
|
|
66
|
-
*
|
|
117
|
+
* Returns `true` when the server supports workspace folders.
|
|
118
|
+
*
|
|
119
|
+
* @param capabilities - The server capabilities to check.
|
|
120
|
+
* @returns `true` when `workspace.workspaceFolders.supported` is `true`.
|
|
67
121
|
*/
|
|
68
122
|
export declare function supportsWorkspaceFolders(capabilities: ServerCapabilities): capabilities is ServerCapabilities & {
|
|
69
123
|
workspace: {
|
|
@@ -72,11 +126,20 @@ export declare function supportsWorkspaceFolders(capabilities: ServerCapabilitie
|
|
|
72
126
|
};
|
|
73
127
|
};
|
|
74
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Helper to check if notebook document sync is supported by the server.
|
|
131
|
+
*
|
|
132
|
+
* @param capabilities - The server capabilities to check.
|
|
133
|
+
* @returns `true` when `notebookDocumentSync` is declared (not null/undefined).
|
|
134
|
+
*/
|
|
75
135
|
export declare function supportsNotebookDocumentSync(capabilities: ServerCapabilities): capabilities is ServerCapabilities & {
|
|
76
136
|
notebookDocumentSync: NonNullable<ServerCapabilities['notebookDocumentSync']>;
|
|
77
137
|
};
|
|
78
138
|
/**
|
|
79
|
-
*
|
|
139
|
+
* Returns `true` when the client supports dynamic file watching registration.
|
|
140
|
+
*
|
|
141
|
+
* @param capabilities - The client capabilities to check.
|
|
142
|
+
* @returns `true` when `workspace.didChangeWatchedFiles.dynamicRegistration` is `true`.
|
|
80
143
|
*/
|
|
81
144
|
export declare function supportsFileWatching(capabilities: ClientCapabilities): capabilities is ClientCapabilities & {
|
|
82
145
|
workspace: {
|
|
@@ -86,7 +149,10 @@ export declare function supportsFileWatching(capabilities: ClientCapabilities):
|
|
|
86
149
|
};
|
|
87
150
|
};
|
|
88
151
|
/**
|
|
89
|
-
*
|
|
152
|
+
* Returns `true` when the client supports work done progress notifications.
|
|
153
|
+
*
|
|
154
|
+
* @param capabilities - The client capabilities to check.
|
|
155
|
+
* @returns `true` when `window.workDoneProgress` is `true`.
|
|
90
156
|
*/
|
|
91
157
|
export declare function supportsWorkDoneProgress(capabilities: ClientCapabilities): capabilities is ClientCapabilities & {
|
|
92
158
|
window: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/protocol/capabilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAC7F,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAKL,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAChC,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,CAAC;AAoCvD;;;GAGG;AAEH;;GAEG;AAEH
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