@lvce-editor/completion-worker 1.24.0 → 1.26.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.
@@ -626,7 +626,8 @@ const splitLines = lines => {
626
626
  return lines.split(NewLine);
627
627
  };
628
628
  const getCurrentStack = () => {
629
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
629
+ const stackLinesToSkip = 3;
630
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
630
631
  return currentStack;
631
632
  };
632
633
  const getNewLineIndex = (string, startIndex = undefined) => {
@@ -897,6 +898,12 @@ const invokeAndTransfer$1 = (ipc, method, ...params) => {
897
898
  return invokeHelper(ipc, method, params, true);
898
899
  };
899
900
 
901
+ class CommandNotFoundError extends Error {
902
+ constructor(command) {
903
+ super(`Command not found ${command}`);
904
+ this.name = 'CommandNotFoundError';
905
+ }
906
+ }
900
907
  const commands = Object.create(null);
901
908
  const register = commandMap => {
902
909
  Object.assign(commands, commandMap);
@@ -907,7 +914,7 @@ const getCommand$1 = key => {
907
914
  const execute$1 = (command, ...args) => {
908
915
  const fn = getCommand$1(command);
909
916
  if (!fn) {
910
- throw new Error(`command not found ${command}`);
917
+ throw new CommandNotFoundError(command);
911
918
  }
912
919
  return fn(...args);
913
920
  };
@@ -1172,6 +1179,10 @@ const getPositionAtCursor$2 = async parentUid => {
1172
1179
  const position = await invoke$c('Editor.getPositionAtCursor', parentUid);
1173
1180
  return position;
1174
1181
  };
1182
+ const getOffsetAtCursor$2 = async editorId => {
1183
+ // @ts-ignore
1184
+ return await invoke$c('Editor.getOffsetAtCursor', editorId);
1185
+ };
1175
1186
  const getSelections$2 = async editorUid => {
1176
1187
  const selections = await invoke$c('Editor.getSelections2', editorUid);
1177
1188
  return selections;
@@ -1189,6 +1200,7 @@ const EditorWorker$2 = {
1189
1200
  closeWidget: closeWidget$1,
1190
1201
  dispose: dispose$c,
1191
1202
  getLines: getLines$2,
1203
+ getOffsetAtCursor: getOffsetAtCursor$2,
1192
1204
  getPositionAtCursor: getPositionAtCursor$2,
1193
1205
  getSelections: getSelections$2,
1194
1206
  getWordAt: getWordAt$1,
@@ -1219,6 +1231,7 @@ const {
1219
1231
  getPositionAtCursor: getPositionAtCursor$1,
1220
1232
  getSelections: getSelections$1,
1221
1233
  getWordAt,
1234
+ getOffsetAtCursor: getOffsetAtCursor$1,
1222
1235
  getWordAtOffset2,
1223
1236
  getWordBefore: getWordBefore$1,
1224
1237
  invokeAndTransfer
@@ -1231,6 +1244,7 @@ const EditorWorker = {
1231
1244
  closeWidget,
1232
1245
  dispose: dispose$2,
1233
1246
  getLines: getLines$1,
1247
+ getOffsetAtCursor: getOffsetAtCursor$1,
1234
1248
  getPositionAtCursor: getPositionAtCursor$1,
1235
1249
  getSelections: getSelections$1,
1236
1250
  getWordAt,
@@ -1376,8 +1390,7 @@ const openDetails = async state => {
1376
1390
  };
1377
1391
 
1378
1392
  const applyEdit = async (editorUid, changes) => {
1379
- // @ts-ignore
1380
- await invoke$1('Editor.applyEdit2', editorUid, changes);
1393
+ await applyEdit$1(editorUid, changes);
1381
1394
  };
1382
1395
 
1383
1396
  const {
@@ -1457,9 +1470,7 @@ const execute = async ({
1457
1470
  editorUid,
1458
1471
  args,
1459
1472
  event,
1460
- method,
1461
- noProviderFoundMessage,
1462
- noProviderFoundResult = undefined
1473
+ method
1463
1474
  }) => {
1464
1475
  const fullEvent = `${event}:${editorLanguageId}`;
1465
1476
  await activateByEvent(fullEvent);
@@ -1473,23 +1484,18 @@ const executeCompletionProvider = async (editorUid, editorLanguageId, offset) =>
1473
1484
  editorLanguageId,
1474
1485
  event: OnCompletion,
1475
1486
  method: CompletionExecute,
1476
- args: [offset],
1477
- noProviderFoundMessage: 'no completion provider found',
1478
- noProviderFoundResult: []});
1487
+ args: [offset]});
1479
1488
  };
1480
1489
  const executeResolveCompletionItem = async (editorUid, offset, name, completionItem) => {
1481
1490
  return execute({
1482
1491
  editorUid,
1483
1492
  event: OnCompletion,
1484
1493
  method: CompletionResolveExecute,
1485
- args: [offset, name, completionItem],
1486
- noProviderFoundMessage: 'no completion provider found',
1487
- noProviderFoundResult: []});
1494
+ args: [offset, name, completionItem]});
1488
1495
  };
1489
1496
 
1490
- const getOffsetAtCursor = editorUid => {
1491
- // TODO ask editor worker
1492
- return 0;
1497
+ const getOffsetAtCursor = async editorUid => {
1498
+ return getOffsetAtCursor$1(editorUid);
1493
1499
  };
1494
1500
 
1495
1501
  // TODO don't send unnecessary parts of completion item like matches
@@ -1497,7 +1503,7 @@ const resolveCompletion = async (editorUid, name, completionItem) => {
1497
1503
  try {
1498
1504
  string(name);
1499
1505
  object(completionItem);
1500
- const offset = getOffsetAtCursor(editorUid);
1506
+ const offset = await getOffsetAtCursor(editorUid);
1501
1507
  const resolvedCompletionItem = await executeResolveCompletionItem(editorUid, offset, name, completionItem);
1502
1508
  return resolvedCompletionItem;
1503
1509
  } catch {
@@ -2018,7 +2024,7 @@ const error = message => {
2018
2024
  // TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
2019
2025
  const getCompletions = async (editorUid, editorLanguageId) => {
2020
2026
  try {
2021
- const offset = getOffsetAtCursor(editorUid);
2027
+ const offset = await getOffsetAtCursor(editorUid);
2022
2028
  const completions = await executeCompletionProvider(editorUid, editorLanguageId, offset);
2023
2029
  return completions;
2024
2030
  } catch (error$1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "1.24.0",
3
+ "version": "1.26.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",