@lvce-editor/completion-worker 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/completionWorkerMain.js +208 -45
- package/package.json +1 -1
|
@@ -403,9 +403,103 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
403
403
|
listen: listen$6,
|
|
404
404
|
wrap: wrap$e
|
|
405
405
|
};
|
|
406
|
+
const addListener = (emitter, type, callback) => {
|
|
407
|
+
if ('addEventListener' in emitter) {
|
|
408
|
+
emitter.addEventListener(type, callback);
|
|
409
|
+
} else {
|
|
410
|
+
emitter.on(type, callback);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
const removeListener = (emitter, type, callback) => {
|
|
414
|
+
if ('removeEventListener' in emitter) {
|
|
415
|
+
emitter.removeEventListener(type, callback);
|
|
416
|
+
} else {
|
|
417
|
+
emitter.off(type, callback);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
421
|
+
const {
|
|
422
|
+
resolve,
|
|
423
|
+
promise
|
|
424
|
+
} = Promise.withResolvers();
|
|
425
|
+
const listenerMap = Object.create(null);
|
|
426
|
+
const cleanup = value => {
|
|
427
|
+
for (const event of Object.keys(eventMap)) {
|
|
428
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
429
|
+
}
|
|
430
|
+
resolve(value);
|
|
431
|
+
};
|
|
432
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
433
|
+
const listener = event => {
|
|
434
|
+
cleanup({
|
|
435
|
+
type,
|
|
436
|
+
event
|
|
437
|
+
});
|
|
438
|
+
};
|
|
439
|
+
addListener(eventEmitter, event, listener);
|
|
440
|
+
listenerMap[event] = listener;
|
|
441
|
+
}
|
|
442
|
+
return promise;
|
|
443
|
+
};
|
|
444
|
+
const Message$1 = 3;
|
|
445
|
+
const create$5$1 = async ({
|
|
446
|
+
messagePort,
|
|
447
|
+
isMessagePortOpen
|
|
448
|
+
}) => {
|
|
449
|
+
if (!isMessagePort(messagePort)) {
|
|
450
|
+
throw new IpcError('port must be of type MessagePort');
|
|
451
|
+
}
|
|
452
|
+
if (isMessagePortOpen) {
|
|
453
|
+
return messagePort;
|
|
454
|
+
}
|
|
455
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
456
|
+
message: Message$1
|
|
457
|
+
});
|
|
458
|
+
messagePort.start();
|
|
459
|
+
const {
|
|
460
|
+
type,
|
|
461
|
+
event
|
|
462
|
+
} = await eventPromise;
|
|
463
|
+
if (type !== Message$1) {
|
|
464
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
465
|
+
}
|
|
466
|
+
if (event.data !== readyMessage) {
|
|
467
|
+
throw new IpcError('unexpected first message');
|
|
468
|
+
}
|
|
469
|
+
return messagePort;
|
|
470
|
+
};
|
|
471
|
+
const signal$1 = messagePort => {
|
|
472
|
+
messagePort.start();
|
|
473
|
+
};
|
|
474
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
475
|
+
getData = getData$2;
|
|
476
|
+
send(message) {
|
|
477
|
+
this._rawIpc.postMessage(message);
|
|
478
|
+
}
|
|
479
|
+
sendAndTransfer(message) {
|
|
480
|
+
const transfer = getTransferrables(message);
|
|
481
|
+
this._rawIpc.postMessage(message, transfer);
|
|
482
|
+
}
|
|
483
|
+
dispose() {
|
|
484
|
+
this._rawIpc.close();
|
|
485
|
+
}
|
|
486
|
+
onMessage(callback) {
|
|
487
|
+
this._rawIpc.addEventListener('message', callback);
|
|
488
|
+
}
|
|
489
|
+
onClose(callback) {}
|
|
490
|
+
}
|
|
491
|
+
const wrap$5 = messagePort => {
|
|
492
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
493
|
+
};
|
|
494
|
+
const IpcParentWithMessagePort$1 = {
|
|
495
|
+
__proto__: null,
|
|
496
|
+
create: create$5$1,
|
|
497
|
+
signal: signal$1,
|
|
498
|
+
wrap: wrap$5
|
|
499
|
+
};
|
|
406
500
|
|
|
407
501
|
const Two = '2.0';
|
|
408
|
-
const create$4 = (method, params) => {
|
|
502
|
+
const create$4$1 = (method, params) => {
|
|
409
503
|
return {
|
|
410
504
|
jsonrpc: Two,
|
|
411
505
|
method,
|
|
@@ -413,7 +507,7 @@ const create$4 = (method, params) => {
|
|
|
413
507
|
};
|
|
414
508
|
};
|
|
415
509
|
const callbacks = Object.create(null);
|
|
416
|
-
const set$
|
|
510
|
+
const set$3 = (id, fn) => {
|
|
417
511
|
callbacks[id] = fn;
|
|
418
512
|
};
|
|
419
513
|
const get$2 = id => {
|
|
@@ -432,13 +526,13 @@ const registerPromise = () => {
|
|
|
432
526
|
resolve,
|
|
433
527
|
promise
|
|
434
528
|
} = Promise.withResolvers();
|
|
435
|
-
set$
|
|
529
|
+
set$3(id, resolve);
|
|
436
530
|
return {
|
|
437
531
|
id,
|
|
438
532
|
promise
|
|
439
533
|
};
|
|
440
534
|
};
|
|
441
|
-
const create$2$
|
|
535
|
+
const create$2$2 = (method, params) => {
|
|
442
536
|
const {
|
|
443
537
|
id,
|
|
444
538
|
promise
|
|
@@ -730,7 +824,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
730
824
|
const {
|
|
731
825
|
message,
|
|
732
826
|
promise
|
|
733
|
-
} = create$2$
|
|
827
|
+
} = create$2$2(method, params);
|
|
734
828
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
735
829
|
ipc.sendAndTransfer(message);
|
|
736
830
|
} else {
|
|
@@ -740,13 +834,13 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
740
834
|
return unwrapJsonRpcResult(responseMessage);
|
|
741
835
|
};
|
|
742
836
|
const send = (transport, method, ...params) => {
|
|
743
|
-
const message = create$4(method, params);
|
|
837
|
+
const message = create$4$1(method, params);
|
|
744
838
|
transport.send(message);
|
|
745
839
|
};
|
|
746
|
-
const invoke$
|
|
840
|
+
const invoke$2 = (ipc, method, ...params) => {
|
|
747
841
|
return invokeHelper(ipc, method, params, false);
|
|
748
842
|
};
|
|
749
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
843
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
750
844
|
return invokeHelper(ipc, method, params, true);
|
|
751
845
|
};
|
|
752
846
|
|
|
@@ -776,10 +870,10 @@ const createRpc = ipc => {
|
|
|
776
870
|
send(ipc, method, ...params);
|
|
777
871
|
},
|
|
778
872
|
invoke(method, ...params) {
|
|
779
|
-
return invoke$
|
|
873
|
+
return invoke$2(ipc, method, ...params);
|
|
780
874
|
},
|
|
781
875
|
invokeAndTransfer(method, ...params) {
|
|
782
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
876
|
+
return invokeAndTransfer$1(ipc, method, ...params);
|
|
783
877
|
},
|
|
784
878
|
async dispose() {
|
|
785
879
|
await ipc?.dispose();
|
|
@@ -818,6 +912,35 @@ const listen$1 = async (module, options) => {
|
|
|
818
912
|
return ipc;
|
|
819
913
|
};
|
|
820
914
|
const create$3 = async ({
|
|
915
|
+
commandMap,
|
|
916
|
+
messagePort
|
|
917
|
+
}) => {
|
|
918
|
+
// TODO create a commandMap per rpc instance
|
|
919
|
+
register(commandMap);
|
|
920
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
921
|
+
messagePort,
|
|
922
|
+
isMessagePortOpen: true
|
|
923
|
+
});
|
|
924
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
925
|
+
handleIpc(ipc);
|
|
926
|
+
const rpc = createRpc(ipc);
|
|
927
|
+
messagePort.start();
|
|
928
|
+
return rpc;
|
|
929
|
+
};
|
|
930
|
+
const create$2$1 = async ({
|
|
931
|
+
commandMap,
|
|
932
|
+
messagePort
|
|
933
|
+
}) => {
|
|
934
|
+
return create$3({
|
|
935
|
+
commandMap,
|
|
936
|
+
messagePort
|
|
937
|
+
});
|
|
938
|
+
};
|
|
939
|
+
const PlainMessagePortRpcParent = {
|
|
940
|
+
__proto__: null,
|
|
941
|
+
create: create$2$1
|
|
942
|
+
};
|
|
943
|
+
const create$4 = async ({
|
|
821
944
|
commandMap
|
|
822
945
|
}) => {
|
|
823
946
|
// TODO create a commandMap per rpc instance
|
|
@@ -829,7 +952,7 @@ const create$3 = async ({
|
|
|
829
952
|
};
|
|
830
953
|
const WebWorkerRpcClient = {
|
|
831
954
|
__proto__: null,
|
|
832
|
-
create: create$
|
|
955
|
+
create: create$4
|
|
833
956
|
};
|
|
834
957
|
|
|
835
958
|
const create$2 = () => {
|
|
@@ -893,7 +1016,7 @@ const create$2 = () => {
|
|
|
893
1016
|
|
|
894
1017
|
const {
|
|
895
1018
|
get: get$1,
|
|
896
|
-
set: set$
|
|
1019
|
+
set: set$2,
|
|
897
1020
|
wrapCommand
|
|
898
1021
|
} = create$2();
|
|
899
1022
|
|
|
@@ -918,7 +1041,7 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
|
|
|
918
1041
|
unfilteredItems: [],
|
|
919
1042
|
version: 0
|
|
920
1043
|
};
|
|
921
|
-
set$
|
|
1044
|
+
set$2(uid, state, state);
|
|
922
1045
|
};
|
|
923
1046
|
|
|
924
1047
|
const modules = [];
|
|
@@ -950,14 +1073,17 @@ const getCommandIds = () => {
|
|
|
950
1073
|
return commandIds;
|
|
951
1074
|
};
|
|
952
1075
|
|
|
953
|
-
const
|
|
954
|
-
|
|
1076
|
+
const getPortTuple = () => {
|
|
1077
|
+
const {
|
|
1078
|
+
port1,
|
|
1079
|
+
port2
|
|
1080
|
+
} = new MessageChannel();
|
|
1081
|
+
return {
|
|
1082
|
+
port1,
|
|
1083
|
+
port2
|
|
1084
|
+
};
|
|
955
1085
|
};
|
|
956
1086
|
|
|
957
|
-
const OnCompletion = 'onCompletion';
|
|
958
|
-
|
|
959
|
-
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
960
|
-
|
|
961
1087
|
const rpcs = Object.create(null);
|
|
962
1088
|
const set$9 = (id, rpc) => {
|
|
963
1089
|
rpcs[id] = rpc;
|
|
@@ -989,39 +1115,79 @@ const create = rpcId => {
|
|
|
989
1115
|
};
|
|
990
1116
|
const EditorWorker$1 = 99;
|
|
991
1117
|
const ExtensionHostWorker = 44;
|
|
992
|
-
const RendererWorker$1 = 1;
|
|
993
1118
|
const {
|
|
994
|
-
invoke: invoke$8
|
|
1119
|
+
invoke: invoke$8,
|
|
1120
|
+
invokeAndTransfer: invokeAndTransfer$8,
|
|
1121
|
+
set: set$8
|
|
1122
|
+
} = create(EditorWorker$1);
|
|
995
1123
|
const EditorWorker = {
|
|
996
1124
|
__proto__: null,
|
|
997
|
-
invoke: invoke$8
|
|
1125
|
+
invoke: invoke$8,
|
|
1126
|
+
invokeAndTransfer: invokeAndTransfer$8,
|
|
1127
|
+
set: set$8
|
|
1128
|
+
};
|
|
998
1129
|
const {
|
|
999
|
-
invoke: invoke$6
|
|
1130
|
+
invoke: invoke$6,
|
|
1131
|
+
set: set$6
|
|
1132
|
+
} = create(ExtensionHostWorker);
|
|
1000
1133
|
const ExtensionHost = {
|
|
1001
1134
|
__proto__: null,
|
|
1002
|
-
invoke: invoke$6
|
|
1135
|
+
invoke: invoke$6,
|
|
1136
|
+
set: set$6
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1003
1139
|
const {
|
|
1004
|
-
invoke: invoke$
|
|
1005
|
-
set: set$
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1140
|
+
invoke: invoke$1,
|
|
1141
|
+
set: set$1,
|
|
1142
|
+
invokeAndTransfer
|
|
1143
|
+
} = EditorWorker;
|
|
1144
|
+
|
|
1145
|
+
const sendMessagePortToExtensionHostWorker = async port => {
|
|
1146
|
+
const command = 'HandleMessagePort.handleMessagePort2';
|
|
1147
|
+
// @ts-ignore
|
|
1148
|
+
await invokeAndTransfer(
|
|
1149
|
+
// @ts-ignore
|
|
1150
|
+
'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0 // TODO
|
|
1151
|
+
);
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
const createExtensionHostRpc = async () => {
|
|
1155
|
+
try {
|
|
1156
|
+
const {
|
|
1157
|
+
port1,
|
|
1158
|
+
port2
|
|
1159
|
+
} = getPortTuple();
|
|
1160
|
+
await sendMessagePortToExtensionHostWorker(port2);
|
|
1161
|
+
const rpc = await PlainMessagePortRpcParent.create({
|
|
1162
|
+
commandMap: {},
|
|
1163
|
+
messagePort: port1
|
|
1164
|
+
});
|
|
1165
|
+
return rpc;
|
|
1166
|
+
} catch (error) {
|
|
1167
|
+
throw new VError(error, `Failed to create extension host rpc`);
|
|
1168
|
+
}
|
|
1011
1169
|
};
|
|
1012
1170
|
|
|
1013
1171
|
const {
|
|
1014
|
-
|
|
1015
|
-
|
|
1172
|
+
invoke,
|
|
1173
|
+
set
|
|
1174
|
+
} = ExtensionHost;
|
|
1175
|
+
|
|
1176
|
+
const initialize = async () => {
|
|
1177
|
+
const rpc = await createExtensionHostRpc();
|
|
1178
|
+
set(rpc);
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
const OnCompletion = 'onCompletion';
|
|
1182
|
+
|
|
1183
|
+
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
1016
1184
|
|
|
1017
1185
|
// TODO add tests for this
|
|
1018
1186
|
const activateByEvent = async event => {
|
|
1019
|
-
|
|
1187
|
+
// @ts-ignore
|
|
1188
|
+
await invoke$1('ActivateByEvent.activateByEvent', event);
|
|
1020
1189
|
};
|
|
1021
1190
|
|
|
1022
|
-
const {
|
|
1023
|
-
invoke: invoke$1} = ExtensionHost;
|
|
1024
|
-
|
|
1025
1191
|
const execute = async ({
|
|
1026
1192
|
editor,
|
|
1027
1193
|
args,
|
|
@@ -1032,7 +1198,7 @@ const execute = async ({
|
|
|
1032
1198
|
}) => {
|
|
1033
1199
|
const fullEvent = `${event}:${editor.languageId}`;
|
|
1034
1200
|
await activateByEvent(fullEvent);
|
|
1035
|
-
const result = await invoke
|
|
1201
|
+
const result = await invoke(method, editor.uid, ...args);
|
|
1036
1202
|
return result;
|
|
1037
1203
|
};
|
|
1038
1204
|
|
|
@@ -1271,11 +1437,8 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
|
|
|
1271
1437
|
return Math.min(totalHeight, maxHeight);
|
|
1272
1438
|
};
|
|
1273
1439
|
|
|
1274
|
-
const {
|
|
1275
|
-
invoke} = EditorWorker;
|
|
1276
|
-
|
|
1277
1440
|
const getPositionAtCursor = async parentUid => {
|
|
1278
|
-
const position = await invoke('Editor.getPositionAtCursor', parentUid);
|
|
1441
|
+
const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
|
|
1279
1442
|
return position;
|
|
1280
1443
|
};
|
|
1281
1444
|
|
|
@@ -1373,7 +1536,7 @@ const render2 = (uid, diffResult) => {
|
|
|
1373
1536
|
oldState,
|
|
1374
1537
|
newState
|
|
1375
1538
|
} = get$1(uid);
|
|
1376
|
-
set$
|
|
1539
|
+
set$2(uid, newState, newState);
|
|
1377
1540
|
const commands = applyRender(oldState, newState, diffResult);
|
|
1378
1541
|
return commands;
|
|
1379
1542
|
};
|
|
@@ -1389,14 +1552,14 @@ const commandMap = {
|
|
|
1389
1552
|
'Completions.loadContent': wrapCommand(loadContent),
|
|
1390
1553
|
'Completions.render2': render2,
|
|
1391
1554
|
'Completions.terminate': terminate,
|
|
1392
|
-
'Completions.
|
|
1555
|
+
'Completions.initialize': initialize
|
|
1393
1556
|
};
|
|
1394
1557
|
|
|
1395
1558
|
const listen = async () => {
|
|
1396
1559
|
const rpc = await WebWorkerRpcClient.create({
|
|
1397
1560
|
commandMap: commandMap
|
|
1398
1561
|
});
|
|
1399
|
-
set(rpc);
|
|
1562
|
+
set$1(rpc);
|
|
1400
1563
|
};
|
|
1401
1564
|
|
|
1402
1565
|
const main = async () => {
|