@lvce-editor/completion-worker 1.7.0 → 1.9.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 +110 -84
- package/package.json +1 -1
|
@@ -967,7 +967,79 @@ const WebWorkerRpcClient = {
|
|
|
967
967
|
create: create$4
|
|
968
968
|
};
|
|
969
969
|
|
|
970
|
-
const
|
|
970
|
+
const rpcs = Object.create(null);
|
|
971
|
+
const set$a = (id, rpc) => {
|
|
972
|
+
rpcs[id] = rpc;
|
|
973
|
+
};
|
|
974
|
+
const get$1 = id => {
|
|
975
|
+
return rpcs[id];
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
979
|
+
|
|
980
|
+
const create$2 = rpcId => {
|
|
981
|
+
return {
|
|
982
|
+
// @ts-ignore
|
|
983
|
+
invoke(method, ...params) {
|
|
984
|
+
const rpc = get$1(rpcId);
|
|
985
|
+
// @ts-ignore
|
|
986
|
+
return rpc.invoke(method, ...params);
|
|
987
|
+
},
|
|
988
|
+
// @ts-ignore
|
|
989
|
+
invokeAndTransfer(method, ...params) {
|
|
990
|
+
const rpc = get$1(rpcId);
|
|
991
|
+
// @ts-ignore
|
|
992
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
993
|
+
},
|
|
994
|
+
set(rpc) {
|
|
995
|
+
set$a(rpcId, rpc);
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
};
|
|
999
|
+
const EditorWorker$1 = 99;
|
|
1000
|
+
const ExtensionHostWorker = 44;
|
|
1001
|
+
const {
|
|
1002
|
+
invoke: invoke$9,
|
|
1003
|
+
invokeAndTransfer: invokeAndTransfer$9,
|
|
1004
|
+
set: set$9
|
|
1005
|
+
} = create$2(EditorWorker$1);
|
|
1006
|
+
const EditorWorker = {
|
|
1007
|
+
__proto__: null,
|
|
1008
|
+
invoke: invoke$9,
|
|
1009
|
+
invokeAndTransfer: invokeAndTransfer$9,
|
|
1010
|
+
set: set$9
|
|
1011
|
+
};
|
|
1012
|
+
const {
|
|
1013
|
+
invoke: invoke$7,
|
|
1014
|
+
set: set$7
|
|
1015
|
+
} = create$2(ExtensionHostWorker);
|
|
1016
|
+
const ExtensionHost = {
|
|
1017
|
+
__proto__: null,
|
|
1018
|
+
invoke: invoke$7,
|
|
1019
|
+
set: set$7
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
const {
|
|
1023
|
+
invoke: invoke$1,
|
|
1024
|
+
set: set$2,
|
|
1025
|
+
invokeAndTransfer
|
|
1026
|
+
} = EditorWorker;
|
|
1027
|
+
|
|
1028
|
+
const FocusEditorCompletions = 9;
|
|
1029
|
+
const FocusEditorRename = 11;
|
|
1030
|
+
|
|
1031
|
+
const Completion = 3;
|
|
1032
|
+
|
|
1033
|
+
const close = async state => {
|
|
1034
|
+
const {
|
|
1035
|
+
editorUid
|
|
1036
|
+
} = state;
|
|
1037
|
+
// @ts-ignore
|
|
1038
|
+
await invoke$1('Editor.closeWidget2', editorUid, Completion, 'Completions', FocusEditorCompletions);
|
|
1039
|
+
return state;
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
const create$1 = () => {
|
|
971
1043
|
const states = Object.create(null);
|
|
972
1044
|
return {
|
|
973
1045
|
get(uid) {
|
|
@@ -1027,13 +1099,13 @@ const create$2 = () => {
|
|
|
1027
1099
|
};
|
|
1028
1100
|
|
|
1029
1101
|
const {
|
|
1030
|
-
get
|
|
1031
|
-
set: set$
|
|
1102
|
+
get,
|
|
1103
|
+
set: set$1,
|
|
1032
1104
|
wrapCommand,
|
|
1033
1105
|
dispose: dispose$1
|
|
1034
|
-
} = create$
|
|
1106
|
+
} = create$1();
|
|
1035
1107
|
|
|
1036
|
-
const create
|
|
1108
|
+
const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
|
|
1037
1109
|
const state = {
|
|
1038
1110
|
uid,
|
|
1039
1111
|
items: [],
|
|
@@ -1056,7 +1128,7 @@ const create$1 = (uid, x, y, width, height, editorUid, editorLanguageId) => {
|
|
|
1056
1128
|
editorUid,
|
|
1057
1129
|
editorLanguageId
|
|
1058
1130
|
};
|
|
1059
|
-
set$
|
|
1131
|
+
set$1(uid, state, state);
|
|
1060
1132
|
};
|
|
1061
1133
|
|
|
1062
1134
|
const isEqual$4 = (oldState, newState) => {
|
|
@@ -1104,7 +1176,7 @@ const diff2 = uid => {
|
|
|
1104
1176
|
const {
|
|
1105
1177
|
oldState,
|
|
1106
1178
|
newState
|
|
1107
|
-
} = get
|
|
1179
|
+
} = get(uid);
|
|
1108
1180
|
const diffResult = diff(oldState, newState);
|
|
1109
1181
|
return diffResult;
|
|
1110
1182
|
};
|
|
@@ -1145,64 +1217,11 @@ const openDetails = async state => {
|
|
|
1145
1217
|
return state;
|
|
1146
1218
|
};
|
|
1147
1219
|
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
};
|
|
1152
|
-
const get = id => {
|
|
1153
|
-
return rpcs[id];
|
|
1154
|
-
};
|
|
1155
|
-
|
|
1156
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1157
|
-
|
|
1158
|
-
const create = rpcId => {
|
|
1159
|
-
return {
|
|
1160
|
-
// @ts-ignore
|
|
1161
|
-
invoke(method, ...params) {
|
|
1162
|
-
const rpc = get(rpcId);
|
|
1163
|
-
// @ts-ignore
|
|
1164
|
-
return rpc.invoke(method, ...params);
|
|
1165
|
-
},
|
|
1166
|
-
// @ts-ignore
|
|
1167
|
-
invokeAndTransfer(method, ...params) {
|
|
1168
|
-
const rpc = get(rpcId);
|
|
1169
|
-
// @ts-ignore
|
|
1170
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
1171
|
-
},
|
|
1172
|
-
set(rpc) {
|
|
1173
|
-
set$a(rpcId, rpc);
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
};
|
|
1177
|
-
const EditorWorker$1 = 99;
|
|
1178
|
-
const ExtensionHostWorker = 44;
|
|
1179
|
-
const {
|
|
1180
|
-
invoke: invoke$9,
|
|
1181
|
-
invokeAndTransfer: invokeAndTransfer$9,
|
|
1182
|
-
set: set$9
|
|
1183
|
-
} = create(EditorWorker$1);
|
|
1184
|
-
const EditorWorker = {
|
|
1185
|
-
__proto__: null,
|
|
1186
|
-
invoke: invoke$9,
|
|
1187
|
-
invokeAndTransfer: invokeAndTransfer$9,
|
|
1188
|
-
set: set$9
|
|
1189
|
-
};
|
|
1190
|
-
const {
|
|
1191
|
-
invoke: invoke$7,
|
|
1192
|
-
set: set$7
|
|
1193
|
-
} = create(ExtensionHostWorker);
|
|
1194
|
-
const ExtensionHost = {
|
|
1195
|
-
__proto__: null,
|
|
1196
|
-
invoke: invoke$7,
|
|
1197
|
-
set: set$7
|
|
1220
|
+
const applyEdit = async (editorUid, changes) => {
|
|
1221
|
+
// @ts-ignore
|
|
1222
|
+
await invoke$1('Editor.applyEdit2', editorUid, changes);
|
|
1198
1223
|
};
|
|
1199
1224
|
|
|
1200
|
-
const {
|
|
1201
|
-
invoke: invoke$1,
|
|
1202
|
-
set: set$1,
|
|
1203
|
-
invokeAndTransfer
|
|
1204
|
-
} = EditorWorker;
|
|
1205
|
-
|
|
1206
1225
|
const OnCompletion = 'onCompletion';
|
|
1207
1226
|
|
|
1208
1227
|
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
@@ -1279,6 +1298,16 @@ const resolveCompletion = async (editorUid, name, completionItem) => {
|
|
|
1279
1298
|
}
|
|
1280
1299
|
};
|
|
1281
1300
|
|
|
1301
|
+
const getLines = async editorUid => {
|
|
1302
|
+
const lines = await invoke$1('Editor.getLines2', editorUid);
|
|
1303
|
+
return lines;
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
const getSelections = async editorUid => {
|
|
1307
|
+
const selections = await invoke$1('Editor.getSelections2', editorUid);
|
|
1308
|
+
return selections;
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1282
1311
|
const getSelectionPairs = (selections, i) => {
|
|
1283
1312
|
const first = selections[i];
|
|
1284
1313
|
const second = selections[i + 1];
|
|
@@ -1335,8 +1364,8 @@ const getEdits = async (editorUid, leadingWord, completionItem) => {
|
|
|
1335
1364
|
const word = completionItem.label;
|
|
1336
1365
|
const resolvedItem = await resolveCompletion(editorUid, word, completionItem);
|
|
1337
1366
|
const inserted = resolvedItem ? resolvedItem.snippet : word;
|
|
1338
|
-
const lines = await
|
|
1339
|
-
const selections = await
|
|
1367
|
+
const lines = await getLines(editorUid);
|
|
1368
|
+
const selections = await getSelections(editorUid);
|
|
1340
1369
|
const [startRowIndex, startColumnIndex] = selections;
|
|
1341
1370
|
const leadingWordLength = leadingWord.length;
|
|
1342
1371
|
const replaceRange$1 = new Uint32Array([startRowIndex, startColumnIndex - leadingWordLength, startRowIndex, startColumnIndex]);
|
|
@@ -1344,22 +1373,14 @@ const getEdits = async (editorUid, leadingWord, completionItem) => {
|
|
|
1344
1373
|
return changes;
|
|
1345
1374
|
};
|
|
1346
1375
|
|
|
1347
|
-
const Completion = 3;
|
|
1348
|
-
|
|
1349
1376
|
const select = async (state, completionItem) => {
|
|
1350
1377
|
const {
|
|
1351
1378
|
editorUid,
|
|
1352
1379
|
leadingWord
|
|
1353
1380
|
} = state;
|
|
1354
1381
|
const changes = await getEdits(editorUid, leadingWord, completionItem);
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
// @ts-ignore
|
|
1358
|
-
await invoke$1('Editor.closeWidget2', editorUid, Completion, 'Completions');
|
|
1359
|
-
// TODO remove completion widget from editor
|
|
1360
|
-
return {
|
|
1361
|
-
...state
|
|
1362
|
-
};
|
|
1382
|
+
await applyEdit(editorUid, changes);
|
|
1383
|
+
return close(state);
|
|
1363
1384
|
};
|
|
1364
1385
|
|
|
1365
1386
|
const selectIndex = async (state, index) => {
|
|
@@ -1391,6 +1412,7 @@ const getCommandIds = () => {
|
|
|
1391
1412
|
};
|
|
1392
1413
|
|
|
1393
1414
|
const Enter = 3;
|
|
1415
|
+
const Escape = 8;
|
|
1394
1416
|
const Space$1 = 9;
|
|
1395
1417
|
const End = 255;
|
|
1396
1418
|
const Home = 12;
|
|
@@ -1399,9 +1421,6 @@ const DownArrow = 16;
|
|
|
1399
1421
|
|
|
1400
1422
|
const CtrlCmd = 1 << 11 >>> 0;
|
|
1401
1423
|
|
|
1402
|
-
const FocusEditorCompletions = 9;
|
|
1403
|
-
const FocusEditorRename = 11;
|
|
1404
|
-
|
|
1405
1424
|
const getCommand = shortId => {
|
|
1406
1425
|
return {
|
|
1407
1426
|
command: 'Editor.executeWidgetCommand',
|
|
@@ -1433,6 +1452,10 @@ const getKeyBindings = () => {
|
|
|
1433
1452
|
key: CtrlCmd | Space$1,
|
|
1434
1453
|
...getCommand('toggleDetails'),
|
|
1435
1454
|
when: FocusEditorCompletions
|
|
1455
|
+
}, {
|
|
1456
|
+
key: Escape,
|
|
1457
|
+
...getCommand('close'),
|
|
1458
|
+
when: FocusEditorCompletions
|
|
1436
1459
|
}];
|
|
1437
1460
|
};
|
|
1438
1461
|
|
|
@@ -1617,10 +1640,12 @@ const filterCompletionItems = (completionItems, word) => {
|
|
|
1617
1640
|
if (result.length > 0) {
|
|
1618
1641
|
if (flags & Deprecated) {
|
|
1619
1642
|
// TODO avoid mutation
|
|
1643
|
+
// @ts-ignore
|
|
1620
1644
|
completionItem.matches = EmptyMatches;
|
|
1621
1645
|
deprecated.push(completionItem);
|
|
1622
1646
|
} else {
|
|
1623
1647
|
// TODO avoid mutation
|
|
1648
|
+
// @ts-ignore
|
|
1624
1649
|
completionItem.matches = result;
|
|
1625
1650
|
filteredCompletions.push(completionItem);
|
|
1626
1651
|
}
|
|
@@ -2199,8 +2224,8 @@ const render2 = (uid, diffResult) => {
|
|
|
2199
2224
|
const {
|
|
2200
2225
|
oldState,
|
|
2201
2226
|
newState
|
|
2202
|
-
} = get
|
|
2203
|
-
set$
|
|
2227
|
+
} = get(uid);
|
|
2228
|
+
set$1(uid, newState, newState);
|
|
2204
2229
|
const commands = applyRender(oldState, newState, diffResult);
|
|
2205
2230
|
return commands;
|
|
2206
2231
|
};
|
|
@@ -2210,7 +2235,8 @@ const terminate = () => {
|
|
|
2210
2235
|
};
|
|
2211
2236
|
|
|
2212
2237
|
const commandMap = {
|
|
2213
|
-
'Completions.
|
|
2238
|
+
'Completions.close': wrapCommand(close),
|
|
2239
|
+
'Completions.create': create,
|
|
2214
2240
|
'Completions.diff2': diff2,
|
|
2215
2241
|
'Completions.dispose': dispose,
|
|
2216
2242
|
'Completions.focusFirst': wrapCommand(focusFirst),
|
|
@@ -2224,18 +2250,18 @@ const commandMap = {
|
|
|
2224
2250
|
'Completions.handleWheel': wrapCommand(handleWheel),
|
|
2225
2251
|
'Completions.initialize': initialize,
|
|
2226
2252
|
'Completions.loadContent': wrapCommand(loadContent),
|
|
2253
|
+
'Completions.openDetails': wrapCommand(openDetails),
|
|
2227
2254
|
'Completions.render2': render2,
|
|
2228
2255
|
'Completions.selectCurrent': wrapCommand(selectCurrent),
|
|
2229
2256
|
'Completions.selectIndex': wrapCommand(selectIndex),
|
|
2230
|
-
'Completions.terminate': terminate
|
|
2231
|
-
'Completions.openDetails': wrapCommand(openDetails)
|
|
2257
|
+
'Completions.terminate': terminate
|
|
2232
2258
|
};
|
|
2233
2259
|
|
|
2234
2260
|
const listen = async () => {
|
|
2235
2261
|
const rpc = await WebWorkerRpcClient.create({
|
|
2236
2262
|
commandMap: commandMap
|
|
2237
2263
|
});
|
|
2238
|
-
set$
|
|
2264
|
+
set$2(rpc);
|
|
2239
2265
|
};
|
|
2240
2266
|
|
|
2241
2267
|
const main = async () => {
|