@hydranium/protocol 1.0.0-next.210 → 1.0.0-next.213
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/lib/errors.d.ts +6 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +11 -2
- package/lib/errors.js.map +1 -1
- package/lib/rpc/bind-rpc-methods.d.ts +6 -2
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +17 -7
- package/lib/rpc/bind-rpc-methods.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/package.json +5 -5
- package/src/errors.ts +13 -2
- package/src/rpc/bind-rpc-methods.ts +18 -8
- package/src/rpc/index.ts +1 -0
- package/src/rpc/send-by-method-name.ts +140 -0
package/lib/errors.d.ts
CHANGED
|
@@ -196,6 +196,12 @@ export declare class ReservedClientIdError extends ResponseError<{
|
|
|
196
196
|
constructor(clientId: string);
|
|
197
197
|
get clientId(): string;
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Whether `error` is a `ResponseError` from any copy of `vscode-jsonrpc`. An
|
|
201
|
+
* install holds several copies, and `instanceof` recognises only its own. An
|
|
202
|
+
* error that merely carries an integer `code` has no `toJson`, and is not one.
|
|
203
|
+
*/
|
|
204
|
+
export declare function isResponseError(error: unknown): error is ResponseError<unknown>;
|
|
199
205
|
/**
|
|
200
206
|
* `error` as an instance of the typed error class its code names, with its
|
|
201
207
|
* message, data and stack kept, or `error` itself when its code names none or
|
package/lib/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.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GAAG,KAAK,IAAI,kBAAkB,CAEhF;AAED,2FAA2F;AAC3F,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAEpF;AAED,6FAA6F;AAC7F,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CAExF;AAED,4FAA4F;AAC5F,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAEtF;AAWD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAYtE"}
|
package/lib/errors.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.ReservedClientIdError = exports.DuplicateClientIdError = exports.DUPLICATE_CLIENT_ID = exports.DocumentNotOpenError = exports.DOCUMENT_NOT_OPEN = exports.SessionClosedError = exports.SESSION_CLOSED = exports.RESERVED_CLIENT_ID_ERROR_CODE = exports.DUPLICATE_CLIENT_ID_ERROR_CODE = exports.DOCUMENT_NOT_OPEN_ERROR_CODE = exports.SESSION_CLOSED_ERROR_CODE = exports.ConflictError = exports.CONFLICT_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES = exports.STALE_BASE_VERSION_UPDATE = void 0;
|
|
12
|
+
exports.isResponseError = isResponseError;
|
|
12
13
|
exports.reviveProtocolError = reviveProtocolError;
|
|
13
14
|
exports.isSessionClosedError = isSessionClosedError;
|
|
14
15
|
exports.isDocumentNotOpenError = isDocumentNotOpenError;
|
|
@@ -269,6 +270,14 @@ const PROTOCOL_ERROR_REVIVERS = new Map([
|
|
|
269
270
|
[exports.DUPLICATE_CLIENT_ID_ERROR_CODE, ({ clientId }) => (typeof clientId === 'string' ? new DuplicateClientIdError(clientId) : undefined)],
|
|
270
271
|
[exports.RESERVED_CLIENT_ID_ERROR_CODE, ({ clientId }) => (typeof clientId === 'string' ? new ReservedClientIdError(clientId) : undefined)]
|
|
271
272
|
]);
|
|
273
|
+
/**
|
|
274
|
+
* Whether `error` is a `ResponseError` from any copy of `vscode-jsonrpc`. An
|
|
275
|
+
* install holds several copies, and `instanceof` recognises only its own. An
|
|
276
|
+
* error that merely carries an integer `code` has no `toJson`, and is not one.
|
|
277
|
+
*/
|
|
278
|
+
function isResponseError(error) {
|
|
279
|
+
return (error instanceof Error && 'code' in error && Number.isInteger(error.code) && 'toJson' in error && typeof error.toJson === 'function');
|
|
280
|
+
}
|
|
272
281
|
/**
|
|
273
282
|
* `error` as an instance of the typed error class its code names, with its
|
|
274
283
|
* message, data and stack kept, or `error` itself when its code names none or
|
|
@@ -277,10 +286,10 @@ const PROTOCOL_ERROR_REVIVERS = new Map([
|
|
|
277
286
|
* none of the class getters.
|
|
278
287
|
*/
|
|
279
288
|
function reviveProtocolError(error) {
|
|
280
|
-
if (!(error
|
|
289
|
+
if (!isResponseError(error) || error.data === null || typeof error.data !== 'object') {
|
|
281
290
|
return error;
|
|
282
291
|
}
|
|
283
|
-
const revived = PROTOCOL_ERROR_REVIVERS.get(error.code)?.(error.data);
|
|
292
|
+
const revived = PROTOCOL_ERROR_REVIVERS.get(error.code)?.({ ...error.data });
|
|
284
293
|
if (!revived) {
|
|
285
294
|
return error;
|
|
286
295
|
}
|
package/lib/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;AAElF,mDAA+C;AAC/C,sDAA8F;AAC9F,+DAAmG;AAEnG;;;;;;;;;;GAUG;AAEH;;;;;;;;;GASG;AACU,QAAA,yBAAyB,GAAG,IAAA,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CAAC,CAAC;AAC5F,CAAC;AAED,4FAA4F;AAC5F,iCAAwC,KAAc;IACnD,OAAO,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,EAAE,QAAA,6BAA6B,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,IAAY,EAAE,IAAY;IACjE,OAAO,KAAK,YAAY,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,IAAK,KAAyC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACtH,CAAC;AAED;;mCAEmC;AACnC,MAAM,6BAA6B,GAAG,mDAAmD,CAAC;AAE1F;;;;;;;;;;;;;;;GAeG;AACH,yBAAgC,KAAc;IAC3C,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAI,KAAyC,CAAC,IAAI,CAAC;IAC7D,IAAI,IAAI,KAAK,QAAA,mBAAmB,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACf,CAAC;IACD,OAAO,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAAC;AACrG,CAAC"}
|
|
@@ -106,8 +106,12 @@ export interface BindRpcMethodsOptions {
|
|
|
106
106
|
*
|
|
107
107
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
108
108
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
109
|
-
* standard error envelope,
|
|
110
|
-
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied.
|
|
109
|
+
* standard error envelope, its message rendered when
|
|
110
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. A
|
|
111
|
+
* `ResponseError` from another copy of `vscode-jsonrpc` is rebuilt on this
|
|
112
|
+
* package's copy, so its code and data reach the caller when `connection` comes
|
|
113
|
+
* from that copy too, as the framework's own connections do; over a connection
|
|
114
|
+
* from another copy the caller receives a generic `InternalError`. Errors from a
|
|
111
115
|
* notification handler cannot propagate, and are routed to
|
|
112
116
|
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
113
117
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-rpc-methods.d.ts","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"bind-rpc-methods.d.ts","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,KAAK,UAAU,EAAwB,MAAM,SAAS,CAAC;AAIhE;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACnC;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAElC;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IAE1D;;;;;;;;;OASG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAE1E;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC;CAC1E;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC5C,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,EAC1D,MAAM,EAAE,CAAC,EACT,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EAC1C,OAAO,GAAE,qBAA0B,GACnC,UAAU,CA6EZ"}
|
|
@@ -10,12 +10,21 @@
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.bindRpcMethods = bindRpcMethods;
|
|
12
12
|
const vscode_jsonrpc_1 = require("vscode-jsonrpc");
|
|
13
|
+
const errors_1 = require("../errors");
|
|
13
14
|
const util_1 = require("../util");
|
|
14
15
|
const create_rpc_proxy_1 = require("./create-rpc-proxy");
|
|
15
16
|
const wire_prefix_1 = require("./wire-prefix");
|
|
16
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* The rejection to throw in place of `err`. A `ResponseError` from another copy
|
|
19
|
+
* of `vscode-jsonrpc` is rebuilt on this package's, since a connection keeps the
|
|
20
|
+
* code only of its own copy's errors; one from this copy is thrown as is, so a
|
|
21
|
+
* subclass keeps its `toJson`, unless `render` rewrites its message.
|
|
22
|
+
*/
|
|
17
23
|
function renderRejection(err, render) {
|
|
18
|
-
|
|
24
|
+
if (!(0, errors_1.isResponseError)(err) || (!render && err instanceof vscode_jsonrpc_1.ResponseError)) {
|
|
25
|
+
return err;
|
|
26
|
+
}
|
|
27
|
+
return new vscode_jsonrpc_1.ResponseError(err.code, render ? render(err) : err.message, err.data);
|
|
19
28
|
}
|
|
20
29
|
/**
|
|
21
30
|
* Register each named method on `target` as a handler on `connection`
|
|
@@ -36,8 +45,12 @@ function renderRejection(err, render) {
|
|
|
36
45
|
*
|
|
37
46
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
38
47
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
39
|
-
* standard error envelope,
|
|
40
|
-
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied.
|
|
48
|
+
* standard error envelope, its message rendered when
|
|
49
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. A
|
|
50
|
+
* `ResponseError` from another copy of `vscode-jsonrpc` is rebuilt on this
|
|
51
|
+
* package's copy, so its code and data reach the caller when `connection` comes
|
|
52
|
+
* from that copy too, as the framework's own connections do; over a connection
|
|
53
|
+
* from another copy the caller receives a generic `InternalError`. Errors from a
|
|
41
54
|
* notification handler cannot propagate, and are routed to
|
|
42
55
|
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
43
56
|
*
|
|
@@ -93,9 +106,6 @@ function bindRpcMethods(connection, target, methodNames, options = {}) {
|
|
|
93
106
|
else {
|
|
94
107
|
const render = options.renderErrorMessage;
|
|
95
108
|
disposables.push(resolved.onRequest(wireName, async (params) => {
|
|
96
|
-
if (!render) {
|
|
97
|
-
return dispatch(params);
|
|
98
|
-
}
|
|
99
109
|
try {
|
|
100
110
|
// Awaited inside the try, or a rejected promise escapes it.
|
|
101
111
|
return await dispatch(params);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-rpc-methods.js","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,mDAAuE;
|
|
1
|
+
{"version":3,"file":"bind-rpc-methods.js","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,mDAAuE;AACvE,sCAA4C;AAE5C,kCAAgE;AAChE,yDAA2D;AAC3D,+CAA2D;AAsF3D;;;;;GA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ACrB,MAAM,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;oBACtC,CAAC;gBACJ,CAAC,CAAC,CACJ,CAAC;YACL,CAAC;QACJ,CAAC;IACJ,CAAC,CAAC;IAEF,IAAI,UAAU,YAAY,OAAO,EAAE,CAAC;QACjC,KAAK,UAAU;aACX,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;aAClC,KAAK,CAAC,GAAG,EAAE;YACT,iEAAiE;YACjE,iEAAiE;YACjE,8CAA8C;QACjD,CAAC,CAAC,CAAC;IACT,CAAC;SAAM,CAAC;QACL,MAAM,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED,OAAO;QACJ,OAAO;YACJ,SAAS,GAAG,IAAI,CAAC;YACjB,WAAW,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;KACH,CAAC;AACL,CAAC"}
|
package/lib/rpc/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
export * from './bind-rpc-methods';
|
|
10
10
|
export * from './create-rpc-proxy';
|
|
11
|
+
export * from './send-by-method-name';
|
|
11
12
|
export * from './wire-prefix';
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/rpc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rpc/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAMlF,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rpc/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAMlF,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC"}
|
package/lib/rpc/index.js
CHANGED
|
@@ -27,5 +27,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
27
27
|
// specialised composition.
|
|
28
28
|
__exportStar(require("./bind-rpc-methods"), exports);
|
|
29
29
|
__exportStar(require("./create-rpc-proxy"), exports);
|
|
30
|
+
__exportStar(require("./send-by-method-name"), exports);
|
|
30
31
|
__exportStar(require("./wire-prefix"), exports);
|
|
31
32
|
//# sourceMappingURL=index.js.map
|
package/lib/rpc/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rpc/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kEAAkE;AAClE,+DAA+D;AAC/D,2BAA2B;AAE3B,qDAAmC;AACnC,qDAAmC;AACnC,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rpc/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kEAAkE;AAClE,+DAA+D;AAC/D,2BAA2B;AAE3B,qDAAmC;AACnC,qDAAmC;AACnC,wDAAsC;AACtC,gDAA8B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
* `connection` with `sendRequest` and `sendNotification` sending a typed message
|
|
11
|
+
* by its method name, so it survives a message type built by another copy of
|
|
12
|
+
* `vscode-jsonrpc`. Wrap a connection wherever it is handed to code that sends
|
|
13
|
+
* another copy's typed messages, GLSP's clients and launchers in particular.
|
|
14
|
+
*
|
|
15
|
+
* **Why an install holds several copies.** Upstream pins exactly:
|
|
16
|
+
* - `@eclipse-glsp/*` 2.x pin `vscode-jsonrpc` `8.2.0`, and npm can nest a copy
|
|
17
|
+
* under each GLSP package, so GLSP's packages can split from each other: a
|
|
18
|
+
* connection one of them creates rejects the typed messages another builds.
|
|
19
|
+
* GLSP's upgrade to 9.x, which could let it share the framework's copy, is
|
|
20
|
+
* open as https://github.com/eclipse-glsp/glsp/issues/1720.
|
|
21
|
+
* - `vscode-languageserver@10.0.1` pins `vscode-languageserver-protocol`
|
|
22
|
+
* `3.18.1`, which pins `vscode-jsonrpc` `9.0.0`.
|
|
23
|
+
* - Theia brings protocol `3.17.5` and with it `vscode-jsonrpc` 8.
|
|
24
|
+
*
|
|
25
|
+
* npm hoists one version per name and nests the rest. `overrides` are read from
|
|
26
|
+
* the root manifest alone and never ship with a package, so the framework cannot
|
|
27
|
+
* collapse an adopter's tree.
|
|
28
|
+
*
|
|
29
|
+
* **What breaks across copies.**
|
|
30
|
+
* - Sending: a connection compares a typed message's parameter structure with
|
|
31
|
+
* its own copy's `ParameterStructures.auto` singleton by identity, so a
|
|
32
|
+
* `RequestType` or `NotificationType` built by another copy throws
|
|
33
|
+
* `Unknown parameter structure auto`. GLSP sends typed messages, in
|
|
34
|
+
* `BaseJsonrpcGLSPClient` and in `JsonrpcClientProxy.process`.
|
|
35
|
+
* `vscode-languageserver`'s connection resends by method name already, which
|
|
36
|
+
* is why LSP sends are unaffected.
|
|
37
|
+
* - Types: `ParameterStructures` has a private member, so TypeScript treats each
|
|
38
|
+
* copy's `MessageConnection` as a different type.
|
|
39
|
+
* - Errors: a connection keeps a thrown `ResponseError`'s code and data only
|
|
40
|
+
* when the error is an instance of its own copy's class, and sends a returned
|
|
41
|
+
* one of another copy as a successful result.
|
|
42
|
+
*
|
|
43
|
+
* **What is copy-safe.** Receiving a typed message from another copy, since the
|
|
44
|
+
* receive path compares only against its own `byName` and `byPosition`. With
|
|
45
|
+
* sends by method name, the LSP, data and GLSP heads run over a tree whose GLSP
|
|
46
|
+
* packages keep `vscode-jsonrpc` `8.2.0`.
|
|
47
|
+
*
|
|
48
|
+
* **How it works.** A `Proxy` whose `sendRequest` and `sendNotification` pass the
|
|
49
|
+
* typed message's `method` string; every other member is the connection's own.
|
|
50
|
+
* The parameters go out as the typed send packs them: the first
|
|
51
|
+
* `numberOfParams`, missing ones `null`, and a request's cancellation token
|
|
52
|
+
* from the position after them. Sent by method name, a single parameter goes by
|
|
53
|
+
* name when it is an object and by position otherwise, which matches `auto` and
|
|
54
|
+
* `byName` with an object, as `vscode-languageserver-protocol`'s types use it. A
|
|
55
|
+
* `byPosition` object or a `byName` non-object throws rather than going out in
|
|
56
|
+
* another shape, the packing read from the type's `toString()` since it cannot
|
|
57
|
+
* be compared by identity. So wrapping narrows what a connection accepts: its
|
|
58
|
+
* own copy sends such a type unwrapped. The result is typed as whichever copy's
|
|
59
|
+
* connection its context expects, or as `connection`'s own type without one.
|
|
60
|
+
* That type is the caller's assertion: it holds for the members both copies
|
|
61
|
+
* share, since the sends go by name and the receives are copy-safe.
|
|
62
|
+
*
|
|
63
|
+
* **Where it stops.** Errors: a rejection it produces is still its own copy's
|
|
64
|
+
* `ResponseError`, so recognise errors with `isResponseError`, and build a
|
|
65
|
+
* connection whose errors must keep their code from the framework's copy.
|
|
66
|
+
*
|
|
67
|
+
* See https://github.com/eclipse-emfcloud/hydranium/issues/279.
|
|
68
|
+
*/
|
|
69
|
+
export declare function sendByMethodName<In extends {
|
|
70
|
+
sendRequest<R>(method: string, ...params: unknown[]): Promise<R>;
|
|
71
|
+
sendNotification(method: string, ...params: unknown[]): Promise<void>;
|
|
72
|
+
}, Out extends {
|
|
73
|
+
sendRequest<R>(method: string, ...params: unknown[]): Promise<R>;
|
|
74
|
+
sendNotification(method: string, ...params: unknown[]): Promise<void>;
|
|
75
|
+
} = In>(connection: In): Out;
|
|
76
|
+
//# sourceMappingURL=send-by-method-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-by-method-name.d.ts","sourceRoot":"","sources":["../../src/rpc/send-by-method-name.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAIlF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,wBAAgB,gBAAgB,CAC7B,EAAE,SAAS;IACR,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE,EACD,GAAG,SAAS;IACT,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE,GAAG,EAAE,EACP,UAAU,EAAE,EAAE,GAAG,GAAG,CAsBrB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
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.sendByMethodName = sendByMethodName;
|
|
12
|
+
const vscode_jsonrpc_1 = require("vscode-jsonrpc");
|
|
13
|
+
/**
|
|
14
|
+
* `connection` with `sendRequest` and `sendNotification` sending a typed message
|
|
15
|
+
* by its method name, so it survives a message type built by another copy of
|
|
16
|
+
* `vscode-jsonrpc`. Wrap a connection wherever it is handed to code that sends
|
|
17
|
+
* another copy's typed messages, GLSP's clients and launchers in particular.
|
|
18
|
+
*
|
|
19
|
+
* **Why an install holds several copies.** Upstream pins exactly:
|
|
20
|
+
* - `@eclipse-glsp/*` 2.x pin `vscode-jsonrpc` `8.2.0`, and npm can nest a copy
|
|
21
|
+
* under each GLSP package, so GLSP's packages can split from each other: a
|
|
22
|
+
* connection one of them creates rejects the typed messages another builds.
|
|
23
|
+
* GLSP's upgrade to 9.x, which could let it share the framework's copy, is
|
|
24
|
+
* open as https://github.com/eclipse-glsp/glsp/issues/1720.
|
|
25
|
+
* - `vscode-languageserver@10.0.1` pins `vscode-languageserver-protocol`
|
|
26
|
+
* `3.18.1`, which pins `vscode-jsonrpc` `9.0.0`.
|
|
27
|
+
* - Theia brings protocol `3.17.5` and with it `vscode-jsonrpc` 8.
|
|
28
|
+
*
|
|
29
|
+
* npm hoists one version per name and nests the rest. `overrides` are read from
|
|
30
|
+
* the root manifest alone and never ship with a package, so the framework cannot
|
|
31
|
+
* collapse an adopter's tree.
|
|
32
|
+
*
|
|
33
|
+
* **What breaks across copies.**
|
|
34
|
+
* - Sending: a connection compares a typed message's parameter structure with
|
|
35
|
+
* its own copy's `ParameterStructures.auto` singleton by identity, so a
|
|
36
|
+
* `RequestType` or `NotificationType` built by another copy throws
|
|
37
|
+
* `Unknown parameter structure auto`. GLSP sends typed messages, in
|
|
38
|
+
* `BaseJsonrpcGLSPClient` and in `JsonrpcClientProxy.process`.
|
|
39
|
+
* `vscode-languageserver`'s connection resends by method name already, which
|
|
40
|
+
* is why LSP sends are unaffected.
|
|
41
|
+
* - Types: `ParameterStructures` has a private member, so TypeScript treats each
|
|
42
|
+
* copy's `MessageConnection` as a different type.
|
|
43
|
+
* - Errors: a connection keeps a thrown `ResponseError`'s code and data only
|
|
44
|
+
* when the error is an instance of its own copy's class, and sends a returned
|
|
45
|
+
* one of another copy as a successful result.
|
|
46
|
+
*
|
|
47
|
+
* **What is copy-safe.** Receiving a typed message from another copy, since the
|
|
48
|
+
* receive path compares only against its own `byName` and `byPosition`. With
|
|
49
|
+
* sends by method name, the LSP, data and GLSP heads run over a tree whose GLSP
|
|
50
|
+
* packages keep `vscode-jsonrpc` `8.2.0`.
|
|
51
|
+
*
|
|
52
|
+
* **How it works.** A `Proxy` whose `sendRequest` and `sendNotification` pass the
|
|
53
|
+
* typed message's `method` string; every other member is the connection's own.
|
|
54
|
+
* The parameters go out as the typed send packs them: the first
|
|
55
|
+
* `numberOfParams`, missing ones `null`, and a request's cancellation token
|
|
56
|
+
* from the position after them. Sent by method name, a single parameter goes by
|
|
57
|
+
* name when it is an object and by position otherwise, which matches `auto` and
|
|
58
|
+
* `byName` with an object, as `vscode-languageserver-protocol`'s types use it. A
|
|
59
|
+
* `byPosition` object or a `byName` non-object throws rather than going out in
|
|
60
|
+
* another shape, the packing read from the type's `toString()` since it cannot
|
|
61
|
+
* be compared by identity. So wrapping narrows what a connection accepts: its
|
|
62
|
+
* own copy sends such a type unwrapped. The result is typed as whichever copy's
|
|
63
|
+
* connection its context expects, or as `connection`'s own type without one.
|
|
64
|
+
* That type is the caller's assertion: it holds for the members both copies
|
|
65
|
+
* share, since the sends go by name and the receives are copy-safe.
|
|
66
|
+
*
|
|
67
|
+
* **Where it stops.** Errors: a rejection it produces is still its own copy's
|
|
68
|
+
* `ResponseError`, so recognise errors with `isResponseError`, and build a
|
|
69
|
+
* connection whose errors must keep their code from the framework's copy.
|
|
70
|
+
*
|
|
71
|
+
* See https://github.com/eclipse-emfcloud/hydranium/issues/279.
|
|
72
|
+
*/
|
|
73
|
+
function sendByMethodName(connection) {
|
|
74
|
+
const sendRequest = (type, ...params) => typeof type === 'string'
|
|
75
|
+
? connection.sendRequest(type, ...params)
|
|
76
|
+
: connection.sendRequest(type.method, ...argsOf(type, params, true));
|
|
77
|
+
const sendNotification = (type, ...params) => typeof type === 'string'
|
|
78
|
+
? connection.sendNotification(type, ...params)
|
|
79
|
+
: connection.sendNotification(type.method, ...argsOf(type, params, false));
|
|
80
|
+
const wrapped = new Proxy(connection, {
|
|
81
|
+
get(target, property, receiver) {
|
|
82
|
+
if (property === 'sendRequest') {
|
|
83
|
+
return sendRequest;
|
|
84
|
+
}
|
|
85
|
+
if (property === 'sendNotification') {
|
|
86
|
+
return sendNotification;
|
|
87
|
+
}
|
|
88
|
+
return Reflect.get(target, property, receiver);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
// Typed as the connection its context expects, which the doc above justifies.
|
|
92
|
+
return wrapped;
|
|
93
|
+
}
|
|
94
|
+
/** Whether `vscode-jsonrpc` sends `param` by name under `auto`. */
|
|
95
|
+
function isNamedParam(param) {
|
|
96
|
+
return param !== undefined && param !== null && !Array.isArray(param) && typeof param === 'object';
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The arguments that send `type` by method name with the typed send's params:
|
|
100
|
+
* the first `numberOfParams` of `params`, missing ones `null`, then a request's
|
|
101
|
+
* cancellation token, which the typed send takes from that position. A request
|
|
102
|
+
* always ends in a token, `CancellationToken.None` when it has none, since a
|
|
103
|
+
* send by method name takes a token-shaped last argument for its token. Throws
|
|
104
|
+
* for the one-parameter packing a send by method name cannot express.
|
|
105
|
+
*/
|
|
106
|
+
function argsOf(type, params, isRequest) {
|
|
107
|
+
const args = Array.from({ length: type.numberOfParams }, (_, i) => (i < params.length ? params[i] : null));
|
|
108
|
+
if (type.numberOfParams === 1) {
|
|
109
|
+
const packing = String(type.parameterStructures);
|
|
110
|
+
if ((packing === 'byPosition' && isNamedParam(args[0])) || (packing === 'byName' && !isNamedParam(args[0]))) {
|
|
111
|
+
throw new Error(`sendByMethodName cannot send '${type.method}' ${packing}: by method name, a single object goes by name and anything else by position.`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!isRequest) {
|
|
115
|
+
return args;
|
|
116
|
+
}
|
|
117
|
+
const token = params[type.numberOfParams];
|
|
118
|
+
return [...args, vscode_jsonrpc_1.CancellationToken.is(token) ? token : vscode_jsonrpc_1.CancellationToken.None];
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=send-by-method-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-by-method-name.js","sourceRoot":"","sources":["../../src/rpc/send-by-method-name.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,mDAAmD;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,0BASE,UAAc;IACb,MAAM,WAAW,GAAG,CAAC,IAA2B,EAAE,GAAG,MAAiB,EAAE,EAAE,CACvE,OAAO,IAAI,KAAK,QAAQ;QACrB,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC;QACzC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3E,MAAM,gBAAgB,GAAG,CAAC,IAA2B,EAAE,GAAG,MAAiB,EAAE,EAAE,CAC5E,OAAO,IAAI,KAAK,QAAQ;QACrB,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC;QAC9C,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACjF,MAAM,OAAO,GAAiD,IAAI,KAAK,CAAC,UAAU,EAAE;QACjF,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ;YAC3B,IAAI,QAAQ,KAAK,aAAa,EAAE,CAAC;gBAC9B,OAAO,WAAW,CAAC;YACtB,CAAC;YACD,IAAI,QAAQ,KAAK,kBAAkB,EAAE,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C;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,IAAI,EAAE,kCAAiB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,kCAAiB,CAAC,IAAI,CAAC,CAAC;AAClF,CAAC"}
|
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.213",
|
|
4
4
|
"description": "Generic, language-agnostic types, constants, and pure utilities for the hydranium framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hydranium",
|
|
@@ -104,14 +104,14 @@
|
|
|
104
104
|
"fast-check": "^3.23.2",
|
|
105
105
|
"rimraf": "^5.0.0",
|
|
106
106
|
"typescript": "^7.0.2",
|
|
107
|
-
"vscode-jsonrpc": "9.0.
|
|
107
|
+
"vscode-jsonrpc": "9.0.0"
|
|
108
108
|
},
|
|
109
109
|
"peerDependencies": {
|
|
110
|
-
"vscode-jsonrpc": "9.0.
|
|
110
|
+
"vscode-jsonrpc": "^9.0.0"
|
|
111
111
|
},
|
|
112
112
|
"engines": {
|
|
113
113
|
"node": ">=22.13"
|
|
114
114
|
},
|
|
115
|
-
"//peerDependencies": "`vscode-jsonrpc`
|
|
116
|
-
"//prepack": "The publish guard,
|
|
115
|
+
"//peerDependencies": "`vscode-jsonrpc` takes a caret, so the framework shares the transport the LSP connection resolves, which an `init` scaffold pins: each `vscode-languageserver-protocol` release pins its transport exactly, so an exact peer would name a copy a fresh install rarely holds. The caret excludes 8.x, so a tree whose top holds GLSP's copy fails the peer with a named ERESOLVE warning, an error under `--strict-peer-deps`, rather than resolving silently. No peer reaches a NESTED copy, such as GLSP's or one the LSP packages nest; docs/adopting/requirements.md has the chain. The wire compares message types and `ResponseError`s by copy identity, so the framework sends typed messages by method name and recognises errors with `isResponseError` rather than `instanceof`.",
|
|
116
|
+
"//prepack": "The publish guard, a `prepack` rather than a `prepare`: `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. 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."
|
|
117
117
|
}
|
package/src/errors.ts
CHANGED
|
@@ -320,6 +320,17 @@ const PROTOCOL_ERROR_REVIVERS: ReadonlyMap<number, ProtocolErrorReviver> = new M
|
|
|
320
320
|
[RESERVED_CLIENT_ID_ERROR_CODE, ({ clientId }) => (typeof clientId === 'string' ? new ReservedClientIdError(clientId) : undefined)]
|
|
321
321
|
]);
|
|
322
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Whether `error` is a `ResponseError` from any copy of `vscode-jsonrpc`. An
|
|
325
|
+
* install holds several copies, and `instanceof` recognises only its own. An
|
|
326
|
+
* error that merely carries an integer `code` has no `toJson`, and is not one.
|
|
327
|
+
*/
|
|
328
|
+
export function isResponseError(error: unknown): error is ResponseError<unknown> {
|
|
329
|
+
return (
|
|
330
|
+
error instanceof Error && 'code' in error && Number.isInteger(error.code) && 'toJson' in error && typeof error.toJson === 'function'
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
323
334
|
/**
|
|
324
335
|
* `error` as an instance of the typed error class its code names, with its
|
|
325
336
|
* message, data and stack kept, or `error` itself when its code names none or
|
|
@@ -328,10 +339,10 @@ const PROTOCOL_ERROR_REVIVERS: ReadonlyMap<number, ProtocolErrorReviver> = new M
|
|
|
328
339
|
* none of the class getters.
|
|
329
340
|
*/
|
|
330
341
|
export function reviveProtocolError(error: unknown): unknown {
|
|
331
|
-
if (!(error
|
|
342
|
+
if (!isResponseError(error) || error.data === null || typeof error.data !== 'object') {
|
|
332
343
|
return error;
|
|
333
344
|
}
|
|
334
|
-
const revived = PROTOCOL_ERROR_REVIVERS.get(error.code)?.(error.data);
|
|
345
|
+
const revived = PROTOCOL_ERROR_REVIVERS.get(error.code)?.({ ...error.data });
|
|
335
346
|
if (!revived) {
|
|
336
347
|
return error;
|
|
337
348
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { ResponseError, type MessageConnection } from 'vscode-jsonrpc';
|
|
11
|
+
import { isResponseError } from '../errors';
|
|
11
12
|
import type { LatencyCollector } from '../latency-collector';
|
|
12
13
|
import { type Disposable, DisposableCollection } from '../util';
|
|
13
14
|
import { defaultIsNotification } from './create-rpc-proxy';
|
|
@@ -97,9 +98,17 @@ export interface BindRpcMethodsOptions {
|
|
|
97
98
|
readonly renderErrorMessage?: (error: ResponseError<unknown>) => string;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
/**
|
|
102
|
+
* The rejection to throw in place of `err`. A `ResponseError` from another copy
|
|
103
|
+
* of `vscode-jsonrpc` is rebuilt on this package's, since a connection keeps the
|
|
104
|
+
* code only of its own copy's errors; one from this copy is thrown as is, so a
|
|
105
|
+
* subclass keeps its `toJson`, unless `render` rewrites its message.
|
|
106
|
+
*/
|
|
107
|
+
function renderRejection(err: unknown, render?: (error: ResponseError<unknown>) => string): unknown {
|
|
108
|
+
if (!isResponseError(err) || (!render && err instanceof ResponseError)) {
|
|
109
|
+
return err;
|
|
110
|
+
}
|
|
111
|
+
return new ResponseError(err.code, render ? render(err) : err.message, err.data);
|
|
103
112
|
}
|
|
104
113
|
|
|
105
114
|
/**
|
|
@@ -121,8 +130,12 @@ function renderRejection(err: unknown, render: (error: ResponseError<unknown>) =
|
|
|
121
130
|
*
|
|
122
131
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
123
132
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
124
|
-
* standard error envelope,
|
|
125
|
-
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied.
|
|
133
|
+
* standard error envelope, its message rendered when
|
|
134
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. A
|
|
135
|
+
* `ResponseError` from another copy of `vscode-jsonrpc` is rebuilt on this
|
|
136
|
+
* package's copy, so its code and data reach the caller when `connection` comes
|
|
137
|
+
* from that copy too, as the framework's own connections do; over a connection
|
|
138
|
+
* from another copy the caller receives a generic `InternalError`. Errors from a
|
|
126
139
|
* notification handler cannot propagate, and are routed to
|
|
127
140
|
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
128
141
|
*
|
|
@@ -189,9 +202,6 @@ export function bindRpcMethods<T extends object>(
|
|
|
189
202
|
const render = options.renderErrorMessage;
|
|
190
203
|
disposables.push(
|
|
191
204
|
resolved.onRequest(wireName, async (params: unknown) => {
|
|
192
|
-
if (!render) {
|
|
193
|
-
return dispatch(params);
|
|
194
|
-
}
|
|
195
205
|
try {
|
|
196
206
|
// Awaited inside the try, or a rejected promise escapes it.
|
|
197
207
|
return await dispatch(params);
|
package/src/rpc/index.ts
CHANGED
|
@@ -0,0 +1,140 @@
|
|
|
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 { CancellationToken } from 'vscode-jsonrpc';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `connection` with `sendRequest` and `sendNotification` sending a typed message
|
|
14
|
+
* by its method name, so it survives a message type built by another copy of
|
|
15
|
+
* `vscode-jsonrpc`. Wrap a connection wherever it is handed to code that sends
|
|
16
|
+
* another copy's typed messages, GLSP's clients and launchers in particular.
|
|
17
|
+
*
|
|
18
|
+
* **Why an install holds several copies.** Upstream pins exactly:
|
|
19
|
+
* - `@eclipse-glsp/*` 2.x pin `vscode-jsonrpc` `8.2.0`, and npm can nest a copy
|
|
20
|
+
* under each GLSP package, so GLSP's packages can split from each other: a
|
|
21
|
+
* connection one of them creates rejects the typed messages another builds.
|
|
22
|
+
* GLSP's upgrade to 9.x, which could let it share the framework's copy, is
|
|
23
|
+
* open as https://github.com/eclipse-glsp/glsp/issues/1720.
|
|
24
|
+
* - `vscode-languageserver@10.0.1` pins `vscode-languageserver-protocol`
|
|
25
|
+
* `3.18.1`, which pins `vscode-jsonrpc` `9.0.0`.
|
|
26
|
+
* - Theia brings protocol `3.17.5` and with it `vscode-jsonrpc` 8.
|
|
27
|
+
*
|
|
28
|
+
* npm hoists one version per name and nests the rest. `overrides` are read from
|
|
29
|
+
* the root manifest alone and never ship with a package, so the framework cannot
|
|
30
|
+
* collapse an adopter's tree.
|
|
31
|
+
*
|
|
32
|
+
* **What breaks across copies.**
|
|
33
|
+
* - Sending: a connection compares a typed message's parameter structure with
|
|
34
|
+
* its own copy's `ParameterStructures.auto` singleton by identity, so a
|
|
35
|
+
* `RequestType` or `NotificationType` built by another copy throws
|
|
36
|
+
* `Unknown parameter structure auto`. GLSP sends typed messages, in
|
|
37
|
+
* `BaseJsonrpcGLSPClient` and in `JsonrpcClientProxy.process`.
|
|
38
|
+
* `vscode-languageserver`'s connection resends by method name already, which
|
|
39
|
+
* is why LSP sends are unaffected.
|
|
40
|
+
* - Types: `ParameterStructures` has a private member, so TypeScript treats each
|
|
41
|
+
* copy's `MessageConnection` as a different type.
|
|
42
|
+
* - Errors: a connection keeps a thrown `ResponseError`'s code and data only
|
|
43
|
+
* when the error is an instance of its own copy's class, and sends a returned
|
|
44
|
+
* one of another copy as a successful result.
|
|
45
|
+
*
|
|
46
|
+
* **What is copy-safe.** Receiving a typed message from another copy, since the
|
|
47
|
+
* receive path compares only against its own `byName` and `byPosition`. With
|
|
48
|
+
* sends by method name, the LSP, data and GLSP heads run over a tree whose GLSP
|
|
49
|
+
* packages keep `vscode-jsonrpc` `8.2.0`.
|
|
50
|
+
*
|
|
51
|
+
* **How it works.** A `Proxy` whose `sendRequest` and `sendNotification` pass the
|
|
52
|
+
* typed message's `method` string; every other member is the connection's own.
|
|
53
|
+
* The parameters go out as the typed send packs them: the first
|
|
54
|
+
* `numberOfParams`, missing ones `null`, and a request's cancellation token
|
|
55
|
+
* from the position after them. Sent by method name, a single parameter goes by
|
|
56
|
+
* name when it is an object and by position otherwise, which matches `auto` and
|
|
57
|
+
* `byName` with an object, as `vscode-languageserver-protocol`'s types use it. A
|
|
58
|
+
* `byPosition` object or a `byName` non-object throws rather than going out in
|
|
59
|
+
* another shape, the packing read from the type's `toString()` since it cannot
|
|
60
|
+
* be compared by identity. So wrapping narrows what a connection accepts: its
|
|
61
|
+
* own copy sends such a type unwrapped. The result is typed as whichever copy's
|
|
62
|
+
* connection its context expects, or as `connection`'s own type without one.
|
|
63
|
+
* That type is the caller's assertion: it holds for the members both copies
|
|
64
|
+
* share, since the sends go by name and the receives are copy-safe.
|
|
65
|
+
*
|
|
66
|
+
* **Where it stops.** Errors: a rejection it produces is still its own copy's
|
|
67
|
+
* `ResponseError`, so recognise errors with `isResponseError`, and build a
|
|
68
|
+
* connection whose errors must keep their code from the framework's copy.
|
|
69
|
+
*
|
|
70
|
+
* See https://github.com/eclipse-emfcloud/hydranium/issues/279.
|
|
71
|
+
*/
|
|
72
|
+
export function sendByMethodName<
|
|
73
|
+
In extends {
|
|
74
|
+
sendRequest<R>(method: string, ...params: unknown[]): Promise<R>;
|
|
75
|
+
sendNotification(method: string, ...params: unknown[]): Promise<void>;
|
|
76
|
+
},
|
|
77
|
+
Out extends {
|
|
78
|
+
sendRequest<R>(method: string, ...params: unknown[]): Promise<R>;
|
|
79
|
+
sendNotification(method: string, ...params: unknown[]): Promise<void>;
|
|
80
|
+
} = In
|
|
81
|
+
>(connection: In): Out {
|
|
82
|
+
const sendRequest = (type: string | TypedMessage, ...params: unknown[]) =>
|
|
83
|
+
typeof type === 'string'
|
|
84
|
+
? connection.sendRequest(type, ...params)
|
|
85
|
+
: connection.sendRequest(type.method, ...argsOf(type, params, true));
|
|
86
|
+
const sendNotification = (type: string | TypedMessage, ...params: unknown[]) =>
|
|
87
|
+
typeof type === 'string'
|
|
88
|
+
? connection.sendNotification(type, ...params)
|
|
89
|
+
: connection.sendNotification(type.method, ...argsOf(type, params, false));
|
|
90
|
+
const wrapped: Pick<In, 'sendRequest' | 'sendNotification'> = new Proxy(connection, {
|
|
91
|
+
get(target, property, receiver) {
|
|
92
|
+
if (property === 'sendRequest') {
|
|
93
|
+
return sendRequest;
|
|
94
|
+
}
|
|
95
|
+
if (property === 'sendNotification') {
|
|
96
|
+
return sendNotification;
|
|
97
|
+
}
|
|
98
|
+
return Reflect.get(target, property, receiver);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
// Typed as the connection its context expects, which the doc above justifies.
|
|
102
|
+
return wrapped as Out;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A typed message as any copy of `vscode-jsonrpc` builds it, read by shape rather than identity. */
|
|
106
|
+
interface TypedMessage {
|
|
107
|
+
readonly method: string;
|
|
108
|
+
readonly numberOfParams: number;
|
|
109
|
+
readonly parameterStructures: { toString(): string };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Whether `vscode-jsonrpc` sends `param` by name under `auto`. */
|
|
113
|
+
function isNamedParam(param: unknown): boolean {
|
|
114
|
+
return param !== undefined && param !== null && !Array.isArray(param) && typeof param === 'object';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The arguments that send `type` by method name with the typed send's params:
|
|
119
|
+
* the first `numberOfParams` of `params`, missing ones `null`, then a request's
|
|
120
|
+
* cancellation token, which the typed send takes from that position. A request
|
|
121
|
+
* always ends in a token, `CancellationToken.None` when it has none, since a
|
|
122
|
+
* send by method name takes a token-shaped last argument for its token. Throws
|
|
123
|
+
* for the one-parameter packing a send by method name cannot express.
|
|
124
|
+
*/
|
|
125
|
+
function argsOf(type: TypedMessage, params: unknown[], isRequest: boolean): unknown[] {
|
|
126
|
+
const args = Array.from({ length: type.numberOfParams }, (_, i) => (i < params.length ? params[i] : null));
|
|
127
|
+
if (type.numberOfParams === 1) {
|
|
128
|
+
const packing = String(type.parameterStructures);
|
|
129
|
+
if ((packing === 'byPosition' && isNamedParam(args[0])) || (packing === 'byName' && !isNamedParam(args[0]))) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`sendByMethodName cannot send '${type.method}' ${packing}: by method name, a single object goes by name and anything else by position.`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!isRequest) {
|
|
136
|
+
return args;
|
|
137
|
+
}
|
|
138
|
+
const token = params[type.numberOfParams];
|
|
139
|
+
return [...args, CancellationToken.is(token) ? token : CancellationToken.None];
|
|
140
|
+
}
|