@lspeasy/client 3.0.1 → 3.0.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/capability-guard.d.ts +67 -21
- package/dist/capability-guard.d.ts.map +1 -1
- package/dist/capability-guard.js +101 -176
- package/dist/capability-guard.js.map +1 -1
- package/dist/capability-proxy.js.map +1 -1
- package/dist/client.d.ts +215 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +162 -14
- package/dist/client.js.map +1 -1
- package/dist/connection/health.d.ts +40 -0
- package/dist/connection/health.d.ts.map +1 -1
- package/dist/connection/health.js +40 -0
- package/dist/connection/health.js.map +1 -1
- package/dist/connection/heartbeat.d.ts +29 -0
- package/dist/connection/heartbeat.d.ts.map +1 -1
- package/dist/connection/heartbeat.js +29 -0
- package/dist/connection/heartbeat.js.map +1 -1
- package/dist/connection/partial-result-collector.js.map +1 -1
- package/dist/connection/registration-store.js.map +1 -1
- package/dist/connection/types.d.ts +46 -4
- package/dist/connection/types.d.ts.map +1 -1
- package/dist/connection/types.js +11 -3
- package/dist/connection/types.js.map +1 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/dist/notifications/wait.d.ts +57 -2
- package/dist/notifications/wait.d.ts.map +1 -1
- package/dist/notifications/wait.js +44 -1
- package/dist/notifications/wait.js.map +1 -1
- package/dist/progress.js.map +1 -1
- package/dist/types.d.ts +51 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js.map +1 -1
- package/package.json +6 -7
|
@@ -7,15 +7,47 @@ type HealthEventMap = {
|
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Tracks connection state transitions and message activity timestamps.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* `ConnectionHealthTracker` is created internally by `LSPClient` and exposed
|
|
13
|
+
* via `client.connectionHealth`. Subscribe to `stateChanged` and
|
|
14
|
+
* `healthChanged` events to react to disconnections or transport failures.
|
|
15
|
+
*
|
|
16
|
+
* @useWhen
|
|
17
|
+
* You need to monitor connection liveness — for example, to show a status
|
|
18
|
+
* indicator, trigger reconnection logic, or surface transport errors to users.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link HeartbeatMonitor} for detecting silent transport failures with
|
|
21
|
+
* periodic ping/pong checks.
|
|
22
|
+
*
|
|
23
|
+
* @never
|
|
24
|
+
* NEVER mutate the object returned by `getHealth()` — it is a defensive copy
|
|
25
|
+
* but consumers that store a reference and then modify it will see stale state.
|
|
26
|
+
*
|
|
27
|
+
* NEVER call `setState` from outside `LSPClient` internals. External callers
|
|
28
|
+
* have no knowledge of the full state-transition graph; setting state directly
|
|
29
|
+
* can desync the client's internal bookkeeping from the tracker's reported state.
|
|
30
|
+
*
|
|
31
|
+
* @category Client
|
|
10
32
|
*/
|
|
11
33
|
export declare class ConnectionHealthTracker extends DisposableEventEmitter<HealthEventMap> {
|
|
12
34
|
private health;
|
|
13
35
|
/**
|
|
14
36
|
* Returns a defensive copy of the current health snapshot.
|
|
37
|
+
*
|
|
38
|
+
* @returns A shallow copy of the current {@link ConnectionHealth} object,
|
|
39
|
+
* including a nested copy of `heartbeat` when present.
|
|
15
40
|
*/
|
|
16
41
|
getHealth(): ConnectionHealth;
|
|
17
42
|
/**
|
|
18
43
|
* Updates connection state and emits state/health change events.
|
|
44
|
+
*
|
|
45
|
+
* @param next - The new {@link ConnectionState} to transition to.
|
|
46
|
+
* @param reason - Optional human-readable reason for the state transition
|
|
47
|
+
* (e.g. `'Transport error'`). Included in the emitted `StateChangeEvent`.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link ConnectionState} for valid state values.
|
|
50
|
+
* @see {@link ConnectionHealthTracker} for the full class contract.
|
|
19
51
|
*/
|
|
20
52
|
setState(next: ConnectionState, reason?: string): void;
|
|
21
53
|
/**
|
|
@@ -32,10 +64,18 @@ export declare class ConnectionHealthTracker extends DisposableEventEmitter<Heal
|
|
|
32
64
|
setHeartbeat(status: HeartbeatStatus): void;
|
|
33
65
|
/**
|
|
34
66
|
* Subscribes to connection state transitions.
|
|
67
|
+
*
|
|
68
|
+
* @param handler - Callback invoked with a {@link StateChangeEvent} each time
|
|
69
|
+
* the connection state changes.
|
|
70
|
+
* @returns An unsubscribe function — call it to remove the listener.
|
|
35
71
|
*/
|
|
36
72
|
onStateChange(handler: (event: StateChangeEvent) => void): () => void;
|
|
37
73
|
/**
|
|
38
74
|
* Subscribes to health snapshot updates.
|
|
75
|
+
*
|
|
76
|
+
* @param handler - Callback invoked with the latest {@link ConnectionHealth}
|
|
77
|
+
* snapshot after any state or activity change.
|
|
78
|
+
* @returns An unsubscribe function — call it to remove the listener.
|
|
39
79
|
*/
|
|
40
80
|
onHealthChange(handler: (health: ConnectionHealth) => void): () => void;
|
|
41
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/connection/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,CAAC,gBAAgB,CAAC,CAAC;IACjC,aAAa,EAAE,CAAC,gBAAgB,CAAC,CAAC;CACnC,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/connection/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,CAAC,gBAAgB,CAAC,CAAC;IACjC,aAAa,EAAE,CAAC,gBAAgB,CAAC,CAAC;CACnC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,uBAAwB,SAAQ,sBAAsB,CAAC,cAAc,CAAC;IACjF,OAAO,CAAC,MAAM,CAIZ;IAEF;;;;;OAKG;IACH,SAAS,IAAI,gBAAgB,CAa5B;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAkBrD;IAED;;OAEG;IACH,eAAe,IAAI,IAAI,CAMtB;IAED;;OAEG;IACH,mBAAmB,IAAI,IAAI,CAkB1B;IAED;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAM1C;IAED;;;;;;OAMG;IACH,aAAa,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAGpE;IAED;;;;;;OAMG;IACH,cAAc,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAGtE;CACF"}
|
|
@@ -2,6 +2,28 @@ import { DisposableEventEmitter } from '@lspeasy/core';
|
|
|
2
2
|
import { ConnectionState } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Tracks connection state transitions and message activity timestamps.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* `ConnectionHealthTracker` is created internally by `LSPClient` and exposed
|
|
8
|
+
* via `client.connectionHealth`. Subscribe to `stateChanged` and
|
|
9
|
+
* `healthChanged` events to react to disconnections or transport failures.
|
|
10
|
+
*
|
|
11
|
+
* @useWhen
|
|
12
|
+
* You need to monitor connection liveness — for example, to show a status
|
|
13
|
+
* indicator, trigger reconnection logic, or surface transport errors to users.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link HeartbeatMonitor} for detecting silent transport failures with
|
|
16
|
+
* periodic ping/pong checks.
|
|
17
|
+
*
|
|
18
|
+
* @never
|
|
19
|
+
* NEVER mutate the object returned by `getHealth()` — it is a defensive copy
|
|
20
|
+
* but consumers that store a reference and then modify it will see stale state.
|
|
21
|
+
*
|
|
22
|
+
* NEVER call `setState` from outside `LSPClient` internals. External callers
|
|
23
|
+
* have no knowledge of the full state-transition graph; setting state directly
|
|
24
|
+
* can desync the client's internal bookkeeping from the tracker's reported state.
|
|
25
|
+
*
|
|
26
|
+
* @category Client
|
|
5
27
|
*/
|
|
6
28
|
export class ConnectionHealthTracker extends DisposableEventEmitter {
|
|
7
29
|
health = {
|
|
@@ -11,6 +33,9 @@ export class ConnectionHealthTracker extends DisposableEventEmitter {
|
|
|
11
33
|
};
|
|
12
34
|
/**
|
|
13
35
|
* Returns a defensive copy of the current health snapshot.
|
|
36
|
+
*
|
|
37
|
+
* @returns A shallow copy of the current {@link ConnectionHealth} object,
|
|
38
|
+
* including a nested copy of `heartbeat` when present.
|
|
14
39
|
*/
|
|
15
40
|
getHealth() {
|
|
16
41
|
const baseHealth = {
|
|
@@ -26,6 +51,13 @@ export class ConnectionHealthTracker extends DisposableEventEmitter {
|
|
|
26
51
|
}
|
|
27
52
|
/**
|
|
28
53
|
* Updates connection state and emits state/health change events.
|
|
54
|
+
*
|
|
55
|
+
* @param next - The new {@link ConnectionState} to transition to.
|
|
56
|
+
* @param reason - Optional human-readable reason for the state transition
|
|
57
|
+
* (e.g. `'Transport error'`). Included in the emitted `StateChangeEvent`.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link ConnectionState} for valid state values.
|
|
60
|
+
* @see {@link ConnectionHealthTracker} for the full class contract.
|
|
29
61
|
*/
|
|
30
62
|
setState(next, reason) {
|
|
31
63
|
if (this.health.state === next) {
|
|
@@ -84,6 +116,10 @@ export class ConnectionHealthTracker extends DisposableEventEmitter {
|
|
|
84
116
|
}
|
|
85
117
|
/**
|
|
86
118
|
* Subscribes to connection state transitions.
|
|
119
|
+
*
|
|
120
|
+
* @param handler - Callback invoked with a {@link StateChangeEvent} each time
|
|
121
|
+
* the connection state changes.
|
|
122
|
+
* @returns An unsubscribe function — call it to remove the listener.
|
|
87
123
|
*/
|
|
88
124
|
onStateChange(handler) {
|
|
89
125
|
const disposable = this.on('stateChanged', handler);
|
|
@@ -91,6 +127,10 @@ export class ConnectionHealthTracker extends DisposableEventEmitter {
|
|
|
91
127
|
}
|
|
92
128
|
/**
|
|
93
129
|
* Subscribes to health snapshot updates.
|
|
130
|
+
*
|
|
131
|
+
* @param handler - Callback invoked with the latest {@link ConnectionHealth}
|
|
132
|
+
* snapshot after any state or activity change.
|
|
133
|
+
* @returns An unsubscribe function — call it to remove the listener.
|
|
94
134
|
*/
|
|
95
135
|
onHealthChange(handler) {
|
|
96
136
|
const disposable = this.on('healthChanged', handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/connection/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAO7C
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/connection/health.ts"],"names":[],"mappings":"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"}
|
|
@@ -10,6 +10,32 @@ export interface HeartbeatMonitorOptions {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Runs interval-based heartbeat checks for active transports.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Created internally by `LSPClient` when `ClientOptions.heartbeat` is
|
|
16
|
+
* configured. The monitor periodically sends a ping (via `onPing`) and checks
|
|
17
|
+
* whether a pong was received within `timeout` ms. If not, `onUnresponsive`
|
|
18
|
+
* is called so the client can close and attempt to reconnect.
|
|
19
|
+
*
|
|
20
|
+
* @useWhen
|
|
21
|
+
* You need to detect silent transport failures — for example, when the server
|
|
22
|
+
* process dies without closing the socket, leaving the client hanging
|
|
23
|
+
* indefinitely on pending requests.
|
|
24
|
+
*
|
|
25
|
+
* @avoidWhen
|
|
26
|
+
* The transport already provides its own keep-alive mechanism (e.g. WebSocket
|
|
27
|
+
* ping frames) — adding a heartbeat on top creates redundant round-trips and
|
|
28
|
+
* may interfere with the transport's own timeout logic.
|
|
29
|
+
*
|
|
30
|
+
* @never
|
|
31
|
+
* NEVER set `interval` shorter than the typical round-trip latency for your
|
|
32
|
+
* transport — doing so causes constant `onUnresponsive` callbacks on any
|
|
33
|
+
* non-local transport, triggering spurious reconnects.
|
|
34
|
+
*
|
|
35
|
+
* NEVER rely on heartbeat for authentication or access control. The heartbeat
|
|
36
|
+
* only confirms the transport is alive; it carries no identity information.
|
|
37
|
+
*
|
|
38
|
+
* @category Client
|
|
13
39
|
*/
|
|
14
40
|
export declare class HeartbeatMonitor {
|
|
15
41
|
private readonly options;
|
|
@@ -30,6 +56,9 @@ export declare class HeartbeatMonitor {
|
|
|
30
56
|
markPong(): void;
|
|
31
57
|
/**
|
|
32
58
|
* Returns the latest heartbeat status snapshot.
|
|
59
|
+
*
|
|
60
|
+
* @returns A shallow copy of the current {@link HeartbeatStatus}, including
|
|
61
|
+
* timing and responsiveness information.
|
|
33
62
|
*/
|
|
34
63
|
getStatus(): HeartbeatStatus;
|
|
35
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../src/connection/heartbeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED
|
|
1
|
+
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../src/connection/heartbeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,gBAAgB;IAIf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,MAAM,CAAkB;IAEhC,YAA6B,OAAO,EAAE,uBAAuB,EAS5D;IAED;;OAEG;IACH,KAAK,IAAI,IAAI,CAuBZ;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,CAKX;IAED;;OAEG;IACH,QAAQ,IAAI,IAAI,CAWf;IAED;;;;;OAKG;IACH,SAAS,IAAI,eAAe,CAE3B;CACF"}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Runs interval-based heartbeat checks for active transports.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Created internally by `LSPClient` when `ClientOptions.heartbeat` is
|
|
6
|
+
* configured. The monitor periodically sends a ping (via `onPing`) and checks
|
|
7
|
+
* whether a pong was received within `timeout` ms. If not, `onUnresponsive`
|
|
8
|
+
* is called so the client can close and attempt to reconnect.
|
|
9
|
+
*
|
|
10
|
+
* @useWhen
|
|
11
|
+
* You need to detect silent transport failures — for example, when the server
|
|
12
|
+
* process dies without closing the socket, leaving the client hanging
|
|
13
|
+
* indefinitely on pending requests.
|
|
14
|
+
*
|
|
15
|
+
* @avoidWhen
|
|
16
|
+
* The transport already provides its own keep-alive mechanism (e.g. WebSocket
|
|
17
|
+
* ping frames) — adding a heartbeat on top creates redundant round-trips and
|
|
18
|
+
* may interfere with the transport's own timeout logic.
|
|
19
|
+
*
|
|
20
|
+
* @never
|
|
21
|
+
* NEVER set `interval` shorter than the typical round-trip latency for your
|
|
22
|
+
* transport — doing so causes constant `onUnresponsive` callbacks on any
|
|
23
|
+
* non-local transport, triggering spurious reconnects.
|
|
24
|
+
*
|
|
25
|
+
* NEVER rely on heartbeat for authentication or access control. The heartbeat
|
|
26
|
+
* only confirms the transport is alive; it carries no identity information.
|
|
27
|
+
*
|
|
28
|
+
* @category Client
|
|
3
29
|
*/
|
|
4
30
|
export class HeartbeatMonitor {
|
|
5
31
|
options;
|
|
@@ -64,6 +90,9 @@ export class HeartbeatMonitor {
|
|
|
64
90
|
}
|
|
65
91
|
/**
|
|
66
92
|
* Returns the latest heartbeat status snapshot.
|
|
93
|
+
*
|
|
94
|
+
* @returns A shallow copy of the current {@link HeartbeatStatus}, including
|
|
95
|
+
* timing and responsiveness information.
|
|
67
96
|
*/
|
|
68
97
|
getStatus() {
|
|
69
98
|
return { ...this.status };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../../src/connection/heartbeat.ts"],"names":[],"mappings":"AAYA
|
|
1
|
+
{"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../../src/connection/heartbeat.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,gBAAgB;IAIE,OAAO;IAH5B,KAAK,CAA6B;IAClC,MAAM,CAAkB;IAEhC,YAA6B,OAAgC;uBAAhC,OAAO;QAClC,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK;YACxC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ;YACjC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO;YAC/B,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC5B,IAAI,CAAC,MAAM,GAAG;gBACZ,GAAG,IAAI,CAAC,MAAM;gBACd,QAAQ,EAAE,IAAI,IAAI,EAAE;aACrB,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YAEtB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;YAE3C,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBAC1F,IAAI,CAAC,MAAM,GAAG;oBACZ,GAAG,IAAI,CAAC,MAAM;oBACd,YAAY,EAAE,KAAK;iBACpB,CAAC;gBACF,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAChC,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI;QACF,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,IAAI,CAAC,MAAM;YACd,QAAQ,EAAE,IAAI,IAAI,EAAE;YACpB,YAAY,EAAE,IAAI;SACnB,CAAC;QAEF,IAAI,eAAe,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partial-result-collector.js","sourceRoot":"","sources":["../../src/connection/partial-result-collector.ts"],"names":[],"mappings":"AAOA,yFAAyF;AACzF,MAAM,OAAO,sBAAsB;IAChB,UAAU,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE3E,KAAK,CAAW,KAAoB,EAAE,SAAoC
|
|
1
|
+
{"version":3,"file":"partial-result-collector.js","sourceRoot":"","sources":["../../src/connection/partial-result-collector.ts"],"names":[],"mappings":"AAOA,yFAAyF;AACzF,MAAM,OAAO,sBAAsB;IAChB,UAAU,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE3E,KAAK,CAAW,KAAoB,EAAE,SAAoC;QACxE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE;YACzB,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,SAAqC;SACjD,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,KAAoB,EAAE,KAAc;QACvC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;QAED,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAW,KAAoB;QACnC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,SAAS,CAAC,QAAsB,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,KAAoB;QACxB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration-store.js","sourceRoot":"","sources":["../../src/connection/registration-store.ts"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,MAAM,OAAO,iBAAiB;IACX,iBAAiB,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE5E,MAAM,CAAC,YAAiC
|
|
1
|
+
{"version":3,"file":"registration-store.js","sourceRoot":"","sources":["../../src/connection/registration-store.ts"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,MAAM,OAAO,iBAAiB;IACX,iBAAiB,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE5E,MAAM,CAAC,YAAiC;QACtC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,EAAU;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAClC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lifecycle state
|
|
2
|
+
* Lifecycle state of an `LSPClient` connection.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Transitions: `Disconnected` → `Connecting` (on `connect()`) → `Connected`
|
|
6
|
+
* (after `initialized`) → `Disconnecting` (on `disconnect()`) →
|
|
7
|
+
* `Disconnected`.
|
|
8
|
+
*
|
|
9
|
+
* Listen for state changes via `LSPClient.onConnectionStateChange`.
|
|
10
|
+
*
|
|
11
|
+
* @category Client
|
|
3
12
|
*/
|
|
4
13
|
export declare enum ConnectionState {
|
|
5
14
|
Connecting = "connecting",
|
|
@@ -9,39 +18,72 @@ export declare enum ConnectionState {
|
|
|
9
18
|
}
|
|
10
19
|
/**
|
|
11
20
|
* Configuration for optional heartbeat monitoring.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* When `enabled` is `true`, the client sends a `$/ping` request at each
|
|
24
|
+
* `interval` milliseconds. If no response arrives within `timeout`
|
|
25
|
+
* milliseconds, the connection is marked unresponsive.
|
|
26
|
+
*
|
|
27
|
+
* @config
|
|
28
|
+
* @category Client
|
|
12
29
|
*/
|
|
13
30
|
export interface HeartbeatConfig {
|
|
31
|
+
/** Whether heartbeat monitoring is active. */
|
|
14
32
|
enabled?: boolean;
|
|
33
|
+
/** Interval between pings in milliseconds. */
|
|
15
34
|
interval: number;
|
|
35
|
+
/** Time to wait for a pong response in milliseconds. */
|
|
16
36
|
timeout: number;
|
|
17
37
|
}
|
|
18
38
|
/**
|
|
19
|
-
*
|
|
39
|
+
* Snapshot of the current heartbeat monitoring status.
|
|
40
|
+
*
|
|
41
|
+
* @category Client
|
|
20
42
|
*/
|
|
21
43
|
export interface HeartbeatStatus {
|
|
44
|
+
/** Whether heartbeat monitoring is active. */
|
|
22
45
|
enabled: boolean;
|
|
46
|
+
/** Interval between pings in milliseconds. */
|
|
23
47
|
interval: number;
|
|
48
|
+
/** Timeout in milliseconds before a ping is considered unanswered. */
|
|
24
49
|
timeout: number;
|
|
50
|
+
/** Timestamp of the last outgoing ping, or `null` if no ping has been sent. */
|
|
25
51
|
lastPing: Date | null;
|
|
52
|
+
/** Timestamp of the last received pong, or `null` if no pong has been received. */
|
|
26
53
|
lastPong: Date | null;
|
|
54
|
+
/** Whether the server responded to the most recent ping within the timeout window. */
|
|
27
55
|
isResponsive: boolean;
|
|
28
56
|
}
|
|
29
57
|
/**
|
|
30
|
-
* Aggregated connection health
|
|
58
|
+
* Aggregated connection health snapshot returned by
|
|
59
|
+
* `LSPClient.getConnectionHealth()`.
|
|
60
|
+
*
|
|
61
|
+
* @category Client
|
|
31
62
|
*/
|
|
32
63
|
export interface ConnectionHealth {
|
|
64
|
+
/** Current lifecycle state of the connection. */
|
|
33
65
|
state: ConnectionState;
|
|
66
|
+
/** Timestamp of the last outgoing message, or `null` if none has been sent. */
|
|
34
67
|
lastMessageSent: Date | null;
|
|
68
|
+
/** Timestamp of the last incoming message, or `null` if none has been received. */
|
|
35
69
|
lastMessageReceived: Date | null;
|
|
70
|
+
/** Heartbeat monitoring snapshot, present only when heartbeat is configured. */
|
|
36
71
|
heartbeat?: HeartbeatStatus;
|
|
37
72
|
}
|
|
38
73
|
/**
|
|
39
|
-
*
|
|
74
|
+
* Payload emitted when the connection state changes.
|
|
75
|
+
* Subscribe via `LSPClient.onConnectionStateChange()`.
|
|
76
|
+
*
|
|
77
|
+
* @category Client
|
|
40
78
|
*/
|
|
41
79
|
export interface StateChangeEvent {
|
|
80
|
+
/** The state the connection was in before this transition. */
|
|
42
81
|
previous: ConnectionState;
|
|
82
|
+
/** The state the connection has transitioned into. */
|
|
43
83
|
current: ConnectionState;
|
|
84
|
+
/** Wall-clock time at which the state transition occurred. */
|
|
44
85
|
timestamp: Date;
|
|
86
|
+
/** Optional human-readable description of why the state changed. */
|
|
45
87
|
reason?: string;
|
|
46
88
|
}
|
|
47
89
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/connection/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/connection/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,oBAAY,eAAe;IACzB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;CAC9B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,mFAAmF;IACnF,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,sFAAsF;IACtF,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,KAAK,EAAE,eAAe,CAAC;IACvB,+EAA+E;IAC/E,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAC7B,mFAAmF;IACnF,mBAAmB,EAAE,IAAI,GAAG,IAAI,CAAC;IACjC,gFAAgF;IAChF,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,QAAQ,EAAE,eAAe,CAAC;IAC1B,sDAAsD;IACtD,OAAO,EAAE,eAAe,CAAC;IACzB,8DAA8D;IAC9D,SAAS,EAAE,IAAI,CAAC;IAChB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/connection/types.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
export { ConnectionState };
|
|
2
1
|
/**
|
|
3
|
-
* Lifecycle state
|
|
2
|
+
* Lifecycle state of an `LSPClient` connection.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Transitions: `Disconnected` → `Connecting` (on `connect()`) → `Connected`
|
|
6
|
+
* (after `initialized`) → `Disconnecting` (on `disconnect()`) →
|
|
7
|
+
* `Disconnected`.
|
|
8
|
+
*
|
|
9
|
+
* Listen for state changes via `LSPClient.onConnectionStateChange`.
|
|
10
|
+
*
|
|
11
|
+
* @category Client
|
|
4
12
|
*/
|
|
5
|
-
var ConnectionState;
|
|
13
|
+
export var ConnectionState;
|
|
6
14
|
(function (ConnectionState) {
|
|
7
15
|
ConnectionState["Connecting"] = "connecting";
|
|
8
16
|
ConnectionState["Connected"] = "connected";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/connection/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/connection/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,4CAAyB,CAAA;IACzB,0CAAuB,CAAA;IACvB,kDAA+B,CAAA;IAC/B,gDAA6B,CAAA;AAC/B,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* LSP client package for connecting to language servers.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Use `@lspeasy/client` when you need to build the **consumer** side of the
|
|
6
|
+
* Language Server Protocol — an editor extension, a CLI analysis tool, a test
|
|
7
|
+
* harness, or any process that speaks to a language server process.
|
|
8
|
+
*
|
|
9
|
+
* The primary entry point is {@link LSPClient}. Construct it with
|
|
10
|
+
* {@link ClientOptions}, call `connect(transport)` to complete the LSP
|
|
11
|
+
* handshake, then use `expect<ServerCaps>()` to get typed access to
|
|
12
|
+
* capability-aware namespaces (e.g. `client.textDocument.hover(params)`).
|
|
13
|
+
*
|
|
14
|
+
* ### Transport Decision Tree
|
|
15
|
+
*
|
|
16
|
+
* **Stdio** (`StdioTransport` from `@lspeasy/core/node`)
|
|
17
|
+
* — Use when: spawning the language server as a child process (the canonical
|
|
18
|
+
* editor extension pattern). Zero network overhead; server and client share
|
|
19
|
+
* a lifespan. Failure mode: server process dies silently → stdout EOF fires
|
|
20
|
+
* `onClose`; pair with `HeartbeatMonitor` on long-lived processes.
|
|
21
|
+
*
|
|
22
|
+
* **WebSocket** (`WebSocketTransport` from `@lspeasy/core`)
|
|
23
|
+
* — Use when: the language server runs remotely (CI, container, cloud dev env)
|
|
24
|
+
* or must be browser-accessible. Supports reconnect with exponential back-off.
|
|
25
|
+
* Failure mode: network partition → `onError` fires without `onClose`;
|
|
26
|
+
* enable `enableReconnect` and subscribe to `ConnectionHealthTracker` events.
|
|
27
|
+
*
|
|
28
|
+
* **TCP** (`TcpTransport` from `@lspeasy/core/node`)
|
|
29
|
+
* — Use when: you need a persistent local socket and control both ends
|
|
30
|
+
* (e.g. a test harness or a daemon that outlives the client process).
|
|
31
|
+
* Failure mode: port conflict at startup; use `mode: 'client'` only after
|
|
32
|
+
* confirming the server is listening, or wrap in a retry loop.
|
|
33
|
+
*
|
|
34
|
+
* **DedicatedWorkerTransport** (`DedicatedWorkerTransport` from `@lspeasy/core`)
|
|
35
|
+
* — Use when: running the language server in a Web Worker for browser isolation.
|
|
36
|
+
* Zero latency (shared memory), no WebSocket overhead. Failure mode: worker
|
|
37
|
+
* uncaught exception terminates silently; subscribe to `worker.onerror`.
|
|
38
|
+
*
|
|
39
|
+
* ### Connection health
|
|
40
|
+
* Use {@link ConnectionHealthTracker} and {@link HeartbeatMonitor} to detect
|
|
41
|
+
* silent transport failures. Subscribe to state-change events via
|
|
42
|
+
* {@link ConnectionState}.
|
|
43
|
+
*
|
|
44
|
+
* ### Dynamic registration
|
|
45
|
+
* The client handles `client/registerCapability` and
|
|
46
|
+
* `client/unregisterCapability` requests from the server automatically,
|
|
47
|
+
* updating the typed namespaces at runtime.
|
|
48
|
+
*
|
|
49
|
+
* @packageDocumentation
|
|
3
50
|
*/
|
|
4
51
|
export { LSPClient } from './client.js';
|
|
5
52
|
export { CapabilityGuard, ClientCapabilityGuard } from './capability-guard.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACnG,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,YAAY,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAGxE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* LSP client package for connecting to language servers.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Use `@lspeasy/client` when you need to build the **consumer** side of the
|
|
6
|
+
* Language Server Protocol — an editor extension, a CLI analysis tool, a test
|
|
7
|
+
* harness, or any process that speaks to a language server process.
|
|
8
|
+
*
|
|
9
|
+
* The primary entry point is {@link LSPClient}. Construct it with
|
|
10
|
+
* {@link ClientOptions}, call `connect(transport)` to complete the LSP
|
|
11
|
+
* handshake, then use `expect<ServerCaps>()` to get typed access to
|
|
12
|
+
* capability-aware namespaces (e.g. `client.textDocument.hover(params)`).
|
|
13
|
+
*
|
|
14
|
+
* ### Transport Decision Tree
|
|
15
|
+
*
|
|
16
|
+
* **Stdio** (`StdioTransport` from `@lspeasy/core/node`)
|
|
17
|
+
* — Use when: spawning the language server as a child process (the canonical
|
|
18
|
+
* editor extension pattern). Zero network overhead; server and client share
|
|
19
|
+
* a lifespan. Failure mode: server process dies silently → stdout EOF fires
|
|
20
|
+
* `onClose`; pair with `HeartbeatMonitor` on long-lived processes.
|
|
21
|
+
*
|
|
22
|
+
* **WebSocket** (`WebSocketTransport` from `@lspeasy/core`)
|
|
23
|
+
* — Use when: the language server runs remotely (CI, container, cloud dev env)
|
|
24
|
+
* or must be browser-accessible. Supports reconnect with exponential back-off.
|
|
25
|
+
* Failure mode: network partition → `onError` fires without `onClose`;
|
|
26
|
+
* enable `enableReconnect` and subscribe to `ConnectionHealthTracker` events.
|
|
27
|
+
*
|
|
28
|
+
* **TCP** (`TcpTransport` from `@lspeasy/core/node`)
|
|
29
|
+
* — Use when: you need a persistent local socket and control both ends
|
|
30
|
+
* (e.g. a test harness or a daemon that outlives the client process).
|
|
31
|
+
* Failure mode: port conflict at startup; use `mode: 'client'` only after
|
|
32
|
+
* confirming the server is listening, or wrap in a retry loop.
|
|
33
|
+
*
|
|
34
|
+
* **DedicatedWorkerTransport** (`DedicatedWorkerTransport` from `@lspeasy/core`)
|
|
35
|
+
* — Use when: running the language server in a Web Worker for browser isolation.
|
|
36
|
+
* Zero latency (shared memory), no WebSocket overhead. Failure mode: worker
|
|
37
|
+
* uncaught exception terminates silently; subscribe to `worker.onerror`.
|
|
38
|
+
*
|
|
39
|
+
* ### Connection health
|
|
40
|
+
* Use {@link ConnectionHealthTracker} and {@link HeartbeatMonitor} to detect
|
|
41
|
+
* silent transport failures. Subscribe to state-change events via
|
|
42
|
+
* {@link ConnectionState}.
|
|
43
|
+
*
|
|
44
|
+
* ### Dynamic registration
|
|
45
|
+
* The client handles `client/registerCapability` and
|
|
46
|
+
* `client/unregisterCapability` requests from the server automatically,
|
|
47
|
+
* updating the typed namespaces at runtime.
|
|
48
|
+
*
|
|
49
|
+
* @packageDocumentation
|
|
3
50
|
*/
|
|
4
51
|
export { LSPClient } from './client.js';
|
|
5
52
|
export { CapabilityGuard, ClientCapabilityGuard } from './capability-guard.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAS/E,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAOnG,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,12 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Options for `NotificationWaiter` and `LSPClient.waitForNotification`.
|
|
3
|
+
*
|
|
4
|
+
* @config
|
|
5
|
+
* @typeParam TParams - The notification params type for the awaited method.
|
|
6
|
+
* @category Client
|
|
3
7
|
*/
|
|
4
8
|
export interface NotificationWaitOptions<TParams> {
|
|
9
|
+
/**
|
|
10
|
+
* Maximum time to wait in milliseconds before rejecting with a timeout error.
|
|
11
|
+
*/
|
|
5
12
|
timeout: number;
|
|
13
|
+
/**
|
|
14
|
+
* Optional predicate to skip notifications that don't match the expected
|
|
15
|
+
* content. The waiter continues listening until a matching notification
|
|
16
|
+
* arrives or the timeout expires.
|
|
17
|
+
*/
|
|
6
18
|
filter?: (params: TParams) => boolean;
|
|
7
19
|
}
|
|
8
20
|
/**
|
|
9
|
-
* Tracks a single wait-for-notification operation and timeout lifecycle.
|
|
21
|
+
* Tracks a single wait-for-notification operation and its timeout lifecycle.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Created internally by `LSPClient.waitForNotification`. Use
|
|
25
|
+
* `LSPClient.waitForNotification` rather than instantiating this class
|
|
26
|
+
* directly.
|
|
27
|
+
*
|
|
28
|
+
* @useWhen
|
|
29
|
+
* You need to await a specific server-to-client notification after triggering
|
|
30
|
+
* a server-side operation — for example, waiting for
|
|
31
|
+
* `textDocument/publishDiagnostics` after saving a document.
|
|
32
|
+
*
|
|
33
|
+
* @avoidWhen
|
|
34
|
+
* You need to listen for ongoing notifications (not a one-shot wait) — use
|
|
35
|
+
* `LSPClient.onNotification` for persistent subscriptions instead.
|
|
36
|
+
*
|
|
37
|
+
* @never
|
|
38
|
+
* NEVER create a `NotificationWaiter` without setting a timeout — an
|
|
39
|
+
* indefinite wait will leak the waiter permanently if the notification never
|
|
40
|
+
* arrives (e.g. the server suppresses it for certain file types).
|
|
41
|
+
*
|
|
42
|
+
* NEVER use `NotificationWaiter` to wait for notifications that arrive before
|
|
43
|
+
* the waiter is registered. The waiter only sees notifications emitted after
|
|
44
|
+
* `start()` is called; earlier notifications are silently missed.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* // Wait for diagnostics after saving
|
|
49
|
+
* const diags = await client.waitForNotification(
|
|
50
|
+
* 'textDocument/publishDiagnostics',
|
|
51
|
+
* {
|
|
52
|
+
* timeout: 5000,
|
|
53
|
+
* filter: (params) => params.uri === 'file:///src/main.ts',
|
|
54
|
+
* }
|
|
55
|
+
* );
|
|
56
|
+
* console.log(diags.diagnostics);
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @typeParam TParams - The notification params type.
|
|
60
|
+
* @category Client
|
|
10
61
|
*/
|
|
11
62
|
export declare class NotificationWaiter<TParams> {
|
|
12
63
|
private readonly method;
|
|
@@ -22,6 +73,10 @@ export declare class NotificationWaiter<TParams> {
|
|
|
22
73
|
start(): void;
|
|
23
74
|
/**
|
|
24
75
|
* Returns whether an incoming notification satisfies this waiter.
|
|
76
|
+
*
|
|
77
|
+
* @param method - The notification method string of the incoming message.
|
|
78
|
+
* @param params - The notification params to test against the optional filter predicate.
|
|
79
|
+
* @returns `true` when the method matches and the filter (if any) passes.
|
|
25
80
|
*/
|
|
26
81
|
matches(method: string, params: TParams): boolean;
|
|
27
82
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../../src/notifications/wait.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../../src/notifications/wait.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB,CAAC,OAAO;IAC9C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBAAa,kBAAkB,CAAC,OAAO;IAMnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAGxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAT5B,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;IACtD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAElD,YACmB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,uBAAuB,CAAC,OAAO,CAAC,EAC1D,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,EAClC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EACb,SAAS,EAAE,MAAM,IAAI,EAIvC;IAED;;OAEG;IACH,KAAK,IAAI,IAAI,CASZ;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAUhD;IAED;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAG7B;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAGzB;IAED;;OAEG;IACH,OAAO,IAAI,IAAI,CAOd;CACF"}
|