@hydranium/protocol 1.0.0-next.13 → 1.0.0-next.132
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 +35 -1
- package/lib/client/data-connection.d.ts +145 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +205 -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 +17 -22
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +301 -80
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +425 -107
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +13 -8
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +13 -8
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +9 -3
- package/lib/client/message-relay.d.ts.map +1 -1
- package/lib/client/message-relay.js +11 -5
- 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 +149 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +179 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client-ids.d.ts +41 -0
- package/lib/client-ids.d.ts.map +1 -0
- package/lib/client-ids.js +44 -0
- package/lib/client-ids.js.map +1 -0
- package/lib/clock.d.ts +38 -0
- package/lib/clock.d.ts.map +1 -1
- package/lib/clock.js +36 -1
- package/lib/clock.js.map +1 -1
- 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 +11 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +110 -31
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +84 -3
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +67 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/errors.d.ts +102 -12
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +136 -18
- package/lib/errors.js.map +1 -1
- 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 +3 -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/messages/index.d.ts +29 -0
- package/lib/messages/index.d.ts.map +1 -0
- package/lib/messages/index.js +56 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/messages/primitives.d.ts +188 -0
- package/lib/messages/primitives.d.ts.map +1 -0
- package/lib/messages/primitives.js +161 -0
- package/lib/messages/primitives.js.map +1 -0
- package/lib/model-server.d.ts +44 -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/based-on.d.ts +57 -0
- package/lib/model-service/based-on.d.ts.map +1 -0
- package/lib/model-service/based-on.js +37 -0
- package/lib/model-service/based-on.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/patch-merge.d.ts +28 -27
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +66 -22
- 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/rpc/bind-rpc-methods.d.ts +29 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +22 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +7 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +6 -1
- package/lib/rpc/create-rpc-proxy.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 +13 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +19 -5
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/fake-clock.d.ts +9 -1
- package/lib/testing/fake-clock.d.ts.map +1 -1
- package/lib/testing/fake-clock.js +54 -45
- 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 +4 -1
- package/lib/testing/index.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/transfer-diagnostic.d.ts +33 -0
- package/lib/transfer-diagnostic.d.ts.map +1 -1
- package/lib/transfer-diagnostic.js +23 -0
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +22 -5
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js +14 -1
- package/lib/transfer-document.js.map +1 -1
- package/package.json +11 -2
- package/src/client/data-connection.ts +282 -0
- package/src/client/data-events.ts +33 -1
- package/src/client/data-port.ts +17 -23
- package/src/client/data-session.ts +549 -126
- package/src/client/index.ts +13 -8
- package/src/client/message-relay.ts +29 -7
- package/src/client/post-message-transport.ts +219 -4
- package/src/client/rpc-connection.ts +244 -0
- package/src/client-ids.ts +45 -0
- package/src/clock.ts +56 -0
- package/src/data/data-protocol-methods.ts +11 -3
- package/src/data/data-server-protocol.ts +131 -31
- package/src/data/events.ts +90 -3
- package/src/data/requests.ts +71 -11
- package/src/errors.ts +154 -20
- package/src/glsp-save-model-actions.ts +59 -0
- package/src/index.ts +6 -0
- package/src/latency-collector.ts +8 -3
- package/src/messages/index.ts +36 -0
- package/src/messages/primitives.ts +271 -0
- package/src/model-server.ts +47 -18
- package/src/model-service/based-on.ts +63 -0
- package/src/model-service/index.ts +4 -5
- package/src/patch-merge.ts +90 -37
- package/src/profile-session.ts +9 -4
- package/src/rpc/bind-rpc-methods.ts +49 -4
- package/src/rpc/create-rpc-proxy.ts +14 -1
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/data-doubles.ts +42 -17
- package/src/testing/fake-clock.ts +62 -47
- package/src/testing/index.ts +4 -1
- package/src/testing/node/index.ts +2 -2
- package/src/testing/node/message-port-pair.ts +40 -0
- package/src/transfer-diagnostic.ts +40 -0
- package/src/transfer-document.ts +29 -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 +0 -11
- package/lib/model-service/args.js.map +0 -1
- package/src/model-service/args.ts +0 -67
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.makeMessagePortPair = makeMessagePortPair;
|
|
12
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
13
|
+
function makeMessagePortPair() {
|
|
14
|
+
const channel = new node_worker_threads_1.MessageChannel();
|
|
15
|
+
return {
|
|
16
|
+
// Node's port satisfies the structural type at runtime; the cast records
|
|
17
|
+
// one platform's port standing in for the other's.
|
|
18
|
+
port1: channel.port1,
|
|
19
|
+
port2: channel.port2,
|
|
20
|
+
dispose() {
|
|
21
|
+
channel.port1.close();
|
|
22
|
+
channel.port2.close();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=message-port-pair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-port-pair.js","sourceRoot":"","sources":["../../../src/testing/node/message-port-pair.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;AAoBlF,kDAYC;AA9BD,6DAAqD;AAkBrD,SAAgB,mBAAmB;IAChC,MAAM,OAAO,GAAG,IAAI,oCAAc,EAAE,CAAC;IACrC,OAAO;QACJ,yEAAyE;QACzE,mDAAmD;QACnD,KAAK,EAAE,OAAO,CAAC,KAA0C;QACzD,KAAK,EAAE,OAAO,CAAC,KAA0C;QACzD,OAAO;YACJ,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;KACH,CAAC;AACL,CAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
+
import { type MessageParams, type ResolvedMessage } from './messages/primitives';
|
|
9
10
|
/**
|
|
10
11
|
* Generic, transport-friendly diagnostic shape used by the model-server protocol.
|
|
11
12
|
*
|
|
@@ -55,6 +56,21 @@ export interface TransferDiagnostic {
|
|
|
55
56
|
* is not usable as a rule identity on its own.
|
|
56
57
|
*/
|
|
57
58
|
code?: number | string;
|
|
59
|
+
/**
|
|
60
|
+
* Substitutions for the placeholders in the message this {@link code} names,
|
|
61
|
+
* present only for a diagnostic raised from a framework message declaration.
|
|
62
|
+
*
|
|
63
|
+
* Without them a translated template renders with its `{name}` tokens left
|
|
64
|
+
* standing, because substitution leaves an unmatched token in place rather
|
|
65
|
+
* than raising — so a surface that translates from {@link code} alone is
|
|
66
|
+
* correct for a parameterless sentence and visibly wrong for a parameterised
|
|
67
|
+
* one. This is the field that makes the second case work; the LSP carrier has
|
|
68
|
+
* always moved the params, and no carrier below it did.
|
|
69
|
+
*
|
|
70
|
+
* Prefer {@link TransferDiagnostic.resolved} over reading this: it decides
|
|
71
|
+
* whether an identity is present at all, which a lone `params` cannot.
|
|
72
|
+
*/
|
|
73
|
+
params?: MessageParams;
|
|
58
74
|
}
|
|
59
75
|
export declare namespace TransferDiagnostic {
|
|
60
76
|
/** Path separator between AST nodes within an element location. */
|
|
@@ -65,6 +81,23 @@ export declare namespace TransferDiagnostic {
|
|
|
65
81
|
const ELEMENT_PROPERTY_SEPARATOR = "^";
|
|
66
82
|
function isError(diagnostic: TransferDiagnostic): boolean;
|
|
67
83
|
function isParseError(diagnostic: TransferDiagnostic): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The diagnostic as a renderable message, for a surface that translates.
|
|
86
|
+
* `undefined` when it carries no framework identity — a syntactic error, an
|
|
87
|
+
* adopter's own check, a linker failure — which is the case a caller must
|
|
88
|
+
* distinguish rather than render.
|
|
89
|
+
*
|
|
90
|
+
* Hand the result to `renderFrameworkMessage` with whatever catalogue the
|
|
91
|
+
* host has loaded. The `text` is the server's English, so a code the
|
|
92
|
+
* catalogue does not carry still yields a complete sentence.
|
|
93
|
+
*
|
|
94
|
+
* `code` alone does not establish an identity: it also holds Langium's
|
|
95
|
+
* internal code and an adopter's own, and either would be looked up against a
|
|
96
|
+
* catalogue that cannot have it. Requiring `params` is what discriminates,
|
|
97
|
+
* and it is why a parameterless framework message still populates the field
|
|
98
|
+
* with an empty object rather than omitting it.
|
|
99
|
+
*/
|
|
100
|
+
function resolved(diagnostic: TransferDiagnostic): ResolvedMessage | undefined;
|
|
68
101
|
function getPath(diagnostic: TransferDiagnostic): string;
|
|
69
102
|
function errors(diagnostics: TransferDiagnostic[]): TransferDiagnostic[];
|
|
70
103
|
function hasErrors(diagnostics: TransferDiagnostic[]): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-diagnostic.d.ts","sourceRoot":"","sources":["../src/transfer-diagnostic.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAChC;;;;;OAKG;IACH,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,kBAAkB,CAAC;IAC5D;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACvC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,yBAAiB,kBAAkB,CAAC;IACjC,mEAAmE;IAC5D,MAAM,yBAAyB,MAAM,CAAC;IAC7C,wDAAwD;IACjD,MAAM,uBAAuB,MAAM,CAAC;IAC3C,sFAAsF;IAC/E,MAAM,0BAA0B,MAAM,CAAC;IAE9C,SAAgB,OAAO,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAE/D;IAED,SAAgB,YAAY,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAEpE;IAED,SAAgB,OAAO,CAAC,UAAU,EAAE,kBAAkB,GAAG,MAAM,CAE9D;IAED,SAAgB,MAAM,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,EAAE,CAE9E;IAED,SAAgB,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAEpE;IAED,SAAgB,cAAc,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAEzE;CACH"}
|
|
1
|
+
{"version":3,"file":"transfer-diagnostic.d.ts","sourceRoot":"","sources":["../src/transfer-diagnostic.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAChC;;;;;OAKG;IACH,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,kBAAkB,CAAC;IAC5D;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACvC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,yBAAiB,kBAAkB,CAAC;IACjC,mEAAmE;IAC5D,MAAM,yBAAyB,MAAM,CAAC;IAC7C,wDAAwD;IACjD,MAAM,uBAAuB,MAAM,CAAC;IAC3C,sFAAsF;IAC/E,MAAM,0BAA0B,MAAM,CAAC;IAE9C,SAAgB,OAAO,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAE/D;IAED,SAAgB,YAAY,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAEpE;IAED;;;;;;;;;;;;;;;OAeG;IACH,SAAgB,QAAQ,CAAC,UAAU,EAAE,kBAAkB,GAAG,eAAe,GAAG,SAAS,CAKpF;IAED,SAAgB,OAAO,CAAC,UAAU,EAAE,kBAAkB,GAAG,MAAM,CAE9D;IAED,SAAgB,MAAM,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,EAAE,CAE9E;IAED,SAAgB,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAEpE;IAED,SAAgB,cAAc,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAEzE;CACH"}
|
|
@@ -25,6 +25,29 @@ var TransferDiagnostic;
|
|
|
25
25
|
return diagnostic.type === 'parsing-error';
|
|
26
26
|
}
|
|
27
27
|
TransferDiagnostic.isParseError = isParseError;
|
|
28
|
+
/**
|
|
29
|
+
* The diagnostic as a renderable message, for a surface that translates.
|
|
30
|
+
* `undefined` when it carries no framework identity — a syntactic error, an
|
|
31
|
+
* adopter's own check, a linker failure — which is the case a caller must
|
|
32
|
+
* distinguish rather than render.
|
|
33
|
+
*
|
|
34
|
+
* Hand the result to `renderFrameworkMessage` with whatever catalogue the
|
|
35
|
+
* host has loaded. The `text` is the server's English, so a code the
|
|
36
|
+
* catalogue does not carry still yields a complete sentence.
|
|
37
|
+
*
|
|
38
|
+
* `code` alone does not establish an identity: it also holds Langium's
|
|
39
|
+
* internal code and an adopter's own, and either would be looked up against a
|
|
40
|
+
* catalogue that cannot have it. Requiring `params` is what discriminates,
|
|
41
|
+
* and it is why a parameterless framework message still populates the field
|
|
42
|
+
* with an empty object rather than omitting it.
|
|
43
|
+
*/
|
|
44
|
+
function resolved(diagnostic) {
|
|
45
|
+
if (typeof diagnostic.code !== 'string' || diagnostic.params === undefined) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return { code: diagnostic.code, params: diagnostic.params, text: diagnostic.message };
|
|
49
|
+
}
|
|
50
|
+
TransferDiagnostic.resolved = resolved;
|
|
28
51
|
function getPath(diagnostic) {
|
|
29
52
|
return diagnostic.property ? `${diagnostic.element}${TransferDiagnostic.ELEMENT_PROPERTY_SEPARATOR}${diagnostic.property}` : diagnostic.element;
|
|
30
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-diagnostic.js","sourceRoot":"","sources":["../src/transfer-diagnostic.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;
|
|
1
|
+
{"version":3,"file":"transfer-diagnostic.js","sourceRoot":"","sources":["../src/transfer-diagnostic.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAsElF,IAAiB,kBAAkB,CAsDlC;AAtDD,WAAiB,kBAAkB;IAChC,mEAAmE;IACtD,4CAAyB,GAAG,GAAG,CAAC;IAC7C,wDAAwD;IAC3C,0CAAuB,GAAG,GAAG,CAAC;IAC3C,sFAAsF;IACzE,6CAA0B,GAAG,GAAG,CAAC;IAE9C,SAAgB,OAAO,CAAC,UAA8B;QACnD,OAAO,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC;IAC1C,CAAC;IAFe,0BAAO,UAEtB,CAAA;IAED,SAAgB,YAAY,CAAC,UAA8B;QACxD,OAAO,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC;IAC9C,CAAC;IAFe,+BAAY,eAE3B,CAAA;IAED;;;;;;;;;;;;;;;OAeG;IACH,SAAgB,QAAQ,CAAC,UAA8B;QACpD,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1E,OAAO,SAAS,CAAC;QACpB,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;IACzF,CAAC;IALe,2BAAQ,WAKvB,CAAA;IAED,SAAgB,OAAO,CAAC,UAA8B;QACnD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,GAAG,mBAAA,0BAA0B,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC;IAChI,CAAC;IAFe,0BAAO,UAEtB,CAAA;IAED,SAAgB,MAAM,CAAC,WAAiC;QACrD,OAAO,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAFe,yBAAM,SAErB,CAAA;IAED,SAAgB,SAAS,CAAC,WAAiC;QACxD,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAFe,4BAAS,YAExB,CAAA;IAED,SAAgB,cAAc,CAAC,WAAiC;QAC7D,OAAO,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;IAFe,iCAAc,iBAE7B,CAAA;AACJ,CAAC,EAtDgB,kBAAkB,kCAAlB,kBAAkB,QAsDlC"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import type { TransferDiagnostic } from './transfer-diagnostic';
|
|
10
10
|
import type { TransferElement } from './transfer-element';
|
|
11
|
+
import { type SnapshotVersion } from './model-service/based-on';
|
|
11
12
|
/**
|
|
12
13
|
* Wire envelope exchanged between the model-server's data-server head and
|
|
13
14
|
* its clients. Carries a transfer-shaped root — never an AST root — plus
|
|
@@ -25,14 +26,13 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
|
|
|
25
26
|
uri: string;
|
|
26
27
|
/**
|
|
27
28
|
* The document version this snapshot was taken at — sourced from the
|
|
28
|
-
* server's text-document version counter.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* updates and reject them with `ConflictError`.
|
|
29
|
+
* server's text-document version counter. A caller that mutates the document
|
|
30
|
+
* subsequently sends this straight back as `TransferUpdateDocumentArgs.basedOn`, and
|
|
31
|
+
* the server rejects a stale-based update with `ConflictError`.
|
|
32
32
|
*
|
|
33
33
|
* See `@hydranium/protocol#errors` for the conflict-detection contract.
|
|
34
34
|
*/
|
|
35
|
-
version:
|
|
35
|
+
version: SnapshotVersion;
|
|
36
36
|
/**
|
|
37
37
|
* Absent when the document does not exist — the server answers an unknown URI
|
|
38
38
|
* with a shaped envelope rather than an error, so absence is an ordinary
|
|
@@ -41,6 +41,14 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
|
|
|
41
41
|
*/
|
|
42
42
|
root?: TTransfer;
|
|
43
43
|
diagnostics: TDiagnostic[];
|
|
44
|
+
/**
|
|
45
|
+
* Whether the server holds text for this document that its file does not,
|
|
46
|
+
* as the server last knew the file: set on every document a data server
|
|
47
|
+
* answers or sends that the server holds, and absent otherwise. A change
|
|
48
|
+
* after this snapshot arrives as `onDocumentDirtyChanged` to a client
|
|
49
|
+
* watching the document.
|
|
50
|
+
*/
|
|
51
|
+
dirty?: boolean;
|
|
44
52
|
}
|
|
45
53
|
/**
|
|
46
54
|
* A {@link TransferDocument} the server actually had, so `root` is present.
|
|
@@ -62,6 +70,15 @@ export declare namespace TransferDocument {
|
|
|
62
70
|
* with it.
|
|
63
71
|
*/
|
|
64
72
|
function assertLoaded<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(document: TransferDocument<TTransfer, TDiagnostic>): LoadedTransferDocument<TTransfer, TDiagnostic>;
|
|
73
|
+
/**
|
|
74
|
+
* The envelope for a document the server does not have — `root` absent, and
|
|
75
|
+
* the version a read of a URI the store never saw reports.
|
|
76
|
+
*
|
|
77
|
+
* Exists so the absent branch is built the same way the present one is: both
|
|
78
|
+
* doors mark the version as coming from a read, and neither asks a caller to
|
|
79
|
+
* do it.
|
|
80
|
+
*/
|
|
81
|
+
function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(uri: string, diagnostics?: TDiagnostic[]): TransferDocument<TTransfer, TDiagnostic>;
|
|
65
82
|
/**
|
|
66
83
|
* Construct a {@link TransferDocument} envelope. `diagnostics` defaults
|
|
67
84
|
* to `[]` so test fixtures, fake protocol implementations, and the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-document.d.ts","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"transfer-document.d.ts","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB;IAClG,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,OAAO,EAAE,eAAe,CAAC;IACzB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,IAAI,gBAAgB,CACvH,SAAS,EACT,WAAW,CACb,GAAG;IACD,IAAI,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,yBAAiB,gBAAgB,CAAC;IAC/B;;;OAGG;IACH,SAAgB,QAAQ,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACzF,QAAQ,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,GAClD,QAAQ,IAAI,sBAAsB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE5D;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EAC7F,QAAQ,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,GAClD,sBAAsB,CAAC,SAAS,EAAE,WAAW,CAAC,CAKhD;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,EACf,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;CACH"}
|
package/lib/transfer-document.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.TransferDocument = void 0;
|
|
12
|
+
const based_on_1 = require("./model-service/based-on");
|
|
12
13
|
var TransferDocument;
|
|
13
14
|
(function (TransferDocument) {
|
|
14
15
|
/**
|
|
@@ -32,6 +33,18 @@ var TransferDocument;
|
|
|
32
33
|
return document;
|
|
33
34
|
}
|
|
34
35
|
TransferDocument.assertLoaded = assertLoaded;
|
|
36
|
+
/**
|
|
37
|
+
* The envelope for a document the server does not have — `root` absent, and
|
|
38
|
+
* the version a read of a URI the store never saw reports.
|
|
39
|
+
*
|
|
40
|
+
* Exists so the absent branch is built the same way the present one is: both
|
|
41
|
+
* doors mark the version as coming from a read, and neither asks a caller to
|
|
42
|
+
* do it.
|
|
43
|
+
*/
|
|
44
|
+
function absent(uri, diagnostics = []) {
|
|
45
|
+
return { uri, version: (0, based_on_1.asSnapshotVersion)(0), root: undefined, diagnostics };
|
|
46
|
+
}
|
|
47
|
+
TransferDocument.absent = absent;
|
|
35
48
|
/**
|
|
36
49
|
* Construct a {@link TransferDocument} envelope. `diagnostics` defaults
|
|
37
50
|
* to `[]` so test fixtures, fake protocol implementations, and the
|
|
@@ -39,7 +52,7 @@ var TransferDocument;
|
|
|
39
52
|
* at every call site.
|
|
40
53
|
*/
|
|
41
54
|
function create(uri, version, root, diagnostics = []) {
|
|
42
|
-
return { uri, version, root, diagnostics };
|
|
55
|
+
return { uri, version: (0, based_on_1.asSnapshotVersion)(version), root, diagnostics };
|
|
43
56
|
}
|
|
44
57
|
TransferDocument.create = create;
|
|
45
58
|
})(TransferDocument || (exports.TransferDocument = TransferDocument = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;
|
|
1
|
+
{"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAIlF,uDAAmF;AAuDnF,IAAiB,gBAAgB,CAuDhC;AAvDD,WAAiB,gBAAgB;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CACrB,QAAkD;QAElD,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;IACtC,CAAC;IAJe,yBAAQ,WAIvB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CACzB,QAAkD;QAElD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,QAAQ,CAAC;IACnB,CAAC;IAPe,6BAAY,eAO3B,CAAA;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAC/E,CAAC;IALe,uBAAM,SAKrB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,OAAe,EACf,IAAe,EACf,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC1E,CAAC;IAPe,uBAAM,SAOrB,CAAA;AACJ,CAAC,EAvDgB,gBAAgB,gCAAhB,gBAAgB,QAuDhC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydranium/protocol",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.132",
|
|
4
4
|
"description": "Generic, language-agnostic types, constants, and pure utilities for the hydranium framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hydranium",
|
|
@@ -41,6 +41,14 @@
|
|
|
41
41
|
"types": "./lib/data/index.d.ts",
|
|
42
42
|
"default": "./lib/data/index.js"
|
|
43
43
|
},
|
|
44
|
+
"./messages": {
|
|
45
|
+
"types": "./lib/messages/index.d.ts",
|
|
46
|
+
"default": "./lib/messages/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./lib/messages": {
|
|
49
|
+
"types": "./lib/messages/index.d.ts",
|
|
50
|
+
"default": "./lib/messages/index.js"
|
|
51
|
+
},
|
|
44
52
|
"./testing": {
|
|
45
53
|
"types": "./lib/testing/index.d.ts",
|
|
46
54
|
"default": "./lib/testing/index.js"
|
|
@@ -88,7 +96,7 @@
|
|
|
88
96
|
"vscode-jsonrpc": "9.0.1"
|
|
89
97
|
},
|
|
90
98
|
"peerDependencies": {
|
|
91
|
-
"vscode-jsonrpc": "
|
|
99
|
+
"vscode-jsonrpc": "9.0.1"
|
|
92
100
|
},
|
|
93
101
|
"engines": {
|
|
94
102
|
"node": ">=22.13"
|
|
@@ -96,5 +104,6 @@
|
|
|
96
104
|
"publishConfig": {
|
|
97
105
|
"access": "public"
|
|
98
106
|
},
|
|
107
|
+
"//peerDependencies": "`vscode-jsonrpc` is EXACT rather than a range, because it is one link of an atomic chain with no independently movable link: `vscode-languageserver-protocol` depends on it at exactly 9.0.1, so any other value an adopter supplies is a SECOND physical copy rather than an upgrade. This wire stack breaks on copy identity rather than on structure — `ParameterStructures.auto` is a singleton compared by `===` in connection.js, so a request type built by one copy and sent over a connection owned by the other throws `Unknown parameter structure auto`. A caret or union range was rejected because npm then resolves a `vscode-jsonrpc@8.2.0` tree SILENTLY, with no diagnostic at all, and the failure surfaces only later at server init. Exact does not fail the install either — npm downgrades an unsatisfiable peer to a warning — but it is a NAMED ERESOLVE warning printing the required version beside the found one, and a hard error for anyone installing with `--strict-peer-deps`. It does NOT prevent a NESTED copy — `@eclipse-glsp/*` carries its own exact `vscode-jsonrpc@8.2.0` dependency and root `overrides` do not ship — so a consumer of the GLSP head must pin the chain in its own manifest, and docs/adopting/requirements.md carries the block to paste.",
|
|
99
108
|
"//prepack": "The publish guard, and it deliberately is NOT a `prepare`: npm runs a workspace `prepare` BEFORE the root `postinstall` that applies patches/vscode-jsonrpc+9.0.1.patch, so building there fails on a cold clone and npm rolls the entire install back. `prepack` runs only when a tarball is made (`npm pack`, `npm publish`) and never on install, so it cannot break the install it has no business touching. It FAILS rather than rebuilds, because the rebuild is exactly the part that ordering defeats. What it defends against: `files` lists `lib`, `lib` is gitignored, and a `files` entry matching nothing is skipped SILENTLY — so `npm publish` from an unbuilt tree emits a tarball of `src` and nothing else, with no error."
|
|
100
109
|
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, 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 { Emitter, type Event } from 'vscode-jsonrpc';
|
|
11
|
+
import { FRAMEWORK_CLIENT_IDS } from '../client-ids';
|
|
12
|
+
import {
|
|
13
|
+
DATA_CLIENT_PROTOCOL_METHODS,
|
|
14
|
+
DATA_SERVER_WIRE_PREFIX,
|
|
15
|
+
type DataClientProtocol,
|
|
16
|
+
type DataServerProtocol,
|
|
17
|
+
type DiagnosticOf,
|
|
18
|
+
type ProjectOf,
|
|
19
|
+
type TransferDocumentDirtyChangedEvent
|
|
20
|
+
} from '../data';
|
|
21
|
+
import type { TransferElement } from '../transfer-element';
|
|
22
|
+
import { DataEvents } from './data-events';
|
|
23
|
+
import type { DataPort } from './data-port';
|
|
24
|
+
import { DataSession, type DataSessionFactory } from './data-session';
|
|
25
|
+
import { RpcConnection, type RpcConnectionLifecycle } from './rpc-connection';
|
|
26
|
+
|
|
27
|
+
/** Options for {@link DataConnection}. */
|
|
28
|
+
export interface DataConnectionOptions<
|
|
29
|
+
TTransfer extends TransferElement = TransferElement,
|
|
30
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
|
|
31
|
+
> extends RpcConnectionLifecycle {
|
|
32
|
+
/**
|
|
33
|
+
* Wire namespace the server is addressed under. Defaults to the
|
|
34
|
+
* framework's {@link DATA_SERVER_WIRE_PREFIX}, which is what an unmodified
|
|
35
|
+
* `DataServer` binds. Override only alongside the server's own
|
|
36
|
+
* `methodNamespace` option — a mismatch turns every request into
|
|
37
|
+
* "Unhandled method" rather than failing at wire-up.
|
|
38
|
+
*/
|
|
39
|
+
readonly methodNamespace?: string;
|
|
40
|
+
/** Builds the sessions `createSession` hands out. Defaults to a plain {@link DataSession}. */
|
|
41
|
+
readonly sessionFactory?: DataSessionFactory<TTransfer, TServer>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** {@link DataConnectionOptions} for a client that does not speak {@link DataClientProtocol}. */
|
|
45
|
+
export interface DataConnectionOptionsWithMethods<
|
|
46
|
+
TClient extends object,
|
|
47
|
+
TTransfer extends TransferElement = TransferElement,
|
|
48
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
|
|
49
|
+
> extends DataConnectionOptions<TTransfer, TServer> {
|
|
50
|
+
/**
|
|
51
|
+
* Method names of the client to bind as inbound handlers. Declare it
|
|
52
|
+
* `as const satisfies ReadonlyArray<keyof YourClient & string>` so the list
|
|
53
|
+
* cannot drift from the interface.
|
|
54
|
+
*/
|
|
55
|
+
readonly clientMethods: readonly (keyof TClient & string)[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Trailing constructor arguments, required only when the client cannot take
|
|
60
|
+
* the framework's default method list.
|
|
61
|
+
*
|
|
62
|
+
* `bindRpcMethods` throws for a name the target does not implement, so a
|
|
63
|
+
* request/response-only client binding the default list fails at wire-up. The
|
|
64
|
+
* conditional turns that into a compile error.
|
|
65
|
+
*/
|
|
66
|
+
export type DataConnectionArgs<
|
|
67
|
+
TTransfer extends TransferElement,
|
|
68
|
+
TClient extends object,
|
|
69
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
|
|
70
|
+
> =
|
|
71
|
+
TClient extends DataClientProtocol<TTransfer>
|
|
72
|
+
? [options?: DataConnectionOptions<TTransfer, TServer> & Partial<DataConnectionOptionsWithMethods<TClient, TTransfer, TServer>>]
|
|
73
|
+
: [options: DataConnectionOptionsWithMethods<TClient, TTransfer, TServer>];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A {@link RpcConnection} to the data head, carrying as many participants as
|
|
77
|
+
* the host has interested parties.
|
|
78
|
+
*
|
|
79
|
+
* Document operations live on the participants rather than here: they carry a
|
|
80
|
+
* `clientId`, which identifies a participant rather than a wire, and the server
|
|
81
|
+
* keys its opens and watches per `(uri, clientId)`. Two parties sharing one
|
|
82
|
+
* identity cannot tell each other's writes from their own echoes.
|
|
83
|
+
*
|
|
84
|
+
* Generic over the transfer root so this file names no grammar. An adopter
|
|
85
|
+
* binds the concrete root (or the union of them, for a multi-grammar head) at
|
|
86
|
+
* its own edge.
|
|
87
|
+
*/
|
|
88
|
+
export class DataConnection<
|
|
89
|
+
TTransfer extends TransferElement,
|
|
90
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>,
|
|
91
|
+
TClient extends object = DataClientProtocol<TTransfer>
|
|
92
|
+
> extends RpcConnection<TServer, TClient> {
|
|
93
|
+
protected readonly sessions = new Set<DataSession<TTransfer, TServer>>();
|
|
94
|
+
protected readonly sessionFactory: DataSessionFactory<TTransfer, TServer>;
|
|
95
|
+
protected readonly createSessionEmitter = new Emitter<DataSession<TTransfer, TServer>>();
|
|
96
|
+
/**
|
|
97
|
+
* Fires with each session {@link createSession} starts, before it returns,
|
|
98
|
+
* so a listener sees every session a caller can. A session started before
|
|
99
|
+
* the listener subscribed is in {@link liveSessions}.
|
|
100
|
+
*/
|
|
101
|
+
readonly onDidCreateSession: Event<DataSession<TTransfer, TServer>> = this.createSessionEmitter.event;
|
|
102
|
+
/**
|
|
103
|
+
* Per URI, the `dirty` the client was last told since a session of this
|
|
104
|
+
* connection last opened the URI. A restore tells the client its answer
|
|
105
|
+
* only where it differs, so the client hears changes and nothing else; see
|
|
106
|
+
* {@link DataSessionHost.restoreDirty}.
|
|
107
|
+
*/
|
|
108
|
+
protected readonly dirtyStates = new Map<string, boolean>();
|
|
109
|
+
|
|
110
|
+
constructor(port: DataPort, client: TClient, ...rest: DataConnectionArgs<TTransfer, TClient, TServer>) {
|
|
111
|
+
const [options = {}] = rest as [
|
|
112
|
+
(DataConnectionOptions<TTransfer, TServer> & Partial<DataConnectionOptionsWithMethods<TClient, TTransfer, TServer>>)?
|
|
113
|
+
];
|
|
114
|
+
super(port, client, {
|
|
115
|
+
methodNamespace: options.methodNamespace ?? DATA_SERVER_WIRE_PREFIX,
|
|
116
|
+
// The default is reachable only where `TClient` satisfies
|
|
117
|
+
// `DataClientProtocol`, which the constructor's conditional enforces;
|
|
118
|
+
// the compiler cannot carry that through to the generic parameter.
|
|
119
|
+
clientMethods: options.clientMethods ?? (DATA_CLIENT_PROTOCOL_METHODS as unknown as readonly (keyof TClient & string)[]),
|
|
120
|
+
lifecycle: options
|
|
121
|
+
});
|
|
122
|
+
this.sessionFactory =
|
|
123
|
+
options.sessionFactory ?? ((clientId, host, label) => new DataSession<TTransfer, TServer>(clientId, host, label));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The sessions of this connection that have not ended, in the order they
|
|
128
|
+
* started. A session is listed until its `onDidDispose` fires, or until
|
|
129
|
+
* {@link dispose} clears the list.
|
|
130
|
+
*/
|
|
131
|
+
get liveSessions(): readonly DataSession<TTransfer, TServer>[] {
|
|
132
|
+
return [...this.sessions];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Start a participant on this connection, registered with the server under a
|
|
137
|
+
* fresh id, `label` plus `#` plus a random UUID, or under `clientId` when
|
|
138
|
+
* given. Pass a `label` naming the participant; without one it is
|
|
139
|
+
* `session`. Synchronous: the registration is sent at once, and the
|
|
140
|
+
* session's calls wait for it. The server refuses an id live anywhere in
|
|
141
|
+
* its process, and every call of that session then rejects with a
|
|
142
|
+
* `DuplicateClientIdError` code.
|
|
143
|
+
*
|
|
144
|
+
* Throws for an id in {@link FRAMEWORK_CLIENT_IDS} — those are authors the
|
|
145
|
+
* SERVER emits rather than participants, so a session holding one would read
|
|
146
|
+
* the framework's own broadcasts as its own echoes and drop them — and for
|
|
147
|
+
* an id a live session on this connection already holds.
|
|
148
|
+
*/
|
|
149
|
+
createSession(label = 'session', clientId?: string): DataSession<TTransfer, TServer> {
|
|
150
|
+
this.assertLive();
|
|
151
|
+
const id = clientId ?? `${label}#${globalThis.crypto.randomUUID()}`;
|
|
152
|
+
if (FRAMEWORK_CLIENT_IDS.includes(id)) {
|
|
153
|
+
throw new Error(`clientId '${id}' is reserved by the framework and cannot identify a participant`);
|
|
154
|
+
}
|
|
155
|
+
if ([...this.sessions].some(session => session.clientId === id)) {
|
|
156
|
+
throw new Error(`clientId '${id}' already identifies a live participant on this connection`);
|
|
157
|
+
}
|
|
158
|
+
const session = this.sessionFactory(
|
|
159
|
+
id,
|
|
160
|
+
{
|
|
161
|
+
connected: () => this.connected(),
|
|
162
|
+
reportError: (error, reported) => this.reportError(error, reported),
|
|
163
|
+
restoreDirty: event => {
|
|
164
|
+
if (this.dirtyStates.get(event.uri) !== event.dirty) {
|
|
165
|
+
this.deliverDirty(event);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
forgetDirty: uri => this.dirtyStates.delete(uri)
|
|
169
|
+
},
|
|
170
|
+
label
|
|
171
|
+
);
|
|
172
|
+
this.sessions.add(session);
|
|
173
|
+
// Subscribed before the session is handed out, so the id is free again
|
|
174
|
+
// on this connection by the time any caller's listener runs.
|
|
175
|
+
session.onDidDispose(() => this.sessions.delete(session));
|
|
176
|
+
// A failure reaches the session's own calls, which wait for the same
|
|
177
|
+
// registration; caught here only so it is not also reported unhandled.
|
|
178
|
+
session.connected().catch(() => undefined);
|
|
179
|
+
this.createSessionEmitter.fire(session);
|
|
180
|
+
return session;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The client, with its `onDocumentDirtyChanged` passing through
|
|
185
|
+
* {@link deliverDirty} first, so {@link dirtyStates} holds what the server
|
|
186
|
+
* told it. Every other bound method forwards to the client unchanged, and
|
|
187
|
+
* one the client lacks stays absent, so the binding still refuses it.
|
|
188
|
+
*/
|
|
189
|
+
protected override localTarget(): TClient {
|
|
190
|
+
const client = this.client as unknown as Record<string, unknown>;
|
|
191
|
+
if (typeof client.onDocumentDirtyChanged !== 'function') {
|
|
192
|
+
return this.client;
|
|
193
|
+
}
|
|
194
|
+
const target: Record<string, unknown> = {};
|
|
195
|
+
for (const name of this.clientMethods) {
|
|
196
|
+
const method: unknown = client[name];
|
|
197
|
+
if (typeof method === 'function') {
|
|
198
|
+
target[name] = (params: unknown): unknown => (method as (params: unknown) => unknown).call(client, params);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
target.onDocumentDirtyChanged = (event: TransferDocumentDirtyChangedEvent): void => this.deliverDirty(event);
|
|
202
|
+
return target as unknown as TClient;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Record `event` in {@link dirtyStates} and hand it to the client. */
|
|
206
|
+
protected deliverDirty(event: TransferDocumentDirtyChangedEvent): void {
|
|
207
|
+
this.dirtyStates.set(event.uri, event.dirty);
|
|
208
|
+
const client = this.client as unknown as Partial<Pick<DataClientProtocol<TTransfer>, 'onDocumentDirtyChanged'>>;
|
|
209
|
+
client.onDocumentDirtyChanged?.(event);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* After the transport dropped, reconnect on the next macrotask for the
|
|
214
|
+
* sessions with documents open, so they re-watch and follow their documents
|
|
215
|
+
* again without waiting for a call of their own; a session with nothing
|
|
216
|
+
* open restores on its next call. Nothing is scheduled once this connection
|
|
217
|
+
* is disposed, which drops its generation too.
|
|
218
|
+
*/
|
|
219
|
+
protected override dropGeneration(): void {
|
|
220
|
+
const dropped = this.generation !== undefined;
|
|
221
|
+
super.dropGeneration();
|
|
222
|
+
if (dropped && !this.disposed) {
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
if (!this.disposed) {
|
|
225
|
+
this.sessions.forEach(session => session.reconnect());
|
|
226
|
+
}
|
|
227
|
+
}, 0);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Sessions are detached rather than disposed: the server ends every session
|
|
233
|
+
* on a connection it sees close, so ending each one first sends requests
|
|
234
|
+
* over a connection this call is about to dispose.
|
|
235
|
+
*/
|
|
236
|
+
override dispose(): void {
|
|
237
|
+
for (const session of [...this.sessions]) {
|
|
238
|
+
session.detach();
|
|
239
|
+
}
|
|
240
|
+
// For a factory's session whose `detach` does not fire.
|
|
241
|
+
this.sessions.clear();
|
|
242
|
+
this.createSessionEmitter.dispose();
|
|
243
|
+
super.dispose();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A {@link DataConnection} that brings its own {@link DataEvents}, so a host
|
|
249
|
+
* with several interested parties does not have to supply one.
|
|
250
|
+
*
|
|
251
|
+
* **The client slot holds exactly one object, and that is why this exists.**
|
|
252
|
+
* `createRpcProxy` binds a single `localTarget`, and underneath a method name
|
|
253
|
+
* maps to one handler — a second registration replaces the first silently. So a
|
|
254
|
+
* properties panel and a tree cannot both be the client; one fan-out sits in the
|
|
255
|
+
* slot and both subscribe to it.
|
|
256
|
+
*
|
|
257
|
+
* Use {@link DataConnection} directly instead when the client is yours: an
|
|
258
|
+
* adopter service that implements the protocol plus its own methods, a single
|
|
259
|
+
* consumer that IS the client, or a request/response-only client that binds
|
|
260
|
+
* nothing.
|
|
261
|
+
*/
|
|
262
|
+
export class DataConnectionWithEvents<
|
|
263
|
+
TTransfer extends TransferElement,
|
|
264
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
|
|
265
|
+
> extends DataConnection<TTransfer, TServer, DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>> {
|
|
266
|
+
/** Server pushes, fanned out to as many local listeners as the host has. */
|
|
267
|
+
readonly events: DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>;
|
|
268
|
+
|
|
269
|
+
constructor(port: DataPort, options?: DataConnectionOptions<TTransfer, TServer>) {
|
|
270
|
+
// Built as a local because `this` is unavailable before `super`, then
|
|
271
|
+
// read back onto the field.
|
|
272
|
+
const events = new DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>();
|
|
273
|
+
super(port, events, options);
|
|
274
|
+
this.events = events;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Disposes the fan-out it created, which no caller else holds. */
|
|
278
|
+
override dispose(): void {
|
|
279
|
+
super.dispose();
|
|
280
|
+
this.events.dispose();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -8,7 +8,15 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { Emitter, type Event } from 'vscode-jsonrpc';
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
DataClientProtocol,
|
|
13
|
+
ProjectsChangedEvent,
|
|
14
|
+
TransferDocumentDeletedEvent,
|
|
15
|
+
TransferDocumentDirtyChangedEvent,
|
|
16
|
+
TransferDocumentSavedEvent,
|
|
17
|
+
TransferDocumentsBuiltEvent,
|
|
18
|
+
TransferDocumentUpdatedEvent
|
|
19
|
+
} from '../data';
|
|
12
20
|
import type { Project } from '../project';
|
|
13
21
|
import type { TransferDiagnostic } from '../transfer-diagnostic';
|
|
14
22
|
import type { TransferElement } from '../transfer-element';
|
|
@@ -40,12 +48,21 @@ export class DataEvents<
|
|
|
40
48
|
> implements DataClientProtocol<TTransfer, TDiagnostic, TProject> {
|
|
41
49
|
protected readonly documentUpdatedEmitter = new Emitter<TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>>();
|
|
42
50
|
protected readonly documentSavedEmitter = new Emitter<TransferDocumentSavedEvent<TTransfer, TDiagnostic>>();
|
|
51
|
+
protected readonly documentDirtyChangedEmitter = new Emitter<TransferDocumentDirtyChangedEvent>();
|
|
52
|
+
protected readonly documentDeletedEmitter = new Emitter<TransferDocumentDeletedEvent>();
|
|
53
|
+
protected readonly documentsBuiltEmitter = new Emitter<TransferDocumentsBuiltEvent>();
|
|
43
54
|
protected readonly projectsChangedEmitter = new Emitter<ProjectsChangedEvent<TProject>>();
|
|
44
55
|
|
|
45
56
|
/** A build-phase event for a watched document. Carries the originating `sourceClientId`. */
|
|
46
57
|
readonly onDidUpdateDocument: Event<TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>> = this.documentUpdatedEmitter.event;
|
|
47
58
|
/** A watched document was persisted to disk. */
|
|
48
59
|
readonly onDidSaveDocument: Event<TransferDocumentSavedEvent<TTransfer, TDiagnostic>> = this.documentSavedEmitter.event;
|
|
60
|
+
/** A watched document's text started or stopped differing from its file. */
|
|
61
|
+
readonly onDidChangeDocumentDirty: Event<TransferDocumentDirtyChangedEvent> = this.documentDirtyChangedEmitter.event;
|
|
62
|
+
/** A document's backing file was removed, watched or not. Any watch survives. */
|
|
63
|
+
readonly onDidDeleteDocument: Event<TransferDocumentDeletedEvent> = this.documentDeletedEmitter.event;
|
|
64
|
+
/** Documents built that nobody watches — re-read anything derived from them. */
|
|
65
|
+
readonly onDidBuildDocuments: Event<TransferDocumentsBuiltEvent> = this.documentsBuiltEmitter.event;
|
|
49
66
|
/** The project set changed. */
|
|
50
67
|
readonly onDidChangeProjects: Event<ProjectsChangedEvent<TProject>> = this.projectsChangedEmitter.event;
|
|
51
68
|
|
|
@@ -59,6 +76,18 @@ export class DataEvents<
|
|
|
59
76
|
this.documentSavedEmitter.fire(event);
|
|
60
77
|
}
|
|
61
78
|
|
|
79
|
+
onDocumentDirtyChanged(event: TransferDocumentDirtyChangedEvent): void {
|
|
80
|
+
this.documentDirtyChangedEmitter.fire(event);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
onDocumentDeleted(event: TransferDocumentDeletedEvent): void {
|
|
84
|
+
this.documentDeletedEmitter.fire(event);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void {
|
|
88
|
+
this.documentsBuiltEmitter.fire(event);
|
|
89
|
+
}
|
|
90
|
+
|
|
62
91
|
onProjectsChanged(event: ProjectsChangedEvent<TProject>): void {
|
|
63
92
|
this.projectsChangedEmitter.fire(event);
|
|
64
93
|
}
|
|
@@ -66,6 +95,9 @@ export class DataEvents<
|
|
|
66
95
|
dispose(): void {
|
|
67
96
|
this.documentUpdatedEmitter.dispose();
|
|
68
97
|
this.documentSavedEmitter.dispose();
|
|
98
|
+
this.documentDirtyChangedEmitter.dispose();
|
|
99
|
+
this.documentDeletedEmitter.dispose();
|
|
100
|
+
this.documentsBuiltEmitter.dispose();
|
|
69
101
|
this.projectsChangedEmitter.dispose();
|
|
70
102
|
}
|
|
71
103
|
}
|