@lvce-editor/editor-worker 1.5.1 → 1.7.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/editorWorkerMain.js +512 -27
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -71,7 +71,7 @@ const getNewColor = (x, max) => {
|
|
|
71
71
|
const newColor = `hsl(${hue}, 100%, 50%)`;
|
|
72
72
|
return newColor;
|
|
73
73
|
};
|
|
74
|
-
const loadContent$
|
|
74
|
+
const loadContent$2 = state => {
|
|
75
75
|
const max = 300;
|
|
76
76
|
const x = 20;
|
|
77
77
|
const color = getNewColor(x, max);
|
|
@@ -464,9 +464,13 @@ const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing,
|
|
|
464
464
|
return width;
|
|
465
465
|
};
|
|
466
466
|
|
|
467
|
+
const Dash = '-';
|
|
468
|
+
const Dot = '.';
|
|
467
469
|
const EmptyString = '';
|
|
468
470
|
const Space = ' ';
|
|
469
471
|
const Tab = '\t';
|
|
472
|
+
const Underline = '_';
|
|
473
|
+
const T = 't';
|
|
470
474
|
|
|
471
475
|
const normalizeText = (text, normalize, tabSize) => {
|
|
472
476
|
if (normalize) {
|
|
@@ -1695,6 +1699,8 @@ const {
|
|
|
1695
1699
|
invoke: invoke$2
|
|
1696
1700
|
} = createRpc(ExtensionHostWorker);
|
|
1697
1701
|
|
|
1702
|
+
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
1703
|
+
const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
|
|
1698
1704
|
const HoverExecute = 'ExtensionHostHover.execute';
|
|
1699
1705
|
const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
|
|
1700
1706
|
|
|
@@ -6180,6 +6186,493 @@ const editorUnindent = editor => {
|
|
|
6180
6186
|
|
|
6181
6187
|
// editor.lines //?
|
|
6182
6188
|
|
|
6189
|
+
const OnCompletion = 'onCompletion';
|
|
6190
|
+
const OnHover = 'onHover';
|
|
6191
|
+
|
|
6192
|
+
// TODO add tests for this
|
|
6193
|
+
const activateByEvent = async event => {
|
|
6194
|
+
await invoke$3('ExtensionHostManagement.activateByEvent', event);
|
|
6195
|
+
};
|
|
6196
|
+
|
|
6197
|
+
const execute = async ({
|
|
6198
|
+
editor,
|
|
6199
|
+
args,
|
|
6200
|
+
event,
|
|
6201
|
+
method,
|
|
6202
|
+
noProviderFoundMessage,
|
|
6203
|
+
noProviderFoundResult = undefined
|
|
6204
|
+
}) => {
|
|
6205
|
+
const fullEvent = `${event}:${editor.languageId}`;
|
|
6206
|
+
await activateByEvent(fullEvent);
|
|
6207
|
+
const result = await invoke$2(method, editor.uid, ...args);
|
|
6208
|
+
return result;
|
|
6209
|
+
};
|
|
6210
|
+
|
|
6211
|
+
const combineResults = results => {
|
|
6212
|
+
return results[0] ?? [];
|
|
6213
|
+
};
|
|
6214
|
+
const executeCompletionProvider = (editor, offset) => {
|
|
6215
|
+
return execute({
|
|
6216
|
+
editor,
|
|
6217
|
+
event: OnCompletion,
|
|
6218
|
+
method: CompletionExecute,
|
|
6219
|
+
args: [offset],
|
|
6220
|
+
noProviderFoundMessage: 'no completion provider found',
|
|
6221
|
+
noProviderFoundResult: [],
|
|
6222
|
+
combineResults
|
|
6223
|
+
});
|
|
6224
|
+
};
|
|
6225
|
+
const combineResultsResolve = items => {
|
|
6226
|
+
return items[0] ?? undefined;
|
|
6227
|
+
};
|
|
6228
|
+
const executeResolveCompletionItem = (editor, offset, name, completionItem) => {
|
|
6229
|
+
return execute({
|
|
6230
|
+
editor,
|
|
6231
|
+
event: OnCompletion,
|
|
6232
|
+
method: CompletionResolveExecute,
|
|
6233
|
+
args: [offset, name, completionItem],
|
|
6234
|
+
noProviderFoundMessage: 'no completion provider found',
|
|
6235
|
+
noProviderFoundResult: [],
|
|
6236
|
+
combineResults: combineResultsResolve
|
|
6237
|
+
});
|
|
6238
|
+
};
|
|
6239
|
+
|
|
6240
|
+
// TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
|
|
6241
|
+
const getCompletions = async editor => {
|
|
6242
|
+
const {
|
|
6243
|
+
selections
|
|
6244
|
+
} = editor;
|
|
6245
|
+
const rowIndex = selections[0];
|
|
6246
|
+
const columnIndex = selections[1];
|
|
6247
|
+
// Editor.sync(editor)
|
|
6248
|
+
const offset = await offsetAt(editor, rowIndex, columnIndex);
|
|
6249
|
+
const completions = await executeCompletionProvider(editor, offset);
|
|
6250
|
+
return completions;
|
|
6251
|
+
};
|
|
6252
|
+
|
|
6253
|
+
// TODO don't send unnecessary parts of completion item like matches
|
|
6254
|
+
const resolveCompletion = async (editor, name, completionItem) => {
|
|
6255
|
+
try {
|
|
6256
|
+
object(editor);
|
|
6257
|
+
string(name);
|
|
6258
|
+
object(completionItem);
|
|
6259
|
+
const rowIndex = editor.selections[0];
|
|
6260
|
+
const columnIndex = editor.selections[1];
|
|
6261
|
+
const offset = await offsetAt(editor, rowIndex, columnIndex);
|
|
6262
|
+
// @ts-ignore
|
|
6263
|
+
const resolvedCompletionItem = await executeResolveCompletionItem(editor, offset, name, completionItem);
|
|
6264
|
+
return resolvedCompletionItem;
|
|
6265
|
+
} catch {
|
|
6266
|
+
return undefined;
|
|
6267
|
+
}
|
|
6268
|
+
};
|
|
6269
|
+
|
|
6270
|
+
const None = 1;
|
|
6271
|
+
|
|
6272
|
+
const EmptyMatches = [];
|
|
6273
|
+
|
|
6274
|
+
const Diagonal = 1;
|
|
6275
|
+
const Left = 2;
|
|
6276
|
+
|
|
6277
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
6278
|
+
|
|
6279
|
+
const createTable = size => {
|
|
6280
|
+
const table = [];
|
|
6281
|
+
for (let i = 0; i < size; i++) {
|
|
6282
|
+
const row = new Uint8Array(size);
|
|
6283
|
+
table.push(row);
|
|
6284
|
+
}
|
|
6285
|
+
return table;
|
|
6286
|
+
};
|
|
6287
|
+
|
|
6288
|
+
const isLowerCase = char => {
|
|
6289
|
+
return char === char.toLowerCase();
|
|
6290
|
+
};
|
|
6291
|
+
|
|
6292
|
+
const isUpperCase = char => {
|
|
6293
|
+
return char === char.toUpperCase();
|
|
6294
|
+
};
|
|
6295
|
+
|
|
6296
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
6297
|
+
const isGap = (columnCharBefore, columnChar) => {
|
|
6298
|
+
switch (columnCharBefore) {
|
|
6299
|
+
case Dash:
|
|
6300
|
+
case Underline:
|
|
6301
|
+
case EmptyString:
|
|
6302
|
+
case T:
|
|
6303
|
+
case Space:
|
|
6304
|
+
case Dot:
|
|
6305
|
+
return true;
|
|
6306
|
+
}
|
|
6307
|
+
if (isLowerCase(columnCharBefore) && isUpperCase(columnChar)) {
|
|
6308
|
+
return true;
|
|
6309
|
+
}
|
|
6310
|
+
return false;
|
|
6311
|
+
};
|
|
6312
|
+
|
|
6313
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
6314
|
+
const getScore = (rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, column, wordLength, isDiagonalMatch) => {
|
|
6315
|
+
if (rowCharLow !== columnCharLow) {
|
|
6316
|
+
return -1;
|
|
6317
|
+
}
|
|
6318
|
+
const isMatch = rowChar === columnChar;
|
|
6319
|
+
if (isMatch) {
|
|
6320
|
+
if (isDiagonalMatch) {
|
|
6321
|
+
return 8;
|
|
6322
|
+
}
|
|
6323
|
+
if (isGap(columnCharBefore, columnChar)) {
|
|
6324
|
+
return 8;
|
|
6325
|
+
}
|
|
6326
|
+
return 5;
|
|
6327
|
+
}
|
|
6328
|
+
if (isGap(columnCharBefore, columnChar)) {
|
|
6329
|
+
return 8;
|
|
6330
|
+
}
|
|
6331
|
+
return 5;
|
|
6332
|
+
};
|
|
6333
|
+
|
|
6334
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
6335
|
+
|
|
6336
|
+
const isPatternInWord = (patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) => {
|
|
6337
|
+
while (patternPos < patternLen && wordPos < wordLen) {
|
|
6338
|
+
if (patternLow[patternPos] === wordLow[wordPos]) {
|
|
6339
|
+
patternPos += 1;
|
|
6340
|
+
}
|
|
6341
|
+
wordPos += 1;
|
|
6342
|
+
}
|
|
6343
|
+
return patternPos === patternLen; // pattern must be exhausted
|
|
6344
|
+
};
|
|
6345
|
+
|
|
6346
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
6347
|
+
const traceHighlights = (table, arrows, patternLength, wordLength) => {
|
|
6348
|
+
let row = patternLength;
|
|
6349
|
+
let column = wordLength;
|
|
6350
|
+
const matches = [];
|
|
6351
|
+
while (row >= 1 && column >= 1) {
|
|
6352
|
+
const arrow = arrows[row][column];
|
|
6353
|
+
if (arrow === Left) {
|
|
6354
|
+
column--;
|
|
6355
|
+
} else if (arrow === Diagonal) {
|
|
6356
|
+
row--;
|
|
6357
|
+
column--;
|
|
6358
|
+
const start = column + 1;
|
|
6359
|
+
while (row >= 1 && column >= 1) {
|
|
6360
|
+
const arrow = arrows[row][column];
|
|
6361
|
+
if (arrow === Left) {
|
|
6362
|
+
break;
|
|
6363
|
+
}
|
|
6364
|
+
if (arrow === Diagonal) {
|
|
6365
|
+
row--;
|
|
6366
|
+
column--;
|
|
6367
|
+
}
|
|
6368
|
+
}
|
|
6369
|
+
const end = column;
|
|
6370
|
+
matches.unshift(end, start);
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
matches.unshift(table[patternLength][wordLength - 1]);
|
|
6374
|
+
return matches;
|
|
6375
|
+
};
|
|
6376
|
+
|
|
6377
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
6378
|
+
const gridSize = 128;
|
|
6379
|
+
const table = createTable(gridSize);
|
|
6380
|
+
const arrows = createTable(gridSize);
|
|
6381
|
+
// @ts-ignore
|
|
6382
|
+
createTable(gridSize);
|
|
6383
|
+
const filterCompletionItem = (pattern, word) => {
|
|
6384
|
+
const patternLength = Math.min(pattern.length, gridSize - 1);
|
|
6385
|
+
const wordLength = Math.min(word.length, gridSize - 1);
|
|
6386
|
+
const patternLower = pattern.toLowerCase();
|
|
6387
|
+
const wordLower = word.toLowerCase();
|
|
6388
|
+
if (!isPatternInWord(patternLower, 0, patternLength, wordLower, 0, wordLength)) {
|
|
6389
|
+
return EmptyMatches;
|
|
6390
|
+
}
|
|
6391
|
+
let strongMatch = false;
|
|
6392
|
+
for (let row = 1; row < patternLength + 1; row++) {
|
|
6393
|
+
const rowChar = pattern[row - 1];
|
|
6394
|
+
const rowCharLow = patternLower[row - 1];
|
|
6395
|
+
for (let column = 1; column < wordLength + 1; column++) {
|
|
6396
|
+
const columnChar = word[column - 1];
|
|
6397
|
+
const columnCharLow = wordLower[column - 1];
|
|
6398
|
+
const columnCharBefore = word[column - 2] || '';
|
|
6399
|
+
const isDiagonalMatch = arrows[row - 1][column - 1] === Diagonal;
|
|
6400
|
+
const score = getScore(rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, column, wordLength, isDiagonalMatch);
|
|
6401
|
+
if (row === 1 && score > 5) {
|
|
6402
|
+
strongMatch = true;
|
|
6403
|
+
}
|
|
6404
|
+
let diagonalScore = score + table[row - 1][column - 1];
|
|
6405
|
+
if (isDiagonalMatch && score !== -1) {
|
|
6406
|
+
diagonalScore += 2;
|
|
6407
|
+
}
|
|
6408
|
+
const leftScore = table[row][column - 1];
|
|
6409
|
+
if (leftScore > diagonalScore) {
|
|
6410
|
+
table[row][column] = leftScore;
|
|
6411
|
+
arrows[row][column] = Left;
|
|
6412
|
+
} else {
|
|
6413
|
+
table[row][column] = diagonalScore;
|
|
6414
|
+
arrows[row][column] = Diagonal;
|
|
6415
|
+
}
|
|
6416
|
+
}
|
|
6417
|
+
}
|
|
6418
|
+
if (!strongMatch) {
|
|
6419
|
+
return EmptyMatches;
|
|
6420
|
+
}
|
|
6421
|
+
// printTables(pattern, 0, word, 0)
|
|
6422
|
+
const highlights = traceHighlights(table, arrows, patternLength, wordLength);
|
|
6423
|
+
return highlights;
|
|
6424
|
+
};
|
|
6425
|
+
|
|
6426
|
+
const Deprecated = 1 << 0;
|
|
6427
|
+
|
|
6428
|
+
const addEmptyMatch = item => {
|
|
6429
|
+
return {
|
|
6430
|
+
...item,
|
|
6431
|
+
matches: EmptyMatches
|
|
6432
|
+
};
|
|
6433
|
+
};
|
|
6434
|
+
const filterCompletionItems = (completionItems, word) => {
|
|
6435
|
+
if (word === EmptyString) {
|
|
6436
|
+
return completionItems.map(addEmptyMatch);
|
|
6437
|
+
}
|
|
6438
|
+
const filteredCompletions = [];
|
|
6439
|
+
const deprecated = [];
|
|
6440
|
+
for (const completionItem of completionItems) {
|
|
6441
|
+
const {
|
|
6442
|
+
label,
|
|
6443
|
+
flags
|
|
6444
|
+
} = completionItem;
|
|
6445
|
+
const result = filterCompletionItem(word, label);
|
|
6446
|
+
if (result !== EmptyMatches) {
|
|
6447
|
+
if (flags & Deprecated) {
|
|
6448
|
+
// TODO avoid mutation
|
|
6449
|
+
completionItem.matches = EmptyMatches;
|
|
6450
|
+
deprecated.push(completionItem);
|
|
6451
|
+
} else {
|
|
6452
|
+
// TODO avoid mutation
|
|
6453
|
+
completionItem.matches = result;
|
|
6454
|
+
filteredCompletions.push(completionItem);
|
|
6455
|
+
}
|
|
6456
|
+
}
|
|
6457
|
+
}
|
|
6458
|
+
if (deprecated.length > 0) {
|
|
6459
|
+
filteredCompletions.push(...deprecated);
|
|
6460
|
+
}
|
|
6461
|
+
return filteredCompletions;
|
|
6462
|
+
};
|
|
6463
|
+
|
|
6464
|
+
const getFinalDeltaY = (height, itemHeight, itemsLength) => {
|
|
6465
|
+
const contentHeight = itemsLength * itemHeight;
|
|
6466
|
+
const finalDeltaY = Math.max(contentHeight - height, 0);
|
|
6467
|
+
return finalDeltaY;
|
|
6468
|
+
};
|
|
6469
|
+
|
|
6470
|
+
const getListHeight = (itemsLength, itemHeight, maxHeight) => {
|
|
6471
|
+
number$1(itemsLength);
|
|
6472
|
+
number$1(itemHeight);
|
|
6473
|
+
number$1(maxHeight);
|
|
6474
|
+
if (itemsLength === 0) {
|
|
6475
|
+
return itemHeight;
|
|
6476
|
+
}
|
|
6477
|
+
const totalHeight = itemsLength * itemHeight;
|
|
6478
|
+
return Math.min(totalHeight, maxHeight);
|
|
6479
|
+
};
|
|
6480
|
+
|
|
6481
|
+
const RE_WORD = /[\w\-]+$/;
|
|
6482
|
+
const getWordAtOffset = editor => {
|
|
6483
|
+
const {
|
|
6484
|
+
lines,
|
|
6485
|
+
selections
|
|
6486
|
+
} = editor;
|
|
6487
|
+
const rowIndex = selections[0];
|
|
6488
|
+
const columnIndex = selections[1];
|
|
6489
|
+
const line = lines[rowIndex];
|
|
6490
|
+
const part = line.slice(0, columnIndex);
|
|
6491
|
+
const wordMatch = part.match(RE_WORD);
|
|
6492
|
+
if (wordMatch) {
|
|
6493
|
+
return wordMatch[0];
|
|
6494
|
+
}
|
|
6495
|
+
return '';
|
|
6496
|
+
};
|
|
6497
|
+
const handleEditorType = (editorUid, state, text) => {
|
|
6498
|
+
const editor = getEditor(editorUid);
|
|
6499
|
+
const {
|
|
6500
|
+
unfilteredItems,
|
|
6501
|
+
itemHeight,
|
|
6502
|
+
maxHeight
|
|
6503
|
+
} = state;
|
|
6504
|
+
const rowIndex = editor.selections[0];
|
|
6505
|
+
const columnIndex = editor.selections[1];
|
|
6506
|
+
const x$1 = x(editor, rowIndex, columnIndex);
|
|
6507
|
+
// @ts-ignore
|
|
6508
|
+
const y$1 = y(editor, rowIndex);
|
|
6509
|
+
const wordAtOffset = getWordAtOffset(editor);
|
|
6510
|
+
const items = filterCompletionItems(unfilteredItems, wordAtOffset);
|
|
6511
|
+
const newMinLineY = 0;
|
|
6512
|
+
const newMaxLineY = Math.min(items.length, 8);
|
|
6513
|
+
const height = getListHeight(items.length, itemHeight, maxHeight);
|
|
6514
|
+
const finalDeltaY = items.length * itemHeight - height;
|
|
6515
|
+
return {
|
|
6516
|
+
...state,
|
|
6517
|
+
items,
|
|
6518
|
+
x: x$1,
|
|
6519
|
+
y: y$1,
|
|
6520
|
+
minLineY: newMinLineY,
|
|
6521
|
+
maxLineY: newMaxLineY,
|
|
6522
|
+
leadingWord: wordAtOffset,
|
|
6523
|
+
height,
|
|
6524
|
+
finalDeltaY
|
|
6525
|
+
};
|
|
6526
|
+
};
|
|
6527
|
+
const handleEditorDeleteLeft = (editorUid, state) => {
|
|
6528
|
+
const editor = getEditor(editorUid);
|
|
6529
|
+
const {
|
|
6530
|
+
unfilteredItems,
|
|
6531
|
+
itemHeight,
|
|
6532
|
+
maxHeight
|
|
6533
|
+
} = state;
|
|
6534
|
+
const rowIndex = editor.selections[0];
|
|
6535
|
+
const columnIndex = editor.selections[1];
|
|
6536
|
+
const x$1 = x(editor, rowIndex, columnIndex);
|
|
6537
|
+
// @ts-ignore
|
|
6538
|
+
const y$1 = y(editor, rowIndex);
|
|
6539
|
+
const wordAtOffset = getWordAtOffset(editor);
|
|
6540
|
+
if (!wordAtOffset) {
|
|
6541
|
+
editor.completionState = None;
|
|
6542
|
+
return {
|
|
6543
|
+
...state,
|
|
6544
|
+
disposed: true
|
|
6545
|
+
};
|
|
6546
|
+
}
|
|
6547
|
+
const items = filterCompletionItems(unfilteredItems, wordAtOffset);
|
|
6548
|
+
const newMaxLineY = Math.min(items.length, 8);
|
|
6549
|
+
const height = getListHeight(items.length, itemHeight, maxHeight);
|
|
6550
|
+
return {
|
|
6551
|
+
...state,
|
|
6552
|
+
items,
|
|
6553
|
+
x: x$1,
|
|
6554
|
+
y: y$1,
|
|
6555
|
+
maxLineY: newMaxLineY,
|
|
6556
|
+
leadingWord: wordAtOffset,
|
|
6557
|
+
height
|
|
6558
|
+
};
|
|
6559
|
+
};
|
|
6560
|
+
const dispose = state => {
|
|
6561
|
+
return {
|
|
6562
|
+
...state,
|
|
6563
|
+
disposed: true
|
|
6564
|
+
};
|
|
6565
|
+
};
|
|
6566
|
+
const disposeWithEditor = (state, editor) => {
|
|
6567
|
+
editor.completionState = None;
|
|
6568
|
+
editor.completionUid = 0;
|
|
6569
|
+
// Focus.removeAdditionalFocus(FocusKey.EditorCompletion)
|
|
6570
|
+
return dispose(state);
|
|
6571
|
+
};
|
|
6572
|
+
const handleEditorClick = disposeWithEditor;
|
|
6573
|
+
const handleEditorBlur = disposeWithEditor;
|
|
6574
|
+
const loadContent$1 = async (editorUid, state) => {
|
|
6575
|
+
const editor = getEditor(editorUid);
|
|
6576
|
+
const {
|
|
6577
|
+
itemHeight,
|
|
6578
|
+
maxHeight
|
|
6579
|
+
} = state;
|
|
6580
|
+
const unfilteredItems = await getCompletions(editor);
|
|
6581
|
+
const wordAtOffset = getWordAtOffset(editor);
|
|
6582
|
+
const items = filterCompletionItems(unfilteredItems, wordAtOffset);
|
|
6583
|
+
const rowIndex = editor.selections[0];
|
|
6584
|
+
const columnIndex = editor.selections[1];
|
|
6585
|
+
const x$1 = x(editor, rowIndex, columnIndex);
|
|
6586
|
+
// @ts-ignore
|
|
6587
|
+
const y$1 = y(editor, rowIndex);
|
|
6588
|
+
const newMaxLineY = Math.min(items.length, 8);
|
|
6589
|
+
editor.widgets = editor.widgets || [];
|
|
6590
|
+
// editor.widgets.push(ViewletModuleId.EditorCompletion)
|
|
6591
|
+
const itemsLength = items.length;
|
|
6592
|
+
const newFocusedIndex = itemsLength === 0 ? -1 : 0;
|
|
6593
|
+
const total = items.length;
|
|
6594
|
+
const height = getListHeight(items.length, itemHeight, maxHeight);
|
|
6595
|
+
const finalDeltaY = getFinalDeltaY(height, itemHeight, total);
|
|
6596
|
+
return {
|
|
6597
|
+
...state,
|
|
6598
|
+
unfilteredItems,
|
|
6599
|
+
items,
|
|
6600
|
+
x: x$1,
|
|
6601
|
+
y: y$1,
|
|
6602
|
+
maxLineY: newMaxLineY,
|
|
6603
|
+
focusedIndex: newFocusedIndex,
|
|
6604
|
+
finalDeltaY,
|
|
6605
|
+
leadingWord: wordAtOffset,
|
|
6606
|
+
height,
|
|
6607
|
+
rowIndex,
|
|
6608
|
+
columnIndex,
|
|
6609
|
+
editorUid
|
|
6610
|
+
};
|
|
6611
|
+
};
|
|
6612
|
+
const advance = (state, word) => {
|
|
6613
|
+
const filteredItems = filterCompletionItems(state.items, word);
|
|
6614
|
+
return {
|
|
6615
|
+
...state,
|
|
6616
|
+
filteredItems
|
|
6617
|
+
};
|
|
6618
|
+
};
|
|
6619
|
+
|
|
6620
|
+
const getEdits = async (state, editor, completionItem) => {
|
|
6621
|
+
// @ts-ignore
|
|
6622
|
+
const {
|
|
6623
|
+
leadingWord,
|
|
6624
|
+
uid
|
|
6625
|
+
} = state;
|
|
6626
|
+
const word = completionItem.label;
|
|
6627
|
+
const resolvedItem = await resolveCompletion(editor, word, completionItem);
|
|
6628
|
+
const inserted = resolvedItem ? resolvedItem.snippet : word;
|
|
6629
|
+
// TODO type and dispose commands should be sent to renderer process at the same time
|
|
6630
|
+
const {
|
|
6631
|
+
selections
|
|
6632
|
+
} = editor;
|
|
6633
|
+
const [startRowIndex, startColumnIndex] = selections;
|
|
6634
|
+
const leadingWordLength = leadingWord.length;
|
|
6635
|
+
const replaceRange$1 = new Uint32Array([startRowIndex, startColumnIndex - leadingWordLength, startRowIndex, startColumnIndex]);
|
|
6636
|
+
const changes = replaceRange(editor, replaceRange$1, [inserted], '');
|
|
6637
|
+
return changes;
|
|
6638
|
+
};
|
|
6639
|
+
const select = async (state, editor, completionItem) => {
|
|
6640
|
+
const changes = await getEdits(state, editor, completionItem);
|
|
6641
|
+
const index = editor.widgets.indexOf
|
|
6642
|
+
// ViewletModuleId.EditorCompletion
|
|
6643
|
+
();
|
|
6644
|
+
if (index !== -1) {
|
|
6645
|
+
editor.widgets.splice(index, 1);
|
|
6646
|
+
editor.completionState = None;
|
|
6647
|
+
editor.completionUid = 0;
|
|
6648
|
+
}
|
|
6649
|
+
await execute$1('Editor.applyEdit', changes);
|
|
6650
|
+
// await Viewlet.dispose(uid)
|
|
6651
|
+
return state;
|
|
6652
|
+
};
|
|
6653
|
+
const selectIndex = (editorUid, state, index) => {
|
|
6654
|
+
const editor = getEditor(editorUid);
|
|
6655
|
+
const {
|
|
6656
|
+
items
|
|
6657
|
+
} = state;
|
|
6658
|
+
if (index === -1) {
|
|
6659
|
+
return state;
|
|
6660
|
+
}
|
|
6661
|
+
if (index > items.length) {
|
|
6662
|
+
throw new Error('index too large');
|
|
6663
|
+
}
|
|
6664
|
+
const actualIndex = index;
|
|
6665
|
+
const completionItem = items[actualIndex];
|
|
6666
|
+
return select(state, editor, completionItem);
|
|
6667
|
+
};
|
|
6668
|
+
|
|
6669
|
+
const selectCurrent = (editorUid, state) => {
|
|
6670
|
+
const {
|
|
6671
|
+
focusedIndex
|
|
6672
|
+
} = state;
|
|
6673
|
+
return selectIndex(editorUid, state, focusedIndex);
|
|
6674
|
+
};
|
|
6675
|
+
|
|
6183
6676
|
// copied from https://github.com/microsoft/vscode/tree/main/src/vs/base/common/strings.ts by Microsoft (License MIT)
|
|
6184
6677
|
|
|
6185
6678
|
const RE_ESCAPE = /[\\\{\}\*\+\?\|\^\$\.\[\]\(\)]/g;
|
|
@@ -6224,8 +6717,8 @@ const getMatchCount = matches => {
|
|
|
6224
6717
|
return matches.length / 2;
|
|
6225
6718
|
};
|
|
6226
6719
|
|
|
6227
|
-
const loadContent =
|
|
6228
|
-
const editor = getEditor(
|
|
6720
|
+
const loadContent = editorId => {
|
|
6721
|
+
const editor = getEditor(editorId);
|
|
6229
6722
|
const {
|
|
6230
6723
|
selections,
|
|
6231
6724
|
lines
|
|
@@ -6278,10 +6771,15 @@ const focusIndex = async (state, index) => {
|
|
|
6278
6771
|
if (index === matchIndex) {
|
|
6279
6772
|
return state;
|
|
6280
6773
|
}
|
|
6774
|
+
// TODO find next match and highlight it
|
|
6775
|
+
const matchRowIndex = matches[index * 2];
|
|
6776
|
+
const matchColumnIndex = matches[index * 2 + 1];
|
|
6777
|
+
// @ts-ignore
|
|
6778
|
+
const newSelections = new Uint32Array([matchRowIndex, matchColumnIndex, matchRowIndex, matchColumnIndex + value.length]);
|
|
6281
6779
|
// TODO set selections synchronously and render input match index,
|
|
6282
6780
|
// input value and new selections at the same time
|
|
6283
6781
|
// TODO
|
|
6284
|
-
|
|
6782
|
+
await invoke$3('Editor.setSelections', newSelections);
|
|
6285
6783
|
return {
|
|
6286
6784
|
...state,
|
|
6287
6785
|
matchIndex: index
|
|
@@ -6376,27 +6874,6 @@ const ensure = async (fontName, fontUrl) => {
|
|
|
6376
6874
|
setLoaded(fontName);
|
|
6377
6875
|
};
|
|
6378
6876
|
|
|
6379
|
-
const OnHover = 'onHover';
|
|
6380
|
-
|
|
6381
|
-
// TODO add tests for this
|
|
6382
|
-
const activateByEvent = async event => {
|
|
6383
|
-
await invoke$3('ExtensionHostManagement.activateByEvent', event);
|
|
6384
|
-
};
|
|
6385
|
-
|
|
6386
|
-
const execute = async ({
|
|
6387
|
-
editor,
|
|
6388
|
-
args,
|
|
6389
|
-
event,
|
|
6390
|
-
method,
|
|
6391
|
-
noProviderFoundMessage,
|
|
6392
|
-
noProviderFoundResult = undefined
|
|
6393
|
-
}) => {
|
|
6394
|
-
const fullEvent = `${event}:${editor.languageId}`;
|
|
6395
|
-
await activateByEvent(fullEvent);
|
|
6396
|
-
const result = await invoke$2(method, editor.uid, ...args);
|
|
6397
|
-
return result;
|
|
6398
|
-
};
|
|
6399
|
-
|
|
6400
6877
|
const executeHoverProvider = (editor, offset) => {
|
|
6401
6878
|
object(editor);
|
|
6402
6879
|
number$1(offset);
|
|
@@ -7459,7 +7936,7 @@ const renderEditor = async id => {
|
|
|
7459
7936
|
return commands;
|
|
7460
7937
|
};
|
|
7461
7938
|
|
|
7462
|
-
const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPointerMove', 'ColorPicker.loadContent', 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'FindWidget.focusFirst', 'FindWidget.focusIndex', 'FindWidget.focusLast', 'FindWidget.focusNext', 'FindWidget.focusPrevious', 'FindWidget.handleInput', 'FindWidget.loadContent', 'Font.ensure', 'Hover.getHoverInfo', 'Initialize.initialize'];
|
|
7939
|
+
const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPointerMove', 'ColorPicker.loadContent', 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'FindWidget.focusFirst', 'FindWidget.focusIndex', 'FindWidget.focusLast', 'FindWidget.focusNext', 'FindWidget.focusPrevious', 'FindWidget.handleInput', 'FindWidget.loadContent', 'Font.ensure', 'Hover.getHoverInfo', 'Initialize.initialize', 'EditorCompletion.advance', 'EditorCompletion.handleEditorBlur', 'EditorCompletion.handleEditorClick', 'EditorCompletion.handleEditorDeleteLeft', 'EditorCompletion.handleEditorType', 'EditorCompletion.loadContent', 'EditorCompletion.selectCurrent', 'EditorCompletion.selectIndex'];
|
|
7463
7940
|
|
|
7464
7941
|
// TODO wrap commands globally, not per editor
|
|
7465
7942
|
// TODO only store editor state in editor worker, not in renderer worker also
|
|
@@ -7484,7 +7961,7 @@ const wrapCommands = commands => {
|
|
|
7484
7961
|
const commandMap = {
|
|
7485
7962
|
'ColorPicker.handleSliderPointerDown': handleSliderPointerDown,
|
|
7486
7963
|
'ColorPicker.handleSliderPointerMove': handleSliderPointerMove,
|
|
7487
|
-
'ColorPicker.loadContent': loadContent$
|
|
7964
|
+
'ColorPicker.loadContent': loadContent$2,
|
|
7488
7965
|
'Editor.addCursorAbove': addCursorAbove,
|
|
7489
7966
|
'Editor.addCursorBelow': addCursorBelow,
|
|
7490
7967
|
'Editor.applyEdit': applyEdit,
|
|
@@ -7603,6 +8080,14 @@ const commandMap = {
|
|
|
7603
8080
|
'Editor.typeWithAutoClosing': typeWithAutoClosing,
|
|
7604
8081
|
'Editor.undo': undo,
|
|
7605
8082
|
'Editor.unIndent': editorUnindent,
|
|
8083
|
+
'EditorCompletion.advance': advance,
|
|
8084
|
+
'EditorCompletion.handleEditorBlur': handleEditorBlur,
|
|
8085
|
+
'EditorCompletion.handleEditorClick': handleEditorClick,
|
|
8086
|
+
'EditorCompletion.handleEditorDeleteLeft': handleEditorDeleteLeft,
|
|
8087
|
+
'EditorCompletion.handleEditorType': handleEditorType,
|
|
8088
|
+
'EditorCompletion.loadContent': loadContent$1,
|
|
8089
|
+
'EditorCompletion.selectCurrent': selectCurrent,
|
|
8090
|
+
'EditorCompletion.selectIndex': selectIndex,
|
|
7606
8091
|
'FindWidget.focusFirst': focusFirst,
|
|
7607
8092
|
'FindWidget.focusIndex': focusIndex,
|
|
7608
8093
|
'FindWidget.focusLast': focusLast,
|