@lvce-editor/completion-worker 1.6.0 → 1.8.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.
@@ -967,7 +967,79 @@ const WebWorkerRpcClient = {
967
967
  create: create$4
968
968
  };
969
969
 
970
- const create$2 = () => {
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,12 +1099,13 @@ const create$2 = () => {
1027
1099
  };
1028
1100
 
1029
1101
  const {
1030
- get: get$1,
1031
- set: set$2,
1032
- wrapCommand
1033
- } = create$2();
1102
+ get,
1103
+ set: set$1,
1104
+ wrapCommand,
1105
+ dispose: dispose$1
1106
+ } = create$1();
1034
1107
 
1035
- const create$1 = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1108
+ const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1036
1109
  const state = {
1037
1110
  uid,
1038
1111
  items: [],
@@ -1055,7 +1128,7 @@ const create$1 = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1055
1128
  editorUid,
1056
1129
  editorLanguageId
1057
1130
  };
1058
- set$2(uid, state, state);
1131
+ set$1(uid, state, state);
1059
1132
  };
1060
1133
 
1061
1134
  const isEqual$4 = (oldState, newState) => {
@@ -1103,11 +1176,15 @@ const diff2 = uid => {
1103
1176
  const {
1104
1177
  oldState,
1105
1178
  newState
1106
- } = get$1(uid);
1179
+ } = get(uid);
1107
1180
  const diffResult = diff(oldState, newState);
1108
1181
  return diffResult;
1109
1182
  };
1110
1183
 
1184
+ const dispose = uid => {
1185
+ dispose$1(uid);
1186
+ };
1187
+
1111
1188
  const focusIndex = (state, index) => {
1112
1189
  const newState = {
1113
1190
  ...state,
@@ -1140,64 +1217,11 @@ const openDetails = async state => {
1140
1217
  return state;
1141
1218
  };
1142
1219
 
1143
- const rpcs = Object.create(null);
1144
- const set$a = (id, rpc) => {
1145
- rpcs[id] = rpc;
1146
- };
1147
- const get = id => {
1148
- return rpcs[id];
1149
- };
1150
-
1151
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1152
-
1153
- const create = rpcId => {
1154
- return {
1155
- // @ts-ignore
1156
- invoke(method, ...params) {
1157
- const rpc = get(rpcId);
1158
- // @ts-ignore
1159
- return rpc.invoke(method, ...params);
1160
- },
1161
- // @ts-ignore
1162
- invokeAndTransfer(method, ...params) {
1163
- const rpc = get(rpcId);
1164
- // @ts-ignore
1165
- return rpc.invokeAndTransfer(method, ...params);
1166
- },
1167
- set(rpc) {
1168
- set$a(rpcId, rpc);
1169
- }
1170
- };
1171
- };
1172
- const EditorWorker$1 = 99;
1173
- const ExtensionHostWorker = 44;
1174
- const {
1175
- invoke: invoke$9,
1176
- invokeAndTransfer: invokeAndTransfer$9,
1177
- set: set$9
1178
- } = create(EditorWorker$1);
1179
- const EditorWorker = {
1180
- __proto__: null,
1181
- invoke: invoke$9,
1182
- invokeAndTransfer: invokeAndTransfer$9,
1183
- set: set$9
1184
- };
1185
- const {
1186
- invoke: invoke$7,
1187
- set: set$7
1188
- } = create(ExtensionHostWorker);
1189
- const ExtensionHost = {
1190
- __proto__: null,
1191
- invoke: invoke$7,
1192
- set: set$7
1220
+ const applyEdit = async (editorUid, changes) => {
1221
+ // @ts-ignore
1222
+ await invoke$1('Editor.applyEdit2', editorUid, changes);
1193
1223
  };
1194
1224
 
1195
- const {
1196
- invoke: invoke$1,
1197
- set: set$1,
1198
- invokeAndTransfer
1199
- } = EditorWorker;
1200
-
1201
1225
  const OnCompletion = 'onCompletion';
1202
1226
 
1203
1227
  const CompletionExecute = 'ExtensionHostCompletion.execute';
@@ -1239,8 +1263,9 @@ const executeCompletionProvider = async (editorUid, editorLanguageId, offset) =>
1239
1263
  noProviderFoundMessage: 'no completion provider found',
1240
1264
  noProviderFoundResult: []});
1241
1265
  };
1242
- const executeResolveCompletionItem = async (editor, offset, name, completionItem) => {
1266
+ const executeResolveCompletionItem = async (editorUid, offset, name, completionItem) => {
1243
1267
  return execute({
1268
+ editorUid,
1244
1269
  event: OnCompletion,
1245
1270
  method: CompletionResolveExecute,
1246
1271
  args: [offset, name, completionItem],
@@ -1266,8 +1291,7 @@ const resolveCompletion = async (editorUid, name, completionItem) => {
1266
1291
  string(name);
1267
1292
  object(completionItem);
1268
1293
  const offset = getOffsetAtCursor(editorUid);
1269
- // @ts-ignore
1270
- const resolvedCompletionItem = await executeResolveCompletionItem(editor, offset, name, completionItem);
1294
+ const resolvedCompletionItem = await executeResolveCompletionItem(editorUid, offset, name, completionItem);
1271
1295
  return resolvedCompletionItem;
1272
1296
  } catch {
1273
1297
  return undefined;
@@ -1345,12 +1369,8 @@ const select = async (state, completionItem) => {
1345
1369
  leadingWord
1346
1370
  } = state;
1347
1371
  const changes = await getEdits(editorUid, leadingWord, completionItem);
1348
- // @ts-ignore
1349
- await invoke$1('Editor.applyEdit2', editorUid, changes);
1350
- // TODO remove completion widget from editor
1351
- return {
1352
- ...state
1353
- };
1372
+ await applyEdit(editorUid, changes);
1373
+ return close(state);
1354
1374
  };
1355
1375
 
1356
1376
  const selectIndex = async (state, index) => {
@@ -1382,6 +1402,7 @@ const getCommandIds = () => {
1382
1402
  };
1383
1403
 
1384
1404
  const Enter = 3;
1405
+ const Escape = 8;
1385
1406
  const Space$1 = 9;
1386
1407
  const End = 255;
1387
1408
  const Home = 12;
@@ -1390,11 +1411,6 @@ const DownArrow = 16;
1390
1411
 
1391
1412
  const CtrlCmd = 1 << 11 >>> 0;
1392
1413
 
1393
- const FocusEditorCompletions = 9;
1394
- const FocusEditorRename = 11;
1395
-
1396
- const Completion = 3;
1397
-
1398
1414
  const getCommand = shortId => {
1399
1415
  return {
1400
1416
  command: 'Editor.executeWidgetCommand',
@@ -1426,6 +1442,10 @@ const getKeyBindings = () => {
1426
1442
  key: CtrlCmd | Space$1,
1427
1443
  ...getCommand('toggleDetails'),
1428
1444
  when: FocusEditorCompletions
1445
+ }, {
1446
+ key: Escape,
1447
+ ...getCommand('close'),
1448
+ when: FocusEditorCompletions
1429
1449
  }];
1430
1450
  };
1431
1451
 
@@ -2192,8 +2212,8 @@ const render2 = (uid, diffResult) => {
2192
2212
  const {
2193
2213
  oldState,
2194
2214
  newState
2195
- } = get$1(uid);
2196
- set$2(uid, newState, newState);
2215
+ } = get(uid);
2216
+ set$1(uid, newState, newState);
2197
2217
  const commands = applyRender(oldState, newState, diffResult);
2198
2218
  return commands;
2199
2219
  };
@@ -2203,8 +2223,10 @@ const terminate = () => {
2203
2223
  };
2204
2224
 
2205
2225
  const commandMap = {
2206
- 'Completions.create': create$1,
2226
+ 'Completions.close': wrapCommand(close),
2227
+ 'Completions.create': create,
2207
2228
  'Completions.diff2': diff2,
2229
+ 'Completions.dispose': dispose,
2208
2230
  'Completions.focusFirst': wrapCommand(focusFirst),
2209
2231
  'Completions.focusIndex': wrapCommand(focusIndex),
2210
2232
  'Completions.focusNext': wrapCommand(focusNext),
@@ -2216,18 +2238,18 @@ const commandMap = {
2216
2238
  'Completions.handleWheel': wrapCommand(handleWheel),
2217
2239
  'Completions.initialize': initialize,
2218
2240
  'Completions.loadContent': wrapCommand(loadContent),
2241
+ 'Completions.openDetails': wrapCommand(openDetails),
2219
2242
  'Completions.render2': render2,
2220
2243
  'Completions.selectCurrent': wrapCommand(selectCurrent),
2221
2244
  'Completions.selectIndex': wrapCommand(selectIndex),
2222
- 'Completions.terminate': terminate,
2223
- 'Completions.openDetails': wrapCommand(openDetails)
2245
+ 'Completions.terminate': terminate
2224
2246
  };
2225
2247
 
2226
2248
  const listen = async () => {
2227
2249
  const rpc = await WebWorkerRpcClient.create({
2228
2250
  commandMap: commandMap
2229
2251
  });
2230
- set$1(rpc);
2252
+ set$2(rpc);
2231
2253
  };
2232
2254
 
2233
2255
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",