@hydranium/protocol 1.0.0-next.28 → 1.0.0-next.281
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/README.md +44 -49
- package/lib/abstract-logger.d.ts +5 -0
- package/lib/abstract-logger.d.ts.map +1 -1
- package/lib/abstract-logger.js +7 -0
- package/lib/abstract-logger.js.map +1 -1
- package/lib/client/data-connection.d.ts +248 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +439 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +13 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +21 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +34 -24
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +606 -89
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +1015 -114
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +14 -9
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +14 -9
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +4 -4
- package/lib/client/message-relay.js +4 -4
- package/lib/client/message-relay.js.map +1 -1
- package/lib/client/post-message-transport.d.ts +64 -3
- package/lib/client/post-message-transport.d.ts.map +1 -1
- package/lib/client/post-message-transport.js +175 -1
- package/lib/client/post-message-transport.js.map +1 -1
- package/lib/client/rpc-connection.d.ts +157 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +214 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client-ids.d.ts +45 -0
- package/lib/client-ids.d.ts.map +1 -0
- package/lib/client-ids.js +48 -0
- package/lib/client-ids.js.map +1 -0
- package/lib/clock.d.ts +50 -10
- package/lib/clock.d.ts.map +1 -1
- package/lib/clock.js +36 -1
- package/lib/clock.js.map +1 -1
- package/lib/console-logger.d.ts +23 -0
- package/lib/console-logger.d.ts.map +1 -0
- package/lib/console-logger.js +39 -0
- package/lib/console-logger.js.map +1 -0
- package/lib/data/data-protocol-methods.d.ts +4 -4
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +13 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +146 -41
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +124 -21
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +71 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/debouncer.d.ts +3 -3
- package/lib/debouncer.d.ts.map +1 -1
- package/lib/debouncer.js +6 -9
- package/lib/debouncer.js.map +1 -1
- package/lib/errors.d.ts +178 -30
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +263 -32
- package/lib/errors.js.map +1 -1
- package/lib/glsp-request-model-args.d.ts +16 -0
- package/lib/glsp-request-model-args.d.ts.map +1 -0
- package/lib/glsp-request-model-args.js +19 -0
- package/lib/glsp-request-model-args.js.map +1 -0
- package/lib/glsp-save-model-actions.d.ts +50 -0
- package/lib/glsp-save-model-actions.d.ts.map +1 -0
- package/lib/glsp-save-model-actions.js +28 -0
- package/lib/glsp-save-model-actions.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/latency-collector.d.ts +8 -4
- package/lib/latency-collector.d.ts.map +1 -1
- package/lib/latency-collector.js.map +1 -1
- package/lib/logger.d.ts +27 -6
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +31 -3
- package/lib/logger.js.map +1 -1
- package/lib/messages/index.d.ts +4 -2
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +14 -4
- package/lib/messages/index.js.map +1 -1
- package/lib/messages/primitives.d.ts +71 -10
- package/lib/messages/primitives.d.ts.map +1 -1
- package/lib/messages/primitives.js +55 -3
- package/lib/messages/primitives.js.map +1 -1
- package/lib/model-server.d.ts +60 -13
- package/lib/model-server.d.ts.map +1 -1
- package/lib/model-server.js +4 -2
- package/lib/model-server.js.map +1 -1
- package/lib/model-service/base-version.d.ts +64 -0
- package/lib/model-service/base-version.d.ts.map +1 -0
- package/lib/model-service/base-version.js +43 -0
- package/lib/model-service/base-version.js.map +1 -0
- package/lib/model-service/index.d.ts +1 -1
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +4 -5
- package/lib/model-service/index.js.map +1 -1
- package/lib/model-service/reference-candidate.d.ts +5 -3
- package/lib/model-service/reference-candidate.d.ts.map +1 -1
- package/lib/{model-service/args.js → node/index.d.ts} +2 -3
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +29 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/process-memory.d.ts +66 -0
- package/lib/node/process-memory.d.ts.map +1 -0
- package/lib/node/process-memory.js +291 -0
- package/lib/node/process-memory.js.map +1 -0
- package/lib/noop-logger.d.ts.map +1 -1
- package/lib/noop-logger.js.map +1 -1
- package/lib/observable-value.js.map +1 -1
- package/lib/patch-merge.d.ts +63 -35
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +171 -25
- package/lib/patch-merge.js.map +1 -1
- package/lib/profile-session.d.ts +8 -4
- package/lib/profile-session.d.ts.map +1 -1
- package/lib/profile-session.js.map +1 -1
- package/lib/project.d.ts +4 -1
- package/lib/project.d.ts.map +1 -1
- package/lib/project.js.map +1 -1
- package/lib/random-uuid.d.ts +14 -0
- package/lib/random-uuid.d.ts.map +1 -0
- package/lib/random-uuid.js +24 -0
- package/lib/random-uuid.js.map +1 -0
- package/lib/reconcile-write.d.ts +67 -0
- package/lib/reconcile-write.d.ts.map +1 -0
- package/lib/reconcile-write.js +69 -0
- package/lib/reconcile-write.js.map +1 -0
- package/lib/rpc/bind-rpc-methods.d.ts +33 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +32 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +10 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +12 -2
- package/lib/rpc/create-rpc-proxy.js.map +1 -1
- package/lib/rpc/index.d.ts +1 -0
- package/lib/rpc/index.d.ts.map +1 -1
- package/lib/rpc/index.js +1 -0
- package/lib/rpc/index.js.map +1 -1
- package/lib/rpc/send-by-method-name.d.ts +76 -0
- package/lib/rpc/send-by-method-name.d.ts.map +1 -0
- package/lib/rpc/send-by-method-name.js +120 -0
- package/lib/rpc/send-by-method-name.js.map +1 -0
- package/lib/rpc/wire-prefix.js.map +1 -1
- package/lib/testing/catalogue-audit.d.ts +80 -0
- package/lib/testing/catalogue-audit.d.ts.map +1 -0
- package/lib/testing/catalogue-audit.js +94 -0
- package/lib/testing/catalogue-audit.js.map +1 -0
- package/lib/testing/data-doubles.d.ts +41 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +56 -8
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/fake-clock.d.ts +17 -2
- package/lib/testing/fake-clock.d.ts.map +1 -1
- package/lib/testing/fake-clock.js +61 -46
- package/lib/testing/fake-clock.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js +5 -2
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/node/duplex-connection.d.ts.map +1 -1
- package/lib/testing/node/duplex-connection.js +3 -2
- package/lib/testing/node/duplex-connection.js.map +1 -1
- package/lib/testing/node/duplex-stream.js.map +1 -1
- package/lib/testing/node/index.d.ts +1 -0
- package/lib/testing/node/index.d.ts.map +1 -1
- package/lib/testing/node/index.js +2 -2
- package/lib/testing/node/index.js.map +1 -1
- package/lib/testing/node/message-port-pair.d.ts +25 -0
- package/lib/testing/node/message-port-pair.d.ts.map +1 -0
- package/lib/testing/node/message-port-pair.js +26 -0
- package/lib/testing/node/message-port-pair.js.map +1 -0
- package/lib/testing/wait-for.d.ts +3 -2
- package/lib/testing/wait-for.d.ts.map +1 -1
- package/lib/testing/wait-for.js +40 -10
- package/lib/testing/wait-for.js.map +1 -1
- package/lib/tracer.d.ts.map +1 -1
- package/lib/tracer.js +5 -9
- package/lib/tracer.js.map +1 -1
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +70 -32
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js +17 -9
- package/lib/transfer-document.js.map +1 -1
- package/lib/uri.d.ts.map +1 -1
- package/lib/uri.js.map +1 -1
- package/lib/util.d.ts +8 -2
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +32 -4
- package/lib/util.js.map +1 -1
- package/package.json +24 -40
- package/src/abstract-logger.ts +8 -0
- package/src/client/data-connection.ts +535 -0
- package/src/client/data-events.ts +33 -1
- package/src/client/data-port.ts +36 -25
- package/src/client/data-session.ts +1285 -136
- package/src/client/index.ts +14 -9
- package/src/client/message-relay.ts +4 -4
- package/src/client/post-message-transport.ts +219 -4
- package/src/client/rpc-connection.ts +281 -0
- package/src/client-ids.ts +49 -0
- package/src/clock.ts +68 -10
- package/src/console-logger.ts +39 -0
- package/src/data/data-protocol-methods.ts +14 -4
- package/src/data/data-server-protocol.ts +173 -41
- package/src/data/events.ts +130 -21
- package/src/data/requests.ts +77 -11
- package/src/debouncer.ts +7 -10
- package/src/errors.ts +312 -40
- package/src/glsp-request-model-args.ts +16 -0
- package/src/glsp-save-model-actions.ts +59 -0
- package/src/index.ts +6 -0
- package/src/latency-collector.ts +8 -3
- package/src/logger.ts +33 -7
- package/src/messages/index.ts +4 -2
- package/src/messages/primitives.ts +102 -10
- package/src/model-server.ts +64 -19
- package/src/model-service/base-version.ts +72 -0
- package/src/model-service/index.ts +4 -5
- package/src/model-service/reference-candidate.ts +5 -3
- package/src/node/index.ts +14 -0
- package/src/node/process-memory.ts +299 -0
- package/src/patch-merge.ts +230 -45
- package/src/profile-session.ts +9 -4
- package/src/project.ts +4 -1
- package/src/random-uuid.ts +21 -0
- package/src/reconcile-write.ts +128 -0
- package/src/rpc/README.md +6 -6
- package/src/rpc/bind-rpc-methods.ts +59 -4
- package/src/rpc/create-rpc-proxy.ts +20 -2
- package/src/rpc/index.ts +1 -0
- package/src/rpc/send-by-method-name.ts +140 -0
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/data-doubles.ts +141 -19
- package/src/testing/fake-clock.ts +76 -48
- package/src/testing/index.ts +5 -2
- package/src/testing/node/duplex-connection.ts +3 -2
- package/src/testing/node/index.ts +2 -2
- package/src/testing/node/message-port-pair.ts +40 -0
- package/src/testing/wait-for.ts +38 -11
- package/src/tracer.ts +5 -9
- package/src/transfer-document.ts +87 -34
- package/src/util.ts +33 -6
- package/lib/model-service/args.d.ts +0 -64
- package/lib/model-service/args.d.ts.map +0 -1
- package/lib/model-service/args.js.map +0 -1
- package/src/model-service/args.ts +0 -67
package/src/clock.ts
CHANGED
|
@@ -14,9 +14,11 @@ import { Disposable } from './util';
|
|
|
14
14
|
* there is no `start` — you create it at the moment timing begins.
|
|
15
15
|
*
|
|
16
16
|
* Backed by a monotonic source (`performance.now`), so it is sub-millisecond
|
|
17
|
-
* precise and immune to wall-clock
|
|
18
|
-
* `Date.now` delta go backwards; a stopwatch cannot).
|
|
19
|
-
*
|
|
17
|
+
* precise and immune to wall-clock steps (a time sync or a manual change can
|
|
18
|
+
* make a `Date.now` delta go backwards; a stopwatch cannot). In Node on Linux
|
|
19
|
+
* it also leaves out time the system spends suspended, so a duration spanning
|
|
20
|
+
* a suspend reads as the awake time only. Use this for every duration, a TTL
|
|
21
|
+
* included, and {@link Clock.now} for "what time is it".
|
|
20
22
|
*
|
|
21
23
|
* It holds no scheduled resource and is therefore NOT a {@link Disposable} —
|
|
22
24
|
* the disposable thing is a {@link Clock.setTimer}. Reads are lazy, so a fake
|
|
@@ -45,16 +47,16 @@ export interface Stopwatch {
|
|
|
45
47
|
* testable instead of waiting on real wall-clock. The {@link SystemClock}
|
|
46
48
|
* default delegates to the platform; tests bind `makeFakeClock`.
|
|
47
49
|
*
|
|
48
|
-
* Two distinct readings on purpose: {@link now} is wall-clock
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* Two distinct readings on purpose: {@link now} is wall-clock, for a
|
|
51
|
+
* timestamp, while {@link stopwatch} measures durations off a monotonic
|
|
52
|
+
* source. They are different clocks; do not subtract two {@link now} readings
|
|
53
|
+
* to measure a duration. Framework code reads time only through a `Clock`, so
|
|
54
|
+
* a platform workaround lives in one place.
|
|
52
55
|
*
|
|
53
56
|
* A cross-head contract, so it carries no platform or DI-framework coupling.
|
|
54
57
|
*
|
|
55
|
-
* Note:
|
|
56
|
-
*
|
|
57
|
-
* measure would invert their meaning.
|
|
58
|
+
* Note: code that measures real CPU, heap or event-loop time never takes the
|
|
59
|
+
* bound `Clock`: faking the time it measures would invert its meaning.
|
|
58
60
|
*/
|
|
59
61
|
export interface Clock {
|
|
60
62
|
/** Current wall-clock time in milliseconds (the `Date.now` reading). */
|
|
@@ -76,8 +78,30 @@ export interface Clock {
|
|
|
76
78
|
*/
|
|
77
79
|
measure<T>(callback: () => Promise<T>): Promise<Timed<T>>;
|
|
78
80
|
measure<T>(callback: () => T): Timed<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Settle with `promise`, or with {@link TIMED_OUT} once `ms` have elapsed
|
|
83
|
+
* first. A promise that rejects first rejects this one; one that rejects
|
|
84
|
+
* after the timer is ignored. The timer is disposed the moment `promise`
|
|
85
|
+
* settles, so a won race leaves nothing scheduled, but `promise` itself
|
|
86
|
+
* runs on: nothing here can cancel it.
|
|
87
|
+
*
|
|
88
|
+
* Unlike VS Code's `raceTimeout`, this settles with a sentinel rather than
|
|
89
|
+
* `undefined`, so a promise resolving to `undefined` is not taken for a
|
|
90
|
+
* timeout; the caller branches on the result instead of passing an
|
|
91
|
+
* `onTimeout`.
|
|
92
|
+
*
|
|
93
|
+
* A custom implementation extends {@link SystemClock}, whose race runs over
|
|
94
|
+
* the subclass's {@link setTimer}.
|
|
95
|
+
*/
|
|
96
|
+
raceTimer<T>(promise: Promise<T>, ms: number): Promise<T | typeof TIMED_OUT>;
|
|
79
97
|
}
|
|
80
98
|
|
|
99
|
+
/**
|
|
100
|
+
* What {@link Clock.raceTimer} settles with when its timer fires first.
|
|
101
|
+
* Registered under a global key, so two copies of this package agree on it.
|
|
102
|
+
*/
|
|
103
|
+
export const TIMED_OUT = Symbol.for('hydranium/protocol/timed-out');
|
|
104
|
+
|
|
81
105
|
/**
|
|
82
106
|
* The result of {@link Clock.measure}: a callback's return value paired with
|
|
83
107
|
* its elapsed wall-time in milliseconds. A plain value object — no methods, no
|
|
@@ -144,6 +168,10 @@ function unrefTimer(handle: { unref?: () => void }): void {
|
|
|
144
168
|
* Default {@link Clock}: delegates to the platform's `Date.now`,
|
|
145
169
|
* `performance.now`, and `setTimeout`/`clearTimeout`. Bound everywhere in
|
|
146
170
|
* production; swapped for `makeFakeClock` in tests.
|
|
171
|
+
*
|
|
172
|
+
* {@link measure} and {@link raceTimer} run over {@link stopwatch} and
|
|
173
|
+
* {@link setTimer}, so a clock that extends this one and replaces those
|
|
174
|
+
* measures and races on its own time, as the test clock does.
|
|
147
175
|
*/
|
|
148
176
|
export class SystemClock implements Clock {
|
|
149
177
|
now(): number {
|
|
@@ -170,4 +198,34 @@ export class SystemClock implements Clock {
|
|
|
170
198
|
}
|
|
171
199
|
return { result: result as T, elapsedMs: stopwatch.elapsedMs };
|
|
172
200
|
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The timer settles the race one microtask after it fires. A real timer
|
|
204
|
+
* runs only once pending resolutions are delivered, while a fake one fires
|
|
205
|
+
* inside its `advance`, so settling at once would let a promise already
|
|
206
|
+
* resolved when `advance` runs lose to a timer it beats in production. The
|
|
207
|
+
* deferral covers only that promise: one that settles through further
|
|
208
|
+
* chained reactions, such as a `.then` chain, an async function or
|
|
209
|
+
* `Promise.allSettled`, can still lose to an `advance` in the same turn,
|
|
210
|
+
* while it wins on the platform's timer. The handlers go on `promise`
|
|
211
|
+
* before {@link setTimer} runs, so a `setTimer` that throws still leaves
|
|
212
|
+
* `promise` observed.
|
|
213
|
+
*/
|
|
214
|
+
raceTimer<T>(promise: Promise<T>, ms: number): Promise<T | typeof TIMED_OUT> {
|
|
215
|
+
return new Promise<T | typeof TIMED_OUT>((resolve, reject) => {
|
|
216
|
+
// eslint-disable-next-line prefer-const -- with a `const`, a `setTimer` that throws leaves it uninitialised, and the handlers' later read of it is an unhandled ReferenceError
|
|
217
|
+
let timer: Disposable | undefined;
|
|
218
|
+
promise.then(
|
|
219
|
+
value => {
|
|
220
|
+
timer?.dispose();
|
|
221
|
+
resolve(value);
|
|
222
|
+
},
|
|
223
|
+
(err: unknown) => {
|
|
224
|
+
timer?.dispose();
|
|
225
|
+
reject(err);
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
timer = this.setTimer(() => void Promise.resolve().then(() => resolve(TIMED_OUT)), ms);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
173
231
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import { AbstractLogger } from './abstract-logger';
|
|
11
|
+
import { type LogLevel, type Logger } from './logger';
|
|
12
|
+
|
|
13
|
+
/** `console.trace` prints a stack with every line, so `trace` goes out at `debug`. */
|
|
14
|
+
const CONSOLE_METHODS: Record<LogLevel, 'error' | 'warn' | 'info' | 'debug'> = {
|
|
15
|
+
error: 'error',
|
|
16
|
+
warn: 'warn',
|
|
17
|
+
info: 'info',
|
|
18
|
+
debug: 'debug',
|
|
19
|
+
trace: 'debug'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* {@link Logger} that writes each line to `console`, at the method matching its
|
|
24
|
+
* level: the framework's `[Label - time] [component]` prefix and the message,
|
|
25
|
+
* then any trailing arguments as they are, so a browser console can expand
|
|
26
|
+
* them. For a browser page, webview or extension host, which has no other sink
|
|
27
|
+
* to hand. On Node, `info` and `debug` reach stdout, so a process whose stdout
|
|
28
|
+
* carries a protocol stream must not use it.
|
|
29
|
+
*/
|
|
30
|
+
export class ConsoleLogger extends AbstractLogger implements Logger {
|
|
31
|
+
protected emit(level: LogLevel, label: string, message: string, args: readonly unknown[]): void {
|
|
32
|
+
console[CONSOLE_METHODS[level]](`${this.formatLinePrefix(label)} ${message}`, ...args);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected derive(component: string): this {
|
|
36
|
+
const Subclass = this.constructor as new (component?: string) => this;
|
|
37
|
+
return new Subclass(component);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -20,11 +20,17 @@ import type {
|
|
|
20
20
|
|
|
21
21
|
/** Request-method names on {@link DocumentServerProtocol}. */
|
|
22
22
|
export const DOCUMENT_SERVER_PROTOCOL_METHODS = [
|
|
23
|
+
'createSession',
|
|
24
|
+
'closeSession',
|
|
25
|
+
'createModelDocument',
|
|
26
|
+
'updateModelDocuments',
|
|
23
27
|
'openModelDocument',
|
|
24
28
|
'closeModelDocument',
|
|
25
29
|
'getModelDocument',
|
|
26
30
|
'updateModelDocument',
|
|
27
31
|
'saveModelDocument',
|
|
32
|
+
'persistModelDocument',
|
|
33
|
+
'deleteModelDocument',
|
|
28
34
|
'watchModelDocument',
|
|
29
35
|
'unwatchModelDocument',
|
|
30
36
|
'waitForReady'
|
|
@@ -56,12 +62,16 @@ export const REFERENCE_SERVER_PROTOCOL_METHODS = [
|
|
|
56
62
|
'findReferenceCandidates',
|
|
57
63
|
'resolveReference',
|
|
58
64
|
'findNextName'
|
|
59
|
-
] as const satisfies ReadonlyArray<keyof ReferenceServerProtocol
|
|
65
|
+
] as const satisfies ReadonlyArray<keyof ReferenceServerProtocol & string>;
|
|
60
66
|
|
|
61
67
|
/** Notification-method names on {@link DocumentClientProtocol}. */
|
|
62
|
-
export const DOCUMENT_CLIENT_PROTOCOL_METHODS = [
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
export const DOCUMENT_CLIENT_PROTOCOL_METHODS = [
|
|
69
|
+
'onDocumentUpdated',
|
|
70
|
+
'onDocumentSaved',
|
|
71
|
+
'onDocumentDirtyChanged',
|
|
72
|
+
'onDocumentDeleted',
|
|
73
|
+
'onDocumentsBuilt'
|
|
74
|
+
] as const satisfies ReadonlyArray<keyof DocumentClientProtocol<TransferElement> & string>;
|
|
65
75
|
|
|
66
76
|
/** Notification-method names on {@link ProjectClientProtocol}. */
|
|
67
77
|
export const PROJECT_CLIENT_PROTOCOL_METHODS = ['onProjectsChanged'] as const satisfies ReadonlyArray<keyof ProjectClientProtocol & string>;
|
|
@@ -10,16 +10,29 @@
|
|
|
10
10
|
import type { TransferDiagnostic } from '../transfer-diagnostic';
|
|
11
11
|
import type { TransferElement } from '../transfer-element';
|
|
12
12
|
import type { Project } from '../project';
|
|
13
|
-
import type { TransferDocument } from '../transfer-document';
|
|
13
|
+
import type { TransferDocument, TransferSavedDocument } from '../transfer-document';
|
|
14
14
|
import type { CloseModelArgs, FindNextNameArgs, OpenModelArgs, ReferenceContext, ReferenceRequest } from '../model-server';
|
|
15
15
|
import type { ReferenceCandidate, ReferenceTarget } from '../model-service/reference-candidate';
|
|
16
|
-
import type { ProjectsChangedEvent, TransferDocumentSavedEvent, TransferDocumentUpdatedEvent } from './events';
|
|
17
16
|
import type {
|
|
17
|
+
ProjectsChangedEvent,
|
|
18
|
+
TransferDocumentDeletedEvent,
|
|
19
|
+
TransferDocumentDirtyChangedEvent,
|
|
20
|
+
TransferDocumentSavedEvent,
|
|
21
|
+
TransferDocumentsBuiltEvent,
|
|
22
|
+
TransferDocumentUpdatedEvent
|
|
23
|
+
} from './events';
|
|
24
|
+
import type {
|
|
25
|
+
CloseSessionArgs,
|
|
26
|
+
CreateModelDocumentArgs,
|
|
27
|
+
CreateSessionArgs,
|
|
18
28
|
GetModelDocumentArgs,
|
|
19
29
|
GetProjectForUriArgs,
|
|
30
|
+
TransferDeleteDocumentArgs,
|
|
31
|
+
TransferPersistDocumentArgs,
|
|
20
32
|
TransferSaveDocumentArgs,
|
|
21
33
|
WatchModelDocumentArgs,
|
|
22
|
-
TransferUpdateDocumentArgs
|
|
34
|
+
TransferUpdateDocumentArgs,
|
|
35
|
+
TransferUpdateDocumentsArgs
|
|
23
36
|
} from './requests';
|
|
24
37
|
|
|
25
38
|
/**
|
|
@@ -40,35 +53,74 @@ import type {
|
|
|
40
53
|
*/
|
|
41
54
|
export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> {
|
|
42
55
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* document
|
|
56
|
+
* Register `args.clientId` as a client session owned by this connection.
|
|
57
|
+
* Rejects with a `DuplicateClientIdError` code when the id is live anywhere
|
|
58
|
+
* in the server process, and with a `ReservedClientIdError` code when the
|
|
59
|
+
* framework reserves it.
|
|
60
|
+
*
|
|
61
|
+
* A request carrying a registered id acts as that session: it writes only
|
|
62
|
+
* what the session has open, failing with a `DocumentNotOpenError` code
|
|
63
|
+
* otherwise, and opens nothing implicitly; its open reads the file and takes
|
|
64
|
+
* no `languageId`, `version` or `text` seed. The session ends with
|
|
65
|
+
* {@link closeSession} or when the connection closes, and either closes
|
|
66
|
+
* every document it has open.
|
|
54
67
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
|
|
68
|
+
* A registration carrying the `resumeToken` an earlier registration of the
|
|
69
|
+
* same id carried ends that session first, from any connection, so a client
|
|
70
|
+
* whose connection dropped can register again before the server notices.
|
|
71
|
+
*/
|
|
72
|
+
createSession(args: CreateSessionArgs): Promise<void>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* End a session this connection registered: close every document it has
|
|
76
|
+
* open, drop its watches, and free its id. A no-op for an id this
|
|
77
|
+
* connection did not register.
|
|
59
78
|
*/
|
|
60
|
-
|
|
79
|
+
closeSession(args: CloseSessionArgs): Promise<void>;
|
|
61
80
|
|
|
62
81
|
/**
|
|
63
|
-
*
|
|
64
|
-
* {@link openModelDocument}
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
* Create a document with `args.text`, open for the session, and return it
|
|
83
|
+
* as {@link openModelDocument} does. It reaches disk with the first save.
|
|
84
|
+
* Fails when the file exists or any client has the URI open, and with a
|
|
85
|
+
* `SessionClosedError` code when `args.clientId` is not a session
|
|
86
|
+
* registered on this connection.
|
|
87
|
+
*/
|
|
88
|
+
createModelDocument(args: CreateModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Write several documents the session has open, all or none: a conflict or
|
|
92
|
+
* a document not open fails the whole set before any text applies.
|
|
93
|
+
* Resolves to the documents in the order given. Only for a session
|
|
94
|
+
* registered on this connection.
|
|
95
|
+
*/
|
|
96
|
+
updateModelDocuments(args: TransferUpdateDocumentsArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>[]>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Open a document for the client session `clientId` and return its current
|
|
100
|
+
* state. `clientId` must be a session this connection registered with
|
|
101
|
+
* {@link createSession}; any other id fails with the closed-session code,
|
|
102
|
+
* as every document request here does. The document is read from disk
|
|
103
|
+
* unless a client has it open already, so the request carries no
|
|
104
|
+
* `languageId`, `version` or `text` seed. Returns the document at
|
|
105
|
+
* the server's configured target phase, as {@link getModelDocument} does.
|
|
106
|
+
* A repeat open changes nothing.
|
|
107
|
+
*
|
|
108
|
+
* Pair with {@link watchModelDocument} to receive subsequent build-phase
|
|
109
|
+
* events (open returns a one-shot snapshot; later validation diagnostics
|
|
110
|
+
* arrive on the watch channel).
|
|
111
|
+
*/
|
|
112
|
+
openModelDocument(args: Pick<OpenModelArgs, 'uri' | 'clientId' | 'options'>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Close the session's open of `uri`. Counterpart to
|
|
116
|
+
* {@link openModelDocument}; the document stays open until every client
|
|
117
|
+
* has closed it, and then the server releases it, by default reverting it
|
|
118
|
+
* to disk. The default
|
|
119
|
+
* `DataServer` impl ALSO releases any watch for the same
|
|
120
|
+
* `(uri, clientId)` (a forgotten {@link unwatchModelDocument} would
|
|
121
|
+
* otherwise leak dispatch; the implicit unwatch is idempotent).
|
|
122
|
+
* `watchModelDocument` is NOT coupled the other way: opening does not force
|
|
123
|
+
* a watch, so a snapshot reader can open without streaming.
|
|
72
124
|
*/
|
|
73
125
|
closeModelDocument(args: CloseModelArgs): Promise<void>;
|
|
74
126
|
|
|
@@ -81,19 +133,45 @@ export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiag
|
|
|
81
133
|
getModelDocument(args: GetModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
82
134
|
|
|
83
135
|
/**
|
|
84
|
-
* Update a document's content
|
|
85
|
-
*
|
|
86
|
-
* response.
|
|
136
|
+
* Update a document's content as the session `clientId`, which must have
|
|
137
|
+
* it open. The response carries the latest built state including
|
|
138
|
+
* diagnostics; callers observe convergence via that response.
|
|
87
139
|
*/
|
|
88
140
|
updateModelDocument(args: TransferUpdateDocumentArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
|
|
89
141
|
|
|
90
142
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
143
|
+
* Write a document as the session `clientId`, which must have it open, and
|
|
144
|
+
* persist it to disk. The response is the latest build of the document,
|
|
145
|
+
* with the version of the text written in `persisted`. Save semantics
|
|
146
|
+
* depend on the filesystem-provider wiring; rejection paths surface as
|
|
147
|
+
* awaited promise rejections.
|
|
95
148
|
*/
|
|
96
|
-
saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<
|
|
149
|
+
saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Persist the text the server holds for a document the session `clientId`
|
|
153
|
+
* has open, as it is: no update and no serialisation, so another client's
|
|
154
|
+
* unsaved text keeps its formatting. `baseVersion` is checked in the step
|
|
155
|
+
* that takes the text, so text that moved on fails with a `ConflictError`
|
|
156
|
+
* code. The saved event names this session, whoever wrote the text.
|
|
157
|
+
* Responds as {@link saveModelDocument} does.
|
|
158
|
+
*/
|
|
159
|
+
persistModelDocument(args: TransferPersistDocumentArgs): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Delete a document the session `clientId` has open, at once: its file,
|
|
163
|
+
* then the document, as a deletion a file watcher reports removes it. Every
|
|
164
|
+
* session's open of it closes and every client hears
|
|
165
|
+
* {@link DocumentClientProtocol.onDocumentDeleted} naming this session; the
|
|
166
|
+
* session's own watch is released, as {@link closeModelDocument} releases
|
|
167
|
+
* it. `baseVersion` is checked in the step that marks the document for
|
|
168
|
+
* deletion, so text that moved on fails with a `ConflictError` code. A file
|
|
169
|
+
* already gone deletes only the document; a file that cannot be removed
|
|
170
|
+
* fails the call and changes nothing. Resolves once the build that removes
|
|
171
|
+
* the document has run; a read then answers the URI without a model, unless
|
|
172
|
+
* an editor still has it open, whose buffer the document is built from.
|
|
173
|
+
*/
|
|
174
|
+
deleteModelDocument(args: TransferDeleteDocumentArgs): Promise<void>;
|
|
97
175
|
|
|
98
176
|
/**
|
|
99
177
|
* Start watching `(uri, clientId)`. The server starts dispatching
|
|
@@ -194,6 +272,22 @@ export interface DataServerProtocol<
|
|
|
194
272
|
>
|
|
195
273
|
extends DocumentServerProtocol<TTransfer, TDiagnostic>, ProjectServerProtocol<TProject> {}
|
|
196
274
|
|
|
275
|
+
/**
|
|
276
|
+
* The diagnostic shape a server answers with, read back off its own
|
|
277
|
+
* declaration.
|
|
278
|
+
*
|
|
279
|
+
* This is what lets a client tier stay generic over the server alone and still
|
|
280
|
+
* describe what it hands back. Both parameters must be inferred: naming
|
|
281
|
+
* {@link TransferElement} for the transfer instead fails to match while that
|
|
282
|
+
* parameter is still generic, and a default declared against the constraint
|
|
283
|
+
* then stops satisfying it.
|
|
284
|
+
*/
|
|
285
|
+
export type DiagnosticOf<TServer> =
|
|
286
|
+
TServer extends DocumentServerProtocol<infer _TTransfer, infer TDiagnostic> ? TDiagnostic : TransferDiagnostic;
|
|
287
|
+
|
|
288
|
+
/** The project shape a server answers with, read back off its own declaration. */
|
|
289
|
+
export type ProjectOf<TServer> = TServer extends ProjectServerProtocol<infer TProject> ? TProject : Project;
|
|
290
|
+
|
|
197
291
|
/**
|
|
198
292
|
* Cross-reference / naming slice of the server surface — scope-aware
|
|
199
293
|
* queries that resolve against the language's reference services. NOT part
|
|
@@ -204,11 +298,11 @@ export interface DataServerProtocol<
|
|
|
204
298
|
* source/URI (an `ElementSource` with no URI resolves to the sole
|
|
205
299
|
* registered language; a multi-language workspace overrides).
|
|
206
300
|
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
301
|
+
* Not generic over a server's root type: {@link resolveReference} answers with
|
|
302
|
+
* a node a reference names, which is no document root, and candidates and
|
|
303
|
+
* names are diagnostic-free.
|
|
210
304
|
*/
|
|
211
|
-
export interface ReferenceServerProtocol
|
|
305
|
+
export interface ReferenceServerProtocol {
|
|
212
306
|
/**
|
|
213
307
|
* List the reference candidates reachable for the property named in `ctx`
|
|
214
308
|
* from its (possibly synthetic) source. Backed by the language's
|
|
@@ -221,8 +315,13 @@ export interface ReferenceServerProtocol<TTransfer extends TransferElement> {
|
|
|
221
315
|
* target's document URI, display fields, and the resolved node's encoded
|
|
222
316
|
* transfer subtree. Resolves via the language's reference services;
|
|
223
317
|
* `undefined` when the reference does not resolve.
|
|
318
|
+
*
|
|
319
|
+
* `TElement` is the caller's claim about the target node's type; nothing
|
|
320
|
+
* checks it, so leave it at the default unless the reference names one type.
|
|
224
321
|
*/
|
|
225
|
-
resolveReference
|
|
322
|
+
resolveReference<TElement extends TransferElement = TransferElement>(
|
|
323
|
+
ref: ReferenceRequest
|
|
324
|
+
): Promise<ReferenceTarget<TElement> | undefined>;
|
|
226
325
|
|
|
227
326
|
/**
|
|
228
327
|
* Compute the next free name for a new element of `args.type` based on
|
|
@@ -262,6 +361,39 @@ export interface DocumentClientProtocol<TTransfer extends TransferElement, TDiag
|
|
|
262
361
|
* codepath, not a subscription codepath).
|
|
263
362
|
*/
|
|
264
363
|
onDocumentSaved(event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>): void;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Delivered when a subscribed document's text starts or stops differing
|
|
367
|
+
* from its file, as the server last knew it. Gated like
|
|
368
|
+
* {@link onDocumentSaved}; the answer at any one moment is the `dirty` of
|
|
369
|
+
* the documents the server sends. After a reconnect, a `DataSession`
|
|
370
|
+
* delivers here the answer of each document it restored, when that differs
|
|
371
|
+
* from the last this client was told: the flips while the connection was
|
|
372
|
+
* down reached no one.
|
|
373
|
+
*/
|
|
374
|
+
onDocumentDirtyChanged(event: TransferDocumentDirtyChangedEvent): void;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Delivered when a document's backing file was removed. Separate from
|
|
378
|
+
* {@link onDocumentUpdated} for the same reason as {@link onDocumentSaved},
|
|
379
|
+
* and more strongly: there is no built state to deliver, and the build-phase
|
|
380
|
+
* path cannot report a deletion at all.
|
|
381
|
+
*
|
|
382
|
+
* Ungated, because on a browser host — where the workspace lives behind the
|
|
383
|
+
* head — no other source can observe a file disappearing. Recipients that
|
|
384
|
+
* only care about their own documents filter by URI.
|
|
385
|
+
*/
|
|
386
|
+
onDocumentDeleted(event: TransferDocumentDeletedEvent): void;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Delivered once per build, naming the documents that reached the
|
|
390
|
+
* subscription phase and that
|
|
391
|
+
* nobody on this connection watches — chiefly the ones rebuilt as a cascade
|
|
392
|
+
* from a dependency's change, which no filesystem watcher can see because
|
|
393
|
+
* their own files did not change. The complement of
|
|
394
|
+
* {@link onDocumentUpdated}; carries URIs and no documents.
|
|
395
|
+
*/
|
|
396
|
+
onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void;
|
|
265
397
|
}
|
|
266
398
|
|
|
267
399
|
/**
|