@lvce-editor/completion-worker 3.1.0 → 4.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 +101 -77
- package/package.json +1 -1
|
@@ -531,7 +531,7 @@ const register = commandMap => {
|
|
|
531
531
|
const getCommand$1 = key => {
|
|
532
532
|
return commands[key];
|
|
533
533
|
};
|
|
534
|
-
const execute
|
|
534
|
+
const execute = (command, ...args) => {
|
|
535
535
|
const fn = getCommand$1(command);
|
|
536
536
|
if (!fn) {
|
|
537
537
|
throw new CommandNotFoundError(command);
|
|
@@ -753,7 +753,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
753
753
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
754
754
|
return create$1$1(id, errorProperty);
|
|
755
755
|
};
|
|
756
|
-
const create$
|
|
756
|
+
const create$a = (message, result) => {
|
|
757
757
|
return {
|
|
758
758
|
id: message.id,
|
|
759
759
|
jsonrpc: Two$1,
|
|
@@ -762,7 +762,7 @@ const create$9 = (message, result) => {
|
|
|
762
762
|
};
|
|
763
763
|
const getSuccessResponse = (message, result) => {
|
|
764
764
|
const resultProperty = result ?? null;
|
|
765
|
-
return create$
|
|
765
|
+
return create$a(message, resultProperty);
|
|
766
766
|
};
|
|
767
767
|
const getErrorResponseSimple = (id, error) => {
|
|
768
768
|
return {
|
|
@@ -856,7 +856,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
856
856
|
|
|
857
857
|
const Two = '2.0';
|
|
858
858
|
|
|
859
|
-
const create$
|
|
859
|
+
const create$9 = (method, params) => {
|
|
860
860
|
return {
|
|
861
861
|
jsonrpc: Two,
|
|
862
862
|
method,
|
|
@@ -864,7 +864,7 @@ const create$8 = (method, params) => {
|
|
|
864
864
|
};
|
|
865
865
|
};
|
|
866
866
|
|
|
867
|
-
const create$
|
|
867
|
+
const create$8 = (id, method, params) => {
|
|
868
868
|
const message = {
|
|
869
869
|
id,
|
|
870
870
|
jsonrpc: Two,
|
|
@@ -875,12 +875,12 @@ const create$7 = (id, method, params) => {
|
|
|
875
875
|
};
|
|
876
876
|
|
|
877
877
|
let id = 0;
|
|
878
|
-
const create$
|
|
878
|
+
const create$7 = () => {
|
|
879
879
|
return ++id;
|
|
880
880
|
};
|
|
881
881
|
|
|
882
882
|
const registerPromise = map => {
|
|
883
|
-
const id = create$
|
|
883
|
+
const id = create$7();
|
|
884
884
|
const {
|
|
885
885
|
promise,
|
|
886
886
|
resolve
|
|
@@ -897,7 +897,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
897
897
|
id,
|
|
898
898
|
promise
|
|
899
899
|
} = registerPromise(callbacks);
|
|
900
|
-
const message = create$
|
|
900
|
+
const message = create$8(id, method, params);
|
|
901
901
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
902
902
|
ipc.sendAndTransfer(message);
|
|
903
903
|
} else {
|
|
@@ -933,7 +933,7 @@ const createRpc = ipc => {
|
|
|
933
933
|
* @deprecated
|
|
934
934
|
*/
|
|
935
935
|
send(method, ...params) {
|
|
936
|
-
const message = create$
|
|
936
|
+
const message = create$9(method, params);
|
|
937
937
|
ipc.send(message);
|
|
938
938
|
}
|
|
939
939
|
};
|
|
@@ -951,7 +951,7 @@ const logError = () => {
|
|
|
951
951
|
};
|
|
952
952
|
const handleMessage = event => {
|
|
953
953
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
954
|
-
const actualExecute = event?.target?.execute || execute
|
|
954
|
+
const actualExecute = event?.target?.execute || execute;
|
|
955
955
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
956
956
|
};
|
|
957
957
|
|
|
@@ -973,7 +973,7 @@ const listen$1 = async (module, options) => {
|
|
|
973
973
|
return ipc;
|
|
974
974
|
};
|
|
975
975
|
|
|
976
|
-
const create$
|
|
976
|
+
const create$6 = async ({
|
|
977
977
|
commandMap,
|
|
978
978
|
isMessagePortOpen = true,
|
|
979
979
|
messagePort
|
|
@@ -991,7 +991,7 @@ const create$5 = async ({
|
|
|
991
991
|
return rpc;
|
|
992
992
|
};
|
|
993
993
|
|
|
994
|
-
const create$
|
|
994
|
+
const create$5 = async ({
|
|
995
995
|
commandMap,
|
|
996
996
|
isMessagePortOpen,
|
|
997
997
|
send
|
|
@@ -1001,13 +1001,55 @@ const create$4 = async ({
|
|
|
1001
1001
|
port2
|
|
1002
1002
|
} = new MessageChannel();
|
|
1003
1003
|
await send(port1);
|
|
1004
|
-
return create$
|
|
1004
|
+
return create$6({
|
|
1005
1005
|
commandMap,
|
|
1006
1006
|
isMessagePortOpen,
|
|
1007
1007
|
messagePort: port2
|
|
1008
1008
|
});
|
|
1009
1009
|
};
|
|
1010
1010
|
|
|
1011
|
+
const createSharedLazyRpc = factory => {
|
|
1012
|
+
let rpcPromise;
|
|
1013
|
+
const getOrCreate = () => {
|
|
1014
|
+
if (!rpcPromise) {
|
|
1015
|
+
rpcPromise = factory();
|
|
1016
|
+
}
|
|
1017
|
+
return rpcPromise;
|
|
1018
|
+
};
|
|
1019
|
+
return {
|
|
1020
|
+
async dispose() {
|
|
1021
|
+
const rpc = await getOrCreate();
|
|
1022
|
+
await rpc.dispose();
|
|
1023
|
+
},
|
|
1024
|
+
async invoke(method, ...params) {
|
|
1025
|
+
const rpc = await getOrCreate();
|
|
1026
|
+
return rpc.invoke(method, ...params);
|
|
1027
|
+
},
|
|
1028
|
+
async invokeAndTransfer(method, ...params) {
|
|
1029
|
+
const rpc = await getOrCreate();
|
|
1030
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1031
|
+
},
|
|
1032
|
+
async send(method, ...params) {
|
|
1033
|
+
const rpc = await getOrCreate();
|
|
1034
|
+
rpc.send(method, ...params);
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
const create$4 = async ({
|
|
1040
|
+
commandMap,
|
|
1041
|
+
isMessagePortOpen,
|
|
1042
|
+
send
|
|
1043
|
+
}) => {
|
|
1044
|
+
return createSharedLazyRpc(() => {
|
|
1045
|
+
return create$5({
|
|
1046
|
+
commandMap,
|
|
1047
|
+
isMessagePortOpen,
|
|
1048
|
+
send
|
|
1049
|
+
});
|
|
1050
|
+
});
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1011
1053
|
const create$3 = async ({
|
|
1012
1054
|
commandMap
|
|
1013
1055
|
}) => {
|
|
@@ -1108,23 +1150,15 @@ const DownArrow = 16;
|
|
|
1108
1150
|
const CtrlCmd = 1 << 11 >>> 0;
|
|
1109
1151
|
|
|
1110
1152
|
const EditorWorker$1 = 99;
|
|
1111
|
-
const
|
|
1153
|
+
const ExtensionManagementWorker = 9006;
|
|
1112
1154
|
|
|
1113
1155
|
const {
|
|
1114
1156
|
invoke: invoke$1,
|
|
1115
1157
|
invokeAndTransfer,
|
|
1116
1158
|
set: set$2
|
|
1117
1159
|
} = create$2(EditorWorker$1);
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
await invokeAndTransfer(
|
|
1121
|
-
// @ts-ignore
|
|
1122
|
-
'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0);
|
|
1123
|
-
};
|
|
1124
|
-
// TODO add tests for this
|
|
1125
|
-
const activateByEvent = async event => {
|
|
1126
|
-
// @ts-ignore
|
|
1127
|
-
await invoke$1('ActivateByEvent.activateByEvent', event);
|
|
1160
|
+
const sendMessagePortToExtensionManagementWorker = async port => {
|
|
1161
|
+
await invokeAndTransfer('SendMessagePortToExtensionManagementWorker.sendMessagePortToExtensionManagementWorker', port, 0);
|
|
1128
1162
|
};
|
|
1129
1163
|
const applyEdit$1 = async (editorUid, changes) => {
|
|
1130
1164
|
// @ts-ignore
|
|
@@ -1156,28 +1190,37 @@ const getWordAtOffset2 = async editorUid => {
|
|
|
1156
1190
|
const getWordBefore$1 = async (editorUid, rowIndex, columnIndex) => {
|
|
1157
1191
|
return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
|
|
1158
1192
|
};
|
|
1193
|
+
const getUri = async editorUid => {
|
|
1194
|
+
// @ts-ignore
|
|
1195
|
+
return invoke$1('Editor.getUri', editorUid);
|
|
1196
|
+
};
|
|
1197
|
+
const getLanguageId = async editorUid => {
|
|
1198
|
+
// @ts-ignore
|
|
1199
|
+
return invoke$1('Editor.getLanguageId', editorUid);
|
|
1200
|
+
};
|
|
1159
1201
|
|
|
1160
1202
|
const EditorWorker = {
|
|
1161
1203
|
__proto__: null,
|
|
1162
|
-
activateByEvent,
|
|
1163
1204
|
applyEdit: applyEdit$1,
|
|
1164
1205
|
closeWidget,
|
|
1206
|
+
getLanguageId,
|
|
1165
1207
|
getLines: getLines$1,
|
|
1166
1208
|
getOffsetAtCursor: getOffsetAtCursor$1,
|
|
1167
1209
|
getPositionAtCursor: getPositionAtCursor$1,
|
|
1168
1210
|
getSelections: getSelections$1,
|
|
1211
|
+
getUri,
|
|
1169
1212
|
getWordAtOffset2,
|
|
1170
1213
|
getWordBefore: getWordBefore$1,
|
|
1171
1214
|
invoke: invoke$1,
|
|
1172
1215
|
invokeAndTransfer,
|
|
1173
|
-
|
|
1216
|
+
sendMessagePortToExtensionManagementWorker,
|
|
1174
1217
|
set: set$2
|
|
1175
1218
|
};
|
|
1176
1219
|
|
|
1177
1220
|
const {
|
|
1178
1221
|
invoke,
|
|
1179
1222
|
set: set$1
|
|
1180
|
-
} = create$2(
|
|
1223
|
+
} = create$2(ExtensionManagementWorker);
|
|
1181
1224
|
|
|
1182
1225
|
const toCommandId = key => {
|
|
1183
1226
|
const dotIndex = key.indexOf('.');
|
|
@@ -1495,40 +1538,27 @@ const replaceRange = (lines, ranges, replacement, origin) => {
|
|
|
1495
1538
|
return changes;
|
|
1496
1539
|
};
|
|
1497
1540
|
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
const
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
}
|
|
1510
|
-
const fullEvent = `${event}:${editorLanguageId}`;
|
|
1511
|
-
await activateByEvent(fullEvent);
|
|
1512
|
-
const result = await invoke(method, editorUid, ...args);
|
|
1513
|
-
return result;
|
|
1541
|
+
const getText = async editorUid => {
|
|
1542
|
+
const lines = await getLines$1(editorUid);
|
|
1543
|
+
return lines.join('\n');
|
|
1544
|
+
};
|
|
1545
|
+
const getTextDocument = async (editorUid, languageId) => {
|
|
1546
|
+
const [text, uri] = await Promise.all([getText(editorUid), getUri(editorUid)]);
|
|
1547
|
+
return {
|
|
1548
|
+
documentId: editorUid,
|
|
1549
|
+
languageId,
|
|
1550
|
+
text,
|
|
1551
|
+
uri
|
|
1552
|
+
};
|
|
1514
1553
|
};
|
|
1515
|
-
|
|
1516
1554
|
const executeCompletionProvider = async (editorUid, editorLanguageId, offset) => {
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
editorLanguageId,
|
|
1520
|
-
editorUid,
|
|
1521
|
-
event: OnCompletion,
|
|
1522
|
-
method: CompletionExecute
|
|
1523
|
-
});
|
|
1555
|
+
const textDocument = await getTextDocument(editorUid, editorLanguageId);
|
|
1556
|
+
return invoke('Extensions.executeCompletionProvider', textDocument, offset);
|
|
1524
1557
|
};
|
|
1525
1558
|
const executeResolveCompletionItem = async (editorUid, offset, name, completionItem) => {
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
event: OnCompletion,
|
|
1530
|
-
method: CompletionResolveExecute
|
|
1531
|
-
});
|
|
1559
|
+
const editorLanguageId = await getLanguageId(editorUid);
|
|
1560
|
+
const textDocument = await getTextDocument(editorUid, editorLanguageId);
|
|
1561
|
+
return invoke('Extensions.executeResolveCompletionItemProvider', textDocument, offset, name, completionItem);
|
|
1532
1562
|
};
|
|
1533
1563
|
|
|
1534
1564
|
const getOffsetAtCursor = async editorUid => {
|
|
@@ -2029,25 +2059,8 @@ const handleWheel = (state, deltaMode, deltaY) => {
|
|
|
2029
2059
|
return setDeltaY(state, state.deltaY + deltaY);
|
|
2030
2060
|
};
|
|
2031
2061
|
|
|
2032
|
-
const {
|
|
2033
|
-
sendMessagePortToExtensionHostWorker
|
|
2034
|
-
} = EditorWorker;
|
|
2035
|
-
|
|
2036
|
-
const createExtensionHostRpc = async () => {
|
|
2037
|
-
try {
|
|
2038
|
-
const rpc = await create$4({
|
|
2039
|
-
commandMap: {},
|
|
2040
|
-
send: sendMessagePortToExtensionHostWorker
|
|
2041
|
-
});
|
|
2042
|
-
return rpc;
|
|
2043
|
-
} catch (error) {
|
|
2044
|
-
throw new VError(error, `Failed to create extension host rpc`);
|
|
2045
|
-
}
|
|
2046
|
-
};
|
|
2047
|
-
|
|
2048
2062
|
const initialize = async () => {
|
|
2049
|
-
|
|
2050
|
-
set$1(rpc);
|
|
2063
|
+
// Initialization happens during worker startup in Listen.listen.
|
|
2051
2064
|
};
|
|
2052
2065
|
|
|
2053
2066
|
const error = message => {
|
|
@@ -2223,7 +2236,7 @@ const getIconDom = (fileIcon, symbolName) => {
|
|
|
2223
2236
|
}
|
|
2224
2237
|
return {
|
|
2225
2238
|
childCount: 0,
|
|
2226
|
-
className:
|
|
2239
|
+
className: mergeClassNames(ColoredMaskIcon, symbolName),
|
|
2227
2240
|
type: Div
|
|
2228
2241
|
};
|
|
2229
2242
|
};
|
|
@@ -2560,8 +2573,19 @@ const initializeEditorWorker = async () => {
|
|
|
2560
2573
|
set$2(rpc);
|
|
2561
2574
|
};
|
|
2562
2575
|
|
|
2576
|
+
const send = async port => {
|
|
2577
|
+
await sendMessagePortToExtensionManagementWorker(port);
|
|
2578
|
+
};
|
|
2579
|
+
const initializeExtensionManagementWorker = async () => {
|
|
2580
|
+
const rpc = await create$4({
|
|
2581
|
+
commandMap: commandMap,
|
|
2582
|
+
send
|
|
2583
|
+
});
|
|
2584
|
+
set$1(rpc);
|
|
2585
|
+
};
|
|
2586
|
+
|
|
2563
2587
|
const listen = async () => {
|
|
2564
|
-
await initializeEditorWorker();
|
|
2588
|
+
await Promise.all([initializeEditorWorker(), initializeExtensionManagementWorker()]);
|
|
2565
2589
|
};
|
|
2566
2590
|
|
|
2567
2591
|
const main = async () => {
|