@lvce-editor/completion-worker 1.14.0 → 1.15.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 +123 -88
- package/package.json +1 -1
|
@@ -611,6 +611,16 @@ const constructError = (message, type, name) => {
|
|
|
611
611
|
}
|
|
612
612
|
return new ErrorConstructor(message);
|
|
613
613
|
};
|
|
614
|
+
const joinLines = lines => {
|
|
615
|
+
return lines.join(NewLine);
|
|
616
|
+
};
|
|
617
|
+
const splitLines = lines => {
|
|
618
|
+
return lines.split(NewLine);
|
|
619
|
+
};
|
|
620
|
+
const getCurrentStack = () => {
|
|
621
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
|
|
622
|
+
return currentStack;
|
|
623
|
+
};
|
|
614
624
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
615
625
|
return string.indexOf(NewLine, startIndex);
|
|
616
626
|
};
|
|
@@ -621,19 +631,16 @@ const getParentStack = error => {
|
|
|
621
631
|
}
|
|
622
632
|
return parentStack;
|
|
623
633
|
};
|
|
624
|
-
const joinLines = lines => {
|
|
625
|
-
return lines.join(NewLine);
|
|
626
|
-
};
|
|
627
634
|
const MethodNotFound = -32601;
|
|
628
635
|
const Custom = -32001;
|
|
629
|
-
const splitLines = lines => {
|
|
630
|
-
return lines.split(NewLine);
|
|
631
|
-
};
|
|
632
636
|
const restoreJsonRpcError = error => {
|
|
637
|
+
const currentStack = getCurrentStack();
|
|
633
638
|
if (error && error instanceof Error) {
|
|
639
|
+
if (typeof error.stack === 'string') {
|
|
640
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
641
|
+
}
|
|
634
642
|
return error;
|
|
635
643
|
}
|
|
636
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
637
644
|
if (error && error.code && error.code === MethodNotFound) {
|
|
638
645
|
const restoredError = new JsonRpcError(error.message);
|
|
639
646
|
const parentStack = getParentStack(error);
|
|
@@ -714,6 +721,17 @@ const getErrorType = prettyError => {
|
|
|
714
721
|
}
|
|
715
722
|
return undefined;
|
|
716
723
|
};
|
|
724
|
+
const isAlreadyStack = line => {
|
|
725
|
+
return line.trim().startsWith('at ');
|
|
726
|
+
};
|
|
727
|
+
const getStack = prettyError => {
|
|
728
|
+
const stackString = prettyError.stack || '';
|
|
729
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
730
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
731
|
+
return stackString.slice(newLineIndex + 1);
|
|
732
|
+
}
|
|
733
|
+
return stackString;
|
|
734
|
+
};
|
|
717
735
|
const getErrorProperty = (error, prettyError) => {
|
|
718
736
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
719
737
|
return {
|
|
@@ -726,7 +744,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
726
744
|
code: Custom,
|
|
727
745
|
message: prettyError.message,
|
|
728
746
|
data: {
|
|
729
|
-
stack: prettyError
|
|
747
|
+
stack: getStack(prettyError),
|
|
730
748
|
codeFrame: prettyError.codeFrame,
|
|
731
749
|
type: getErrorType(prettyError),
|
|
732
750
|
code: prettyError.code,
|
|
@@ -968,7 +986,7 @@ const WebWorkerRpcClient = {
|
|
|
968
986
|
};
|
|
969
987
|
|
|
970
988
|
const rpcs = Object.create(null);
|
|
971
|
-
const set$
|
|
989
|
+
const set$b = (id, rpc) => {
|
|
972
990
|
rpcs[id] = rpc;
|
|
973
991
|
};
|
|
974
992
|
const get$1 = id => {
|
|
@@ -992,22 +1010,22 @@ const create$2 = rpcId => {
|
|
|
992
1010
|
return rpc.invokeAndTransfer(method, ...params);
|
|
993
1011
|
},
|
|
994
1012
|
set(rpc) {
|
|
995
|
-
set$
|
|
1013
|
+
set$b(rpcId, rpc);
|
|
996
1014
|
}
|
|
997
1015
|
};
|
|
998
1016
|
};
|
|
999
1017
|
const EditorWorker$1 = 99;
|
|
1000
1018
|
const ExtensionHostWorker = 44;
|
|
1001
1019
|
const {
|
|
1002
|
-
invoke: invoke$
|
|
1003
|
-
invokeAndTransfer: invokeAndTransfer$
|
|
1004
|
-
set: set$
|
|
1020
|
+
invoke: invoke$a,
|
|
1021
|
+
invokeAndTransfer: invokeAndTransfer$a,
|
|
1022
|
+
set: set$a
|
|
1005
1023
|
} = create$2(EditorWorker$1);
|
|
1006
1024
|
const EditorWorker = {
|
|
1007
1025
|
__proto__: null,
|
|
1008
|
-
invoke: invoke$
|
|
1009
|
-
invokeAndTransfer: invokeAndTransfer$
|
|
1010
|
-
set: set$
|
|
1026
|
+
invoke: invoke$a,
|
|
1027
|
+
invokeAndTransfer: invokeAndTransfer$a,
|
|
1028
|
+
set: set$a
|
|
1011
1029
|
};
|
|
1012
1030
|
const {
|
|
1013
1031
|
invoke: invoke$7,
|
|
@@ -1223,6 +1241,68 @@ const applyEdit = async (editorUid, changes) => {
|
|
|
1223
1241
|
await invoke$1('Editor.applyEdit2', editorUid, changes);
|
|
1224
1242
|
};
|
|
1225
1243
|
|
|
1244
|
+
const getLines = async editorUid => {
|
|
1245
|
+
const lines = await invoke$1('Editor.getLines2', editorUid);
|
|
1246
|
+
return lines;
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
const getSelections = async editorUid => {
|
|
1250
|
+
const selections = await invoke$1('Editor.getSelections2', editorUid);
|
|
1251
|
+
return selections;
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
const getSelectionPairs = (selections, i) => {
|
|
1255
|
+
const first = selections[i];
|
|
1256
|
+
const second = selections[i + 1];
|
|
1257
|
+
const third = selections[i + 2];
|
|
1258
|
+
const fourth = selections[i + 3];
|
|
1259
|
+
if (first > third || first === third && second >= fourth) {
|
|
1260
|
+
return [third, fourth, first, second, 1];
|
|
1261
|
+
}
|
|
1262
|
+
return [first, second, third, fourth, 0];
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
const getSelectionText = (lines, range) => {
|
|
1266
|
+
const startRowIndex = range.start.rowIndex;
|
|
1267
|
+
const startColumnIndex = range.start.columnIndex;
|
|
1268
|
+
const endRowIndex = Math.min(range.end.rowIndex, lines.length - 1);
|
|
1269
|
+
const endColumnIndex = range.end.columnIndex;
|
|
1270
|
+
if (startRowIndex === endRowIndex) {
|
|
1271
|
+
return [lines[startRowIndex].slice(startColumnIndex, endColumnIndex)];
|
|
1272
|
+
}
|
|
1273
|
+
const selectedLines = [lines[startRowIndex].slice(startColumnIndex), ...lines.slice(startRowIndex + 1, endRowIndex), lines[endRowIndex].slice(0, endColumnIndex)];
|
|
1274
|
+
return selectedLines;
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
// TODO add more exact types
|
|
1278
|
+
const replaceRange = (lines, ranges, replacement, origin) => {
|
|
1279
|
+
const changes = [];
|
|
1280
|
+
const rangesLength = ranges.length;
|
|
1281
|
+
for (let i = 0; i < rangesLength; i += 4) {
|
|
1282
|
+
const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(ranges, i);
|
|
1283
|
+
const start = {
|
|
1284
|
+
rowIndex: selectionStartRow,
|
|
1285
|
+
columnIndex: selectionStartColumn
|
|
1286
|
+
};
|
|
1287
|
+
const end = {
|
|
1288
|
+
rowIndex: selectionEndRow,
|
|
1289
|
+
columnIndex: selectionEndColumn
|
|
1290
|
+
};
|
|
1291
|
+
const selection = {
|
|
1292
|
+
start,
|
|
1293
|
+
end
|
|
1294
|
+
};
|
|
1295
|
+
changes.push({
|
|
1296
|
+
start: start,
|
|
1297
|
+
end: end,
|
|
1298
|
+
inserted: replacement,
|
|
1299
|
+
deleted: getSelectionText(lines, selection),
|
|
1300
|
+
origin
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
return changes;
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1226
1306
|
const OnCompletion = 'onCompletion';
|
|
1227
1307
|
|
|
1228
1308
|
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
@@ -1279,13 +1359,6 @@ const getOffsetAtCursor = editorUid => {
|
|
|
1279
1359
|
return 0;
|
|
1280
1360
|
};
|
|
1281
1361
|
|
|
1282
|
-
// TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
|
|
1283
|
-
const getCompletions = async (editorUid, editorLanguageId) => {
|
|
1284
|
-
const offset = getOffsetAtCursor();
|
|
1285
|
-
const completions = await executeCompletionProvider(editorUid, editorLanguageId, offset);
|
|
1286
|
-
return completions;
|
|
1287
|
-
};
|
|
1288
|
-
|
|
1289
1362
|
// TODO don't send unnecessary parts of completion item like matches
|
|
1290
1363
|
const resolveCompletion = async (editorUid, name, completionItem) => {
|
|
1291
1364
|
try {
|
|
@@ -1299,68 +1372,6 @@ const resolveCompletion = async (editorUid, name, completionItem) => {
|
|
|
1299
1372
|
}
|
|
1300
1373
|
};
|
|
1301
1374
|
|
|
1302
|
-
const getLines = async editorUid => {
|
|
1303
|
-
const lines = await invoke$1('Editor.getLines2', editorUid);
|
|
1304
|
-
return lines;
|
|
1305
|
-
};
|
|
1306
|
-
|
|
1307
|
-
const getSelections = async editorUid => {
|
|
1308
|
-
const selections = await invoke$1('Editor.getSelections2', editorUid);
|
|
1309
|
-
return selections;
|
|
1310
|
-
};
|
|
1311
|
-
|
|
1312
|
-
const getSelectionPairs = (selections, i) => {
|
|
1313
|
-
const first = selections[i];
|
|
1314
|
-
const second = selections[i + 1];
|
|
1315
|
-
const third = selections[i + 2];
|
|
1316
|
-
const fourth = selections[i + 3];
|
|
1317
|
-
if (first > third || first === third && second >= fourth) {
|
|
1318
|
-
return [third, fourth, first, second, 1];
|
|
1319
|
-
}
|
|
1320
|
-
return [first, second, third, fourth, 0];
|
|
1321
|
-
};
|
|
1322
|
-
|
|
1323
|
-
const getSelectionText = (lines, range) => {
|
|
1324
|
-
const startRowIndex = range.start.rowIndex;
|
|
1325
|
-
const startColumnIndex = range.start.columnIndex;
|
|
1326
|
-
const endRowIndex = Math.min(range.end.rowIndex, lines.length - 1);
|
|
1327
|
-
const endColumnIndex = range.end.columnIndex;
|
|
1328
|
-
if (startRowIndex === endRowIndex) {
|
|
1329
|
-
return [lines[startRowIndex].slice(startColumnIndex, endColumnIndex)];
|
|
1330
|
-
}
|
|
1331
|
-
const selectedLines = [lines[startRowIndex].slice(startColumnIndex), ...lines.slice(startRowIndex + 1, endRowIndex), lines[endRowIndex].slice(0, endColumnIndex)];
|
|
1332
|
-
return selectedLines;
|
|
1333
|
-
};
|
|
1334
|
-
|
|
1335
|
-
// TODO add more exact types
|
|
1336
|
-
const replaceRange = (lines, ranges, replacement, origin) => {
|
|
1337
|
-
const changes = [];
|
|
1338
|
-
const rangesLength = ranges.length;
|
|
1339
|
-
for (let i = 0; i < rangesLength; i += 4) {
|
|
1340
|
-
const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(ranges, i);
|
|
1341
|
-
const start = {
|
|
1342
|
-
rowIndex: selectionStartRow,
|
|
1343
|
-
columnIndex: selectionStartColumn
|
|
1344
|
-
};
|
|
1345
|
-
const end = {
|
|
1346
|
-
rowIndex: selectionEndRow,
|
|
1347
|
-
columnIndex: selectionEndColumn
|
|
1348
|
-
};
|
|
1349
|
-
const selection = {
|
|
1350
|
-
start,
|
|
1351
|
-
end
|
|
1352
|
-
};
|
|
1353
|
-
changes.push({
|
|
1354
|
-
start: start,
|
|
1355
|
-
end: end,
|
|
1356
|
-
inserted: replacement,
|
|
1357
|
-
deleted: getSelectionText(lines, selection),
|
|
1358
|
-
origin
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
return changes;
|
|
1362
|
-
};
|
|
1363
|
-
|
|
1364
1375
|
const getEdits = async (editorUid, leadingWord, completionItem) => {
|
|
1365
1376
|
const word = completionItem.label;
|
|
1366
1377
|
const resolvedItem = await resolveCompletion(editorUid, word, completionItem);
|
|
@@ -1859,6 +1870,24 @@ const initialize = async () => {
|
|
|
1859
1870
|
set(rpc);
|
|
1860
1871
|
};
|
|
1861
1872
|
|
|
1873
|
+
const error = message => {
|
|
1874
|
+
// TODO send this to error worker for logging
|
|
1875
|
+
console.error(message);
|
|
1876
|
+
};
|
|
1877
|
+
|
|
1878
|
+
// TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
|
|
1879
|
+
const getCompletions = async (editorUid, editorLanguageId) => {
|
|
1880
|
+
try {
|
|
1881
|
+
const offset = getOffsetAtCursor(editorUid);
|
|
1882
|
+
const completions = await executeCompletionProvider(editorUid, editorLanguageId, offset);
|
|
1883
|
+
return completions;
|
|
1884
|
+
} catch (error$1) {
|
|
1885
|
+
error(`Failed to get completions:`);
|
|
1886
|
+
error(error$1);
|
|
1887
|
+
return [];
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1862
1891
|
const getFinalDeltaY = (height, itemHeight, itemsLength) => {
|
|
1863
1892
|
const contentHeight = itemsLength * itemHeight;
|
|
1864
1893
|
const finalDeltaY = Math.max(contentHeight - height, 0);
|
|
@@ -2237,7 +2266,7 @@ const getHighlights = item => {
|
|
|
2237
2266
|
};
|
|
2238
2267
|
|
|
2239
2268
|
const getLabel = item => {
|
|
2240
|
-
return item.label;
|
|
2269
|
+
return item.label || '';
|
|
2241
2270
|
};
|
|
2242
2271
|
|
|
2243
2272
|
const getTop = (i, minLineY, itemHeight, relative) => {
|
|
@@ -2270,9 +2299,15 @@ const renderItems = (oldState, newState) => {
|
|
|
2270
2299
|
const {
|
|
2271
2300
|
uid,
|
|
2272
2301
|
height,
|
|
2273
|
-
deltaY
|
|
2302
|
+
deltaY,
|
|
2303
|
+
items,
|
|
2304
|
+
itemHeight,
|
|
2305
|
+
leadingWord,
|
|
2306
|
+
minLineY,
|
|
2307
|
+
maxLineY,
|
|
2308
|
+
focusedIndex
|
|
2274
2309
|
} = newState;
|
|
2275
|
-
const visibleItems = getVisibleItems(
|
|
2310
|
+
const visibleItems = getVisibleItems(items, itemHeight, leadingWord, minLineY, maxLineY, focusedIndex, deltaY);
|
|
2276
2311
|
const contentHeight = newState.items.length * newState.itemHeight;
|
|
2277
2312
|
const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
|
|
2278
2313
|
const scrollBarTop = getScrollBarTop(height, contentHeight, deltaY);
|