@lvce-editor/file-search-worker 6.5.0 → 6.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/fileSearchWorkerMain.js +236 -26
- package/package.json +1 -1
|
@@ -429,6 +429,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
429
429
|
listen: listen$6,
|
|
430
430
|
wrap: wrap$e
|
|
431
431
|
};
|
|
432
|
+
const addListener = (emitter, type, callback) => {
|
|
433
|
+
if ('addEventListener' in emitter) {
|
|
434
|
+
emitter.addEventListener(type, callback);
|
|
435
|
+
} else {
|
|
436
|
+
emitter.on(type, callback);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
const removeListener = (emitter, type, callback) => {
|
|
440
|
+
if ('removeEventListener' in emitter) {
|
|
441
|
+
emitter.removeEventListener(type, callback);
|
|
442
|
+
} else {
|
|
443
|
+
emitter.off(type, callback);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
447
|
+
const {
|
|
448
|
+
resolve,
|
|
449
|
+
promise
|
|
450
|
+
} = Promise.withResolvers();
|
|
451
|
+
const listenerMap = Object.create(null);
|
|
452
|
+
const cleanup = value => {
|
|
453
|
+
for (const event of Object.keys(eventMap)) {
|
|
454
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
455
|
+
}
|
|
456
|
+
resolve(value);
|
|
457
|
+
};
|
|
458
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
459
|
+
const listener = event => {
|
|
460
|
+
cleanup({
|
|
461
|
+
type,
|
|
462
|
+
event
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
addListener(eventEmitter, event, listener);
|
|
466
|
+
listenerMap[event] = listener;
|
|
467
|
+
}
|
|
468
|
+
return promise;
|
|
469
|
+
};
|
|
470
|
+
const Message$1 = 3;
|
|
471
|
+
const create$5$1 = async ({
|
|
472
|
+
messagePort,
|
|
473
|
+
isMessagePortOpen
|
|
474
|
+
}) => {
|
|
475
|
+
if (!isMessagePort(messagePort)) {
|
|
476
|
+
throw new IpcError('port must be of type MessagePort');
|
|
477
|
+
}
|
|
478
|
+
if (isMessagePortOpen) {
|
|
479
|
+
return messagePort;
|
|
480
|
+
}
|
|
481
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
482
|
+
message: Message$1
|
|
483
|
+
});
|
|
484
|
+
messagePort.start();
|
|
485
|
+
const {
|
|
486
|
+
type,
|
|
487
|
+
event
|
|
488
|
+
} = await eventPromise;
|
|
489
|
+
if (type !== Message$1) {
|
|
490
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
491
|
+
}
|
|
492
|
+
if (event.data !== readyMessage) {
|
|
493
|
+
throw new IpcError('unexpected first message');
|
|
494
|
+
}
|
|
495
|
+
return messagePort;
|
|
496
|
+
};
|
|
497
|
+
const signal$1 = messagePort => {
|
|
498
|
+
messagePort.start();
|
|
499
|
+
};
|
|
500
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
501
|
+
getData = getData$2;
|
|
502
|
+
send(message) {
|
|
503
|
+
this._rawIpc.postMessage(message);
|
|
504
|
+
}
|
|
505
|
+
sendAndTransfer(message) {
|
|
506
|
+
const transfer = getTransferrables(message);
|
|
507
|
+
this._rawIpc.postMessage(message, transfer);
|
|
508
|
+
}
|
|
509
|
+
dispose() {
|
|
510
|
+
this._rawIpc.close();
|
|
511
|
+
}
|
|
512
|
+
onMessage(callback) {
|
|
513
|
+
this._rawIpc.addEventListener('message', callback);
|
|
514
|
+
}
|
|
515
|
+
onClose(callback) {}
|
|
516
|
+
}
|
|
517
|
+
const wrap$5 = messagePort => {
|
|
518
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
519
|
+
};
|
|
520
|
+
const IpcParentWithMessagePort$1 = {
|
|
521
|
+
__proto__: null,
|
|
522
|
+
create: create$5$1,
|
|
523
|
+
signal: signal$1,
|
|
524
|
+
wrap: wrap$5
|
|
525
|
+
};
|
|
432
526
|
|
|
433
527
|
const Two = '2.0';
|
|
434
528
|
const create$4$1 = (method, params) => {
|
|
@@ -439,7 +533,7 @@ const create$4$1 = (method, params) => {
|
|
|
439
533
|
};
|
|
440
534
|
};
|
|
441
535
|
const callbacks = Object.create(null);
|
|
442
|
-
const set$
|
|
536
|
+
const set$5 = (id, fn) => {
|
|
443
537
|
callbacks[id] = fn;
|
|
444
538
|
};
|
|
445
539
|
const get$2 = id => {
|
|
@@ -449,16 +543,16 @@ const remove = id => {
|
|
|
449
543
|
delete callbacks[id];
|
|
450
544
|
};
|
|
451
545
|
let id = 0;
|
|
452
|
-
const create$3$
|
|
546
|
+
const create$3$2 = () => {
|
|
453
547
|
return ++id;
|
|
454
548
|
};
|
|
455
549
|
const registerPromise = () => {
|
|
456
|
-
const id = create$3$
|
|
550
|
+
const id = create$3$2();
|
|
457
551
|
const {
|
|
458
552
|
resolve,
|
|
459
553
|
promise
|
|
460
554
|
} = Promise.withResolvers();
|
|
461
|
-
set$
|
|
555
|
+
set$5(id, resolve);
|
|
462
556
|
return {
|
|
463
557
|
id,
|
|
464
558
|
promise
|
|
@@ -686,7 +780,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
686
780
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
687
781
|
return create$1$1(id, errorProperty);
|
|
688
782
|
};
|
|
689
|
-
const create$
|
|
783
|
+
const create$6 = (message, result) => {
|
|
690
784
|
return {
|
|
691
785
|
jsonrpc: Two,
|
|
692
786
|
id: message.id,
|
|
@@ -695,7 +789,7 @@ const create$5 = (message, result) => {
|
|
|
695
789
|
};
|
|
696
790
|
const getSuccessResponse = (message, result) => {
|
|
697
791
|
const resultProperty = result ?? null;
|
|
698
|
-
return create$
|
|
792
|
+
return create$6(message, resultProperty);
|
|
699
793
|
};
|
|
700
794
|
const getErrorResponseSimple = (id, error) => {
|
|
701
795
|
return {
|
|
@@ -803,7 +897,7 @@ const send = (transport, method, ...params) => {
|
|
|
803
897
|
const message = create$4$1(method, params);
|
|
804
898
|
transport.send(message);
|
|
805
899
|
};
|
|
806
|
-
const invoke$
|
|
900
|
+
const invoke$4 = (ipc, method, ...params) => {
|
|
807
901
|
return invokeHelper(ipc, method, params, false);
|
|
808
902
|
};
|
|
809
903
|
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
@@ -823,7 +917,7 @@ const register$1 = commandMap => {
|
|
|
823
917
|
const getCommand = key => {
|
|
824
918
|
return commands[key];
|
|
825
919
|
};
|
|
826
|
-
const execute
|
|
920
|
+
const execute = (command, ...args) => {
|
|
827
921
|
const fn = getCommand(command);
|
|
828
922
|
if (!fn) {
|
|
829
923
|
throw new CommandNotFoundError(command);
|
|
@@ -842,7 +936,7 @@ const createRpc = ipc => {
|
|
|
842
936
|
send(ipc, method, ...params);
|
|
843
937
|
},
|
|
844
938
|
invoke(method, ...params) {
|
|
845
|
-
return invoke$
|
|
939
|
+
return invoke$4(ipc, method, ...params);
|
|
846
940
|
},
|
|
847
941
|
invokeAndTransfer(method, ...params) {
|
|
848
942
|
return invokeAndTransfer$1(ipc, method, ...params);
|
|
@@ -864,7 +958,7 @@ const logError = () => {
|
|
|
864
958
|
};
|
|
865
959
|
const handleMessage = event => {
|
|
866
960
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
867
|
-
const actualExecute = event?.target?.execute || execute
|
|
961
|
+
const actualExecute = event?.target?.execute || execute;
|
|
868
962
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
869
963
|
};
|
|
870
964
|
const handleIpc = ipc => {
|
|
@@ -883,6 +977,40 @@ const listen$1 = async (module, options) => {
|
|
|
883
977
|
const ipc = module.wrap(rawIpc);
|
|
884
978
|
return ipc;
|
|
885
979
|
};
|
|
980
|
+
const create$5 = async ({
|
|
981
|
+
commandMap,
|
|
982
|
+
messagePort
|
|
983
|
+
}) => {
|
|
984
|
+
// TODO create a commandMap per rpc instance
|
|
985
|
+
register$1(commandMap);
|
|
986
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
987
|
+
messagePort,
|
|
988
|
+
isMessagePortOpen: true
|
|
989
|
+
});
|
|
990
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
991
|
+
handleIpc(ipc);
|
|
992
|
+
const rpc = createRpc(ipc);
|
|
993
|
+
messagePort.start();
|
|
994
|
+
return rpc;
|
|
995
|
+
};
|
|
996
|
+
const create$3$1 = async ({
|
|
997
|
+
commandMap,
|
|
998
|
+
send
|
|
999
|
+
}) => {
|
|
1000
|
+
const {
|
|
1001
|
+
port1,
|
|
1002
|
+
port2
|
|
1003
|
+
} = new MessageChannel();
|
|
1004
|
+
await send(port1);
|
|
1005
|
+
return create$5({
|
|
1006
|
+
commandMap,
|
|
1007
|
+
messagePort: port2
|
|
1008
|
+
});
|
|
1009
|
+
};
|
|
1010
|
+
const TransferMessagePortRpcParent = {
|
|
1011
|
+
__proto__: null,
|
|
1012
|
+
create: create$3$1
|
|
1013
|
+
};
|
|
886
1014
|
const create$4 = async ({
|
|
887
1015
|
commandMap
|
|
888
1016
|
}) => {
|
|
@@ -926,10 +1054,11 @@ const Img = 17;
|
|
|
926
1054
|
const Script$1 = 2;
|
|
927
1055
|
|
|
928
1056
|
const DebugWorker = 55;
|
|
1057
|
+
const EditorWorker = 99;
|
|
929
1058
|
const RendererWorker$1 = 1;
|
|
930
1059
|
|
|
931
1060
|
const rpcs = Object.create(null);
|
|
932
|
-
const set$
|
|
1061
|
+
const set$4 = (id, rpc) => {
|
|
933
1062
|
rpcs[id] = rpc;
|
|
934
1063
|
};
|
|
935
1064
|
const get$1 = id => {
|
|
@@ -951,7 +1080,7 @@ const create$3 = rpcId => {
|
|
|
951
1080
|
return rpc.invokeAndTransfer(method, ...params);
|
|
952
1081
|
},
|
|
953
1082
|
set(rpc) {
|
|
954
|
-
set$
|
|
1083
|
+
set$4(rpcId, rpc);
|
|
955
1084
|
},
|
|
956
1085
|
async dispose() {
|
|
957
1086
|
const rpc = get$1(rpcId);
|
|
@@ -960,6 +1089,14 @@ const create$3 = rpcId => {
|
|
|
960
1089
|
};
|
|
961
1090
|
};
|
|
962
1091
|
|
|
1092
|
+
const {
|
|
1093
|
+
invoke: invoke$3,
|
|
1094
|
+
set: set$3} = create$3(EditorWorker);
|
|
1095
|
+
const getLines = async editorUid => {
|
|
1096
|
+
const lines = await invoke$3('Editor.getLines2', editorUid);
|
|
1097
|
+
return lines;
|
|
1098
|
+
};
|
|
1099
|
+
|
|
963
1100
|
const {
|
|
964
1101
|
invoke: invoke$2,
|
|
965
1102
|
invokeAndTransfer,
|
|
@@ -2251,15 +2388,26 @@ const getFilterValueEverything = value => {
|
|
|
2251
2388
|
const prefixLength = prefix.length;
|
|
2252
2389
|
return value.slice(prefixLength).trim();
|
|
2253
2390
|
};
|
|
2391
|
+
const getValueGoToLine = value => {
|
|
2392
|
+
if (value.startsWith('::')) {
|
|
2393
|
+
return value.slice(2);
|
|
2394
|
+
}
|
|
2395
|
+
return value.slice(1);
|
|
2396
|
+
};
|
|
2254
2397
|
const getFn$1 = id => {
|
|
2255
2398
|
switch (id) {
|
|
2256
2399
|
case EveryThing$1:
|
|
2257
2400
|
return getFilterValueEverything;
|
|
2401
|
+
case GoToLine$2:
|
|
2402
|
+
return getValueGoToLine;
|
|
2258
2403
|
default:
|
|
2259
2404
|
return noop;
|
|
2260
2405
|
}
|
|
2261
2406
|
};
|
|
2262
|
-
const getFilterValue = (id, value) => {
|
|
2407
|
+
const getFilterValue = (id, subId, value) => {
|
|
2408
|
+
if (subId === GoToLine$2) {
|
|
2409
|
+
return getValueGoToLine(value);
|
|
2410
|
+
}
|
|
2263
2411
|
const fn = getFn$1(id);
|
|
2264
2412
|
const filterValue = fn(value);
|
|
2265
2413
|
return filterValue;
|
|
@@ -2500,7 +2648,31 @@ const getPicks$9 = async searchValue => {
|
|
|
2500
2648
|
return picks;
|
|
2501
2649
|
};
|
|
2502
2650
|
|
|
2503
|
-
const
|
|
2651
|
+
const getText = async () => {
|
|
2652
|
+
// TODO
|
|
2653
|
+
const id = await getActiveEditorId();
|
|
2654
|
+
const lines = await getLines(id);
|
|
2655
|
+
return lines.join('\n');
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2658
|
+
const toPick = column => {
|
|
2659
|
+
return {
|
|
2660
|
+
description: '',
|
|
2661
|
+
direntType: None$2,
|
|
2662
|
+
fileIcon: '',
|
|
2663
|
+
icon: '',
|
|
2664
|
+
label: `${column}`,
|
|
2665
|
+
matches: [],
|
|
2666
|
+
uri: ''
|
|
2667
|
+
};
|
|
2668
|
+
};
|
|
2669
|
+
const getPicks$8 = async value => {
|
|
2670
|
+
if (value.startsWith('::')) {
|
|
2671
|
+
const text = await getText();
|
|
2672
|
+
const columns = [...Array(text.length).fill(0)].map((item, index) => index);
|
|
2673
|
+
const picks = columns.map(toPick);
|
|
2674
|
+
return picks;
|
|
2675
|
+
}
|
|
2504
2676
|
const picks = [{
|
|
2505
2677
|
description: '',
|
|
2506
2678
|
direntType: None$2,
|
|
@@ -2785,18 +2957,44 @@ const selectPick$6 = async pick => {
|
|
|
2785
2957
|
};
|
|
2786
2958
|
};
|
|
2787
2959
|
|
|
2788
|
-
const
|
|
2789
|
-
|
|
2960
|
+
const setCursor = async (rowIndex, columnIndex) => {
|
|
2961
|
+
await invoke$2('Editor.cursorSet', rowIndex, columnIndex);
|
|
2790
2962
|
};
|
|
2791
2963
|
|
|
2792
|
-
const
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2964
|
+
const getPosition = (text, wantedColumn) => {
|
|
2965
|
+
let row = 0;
|
|
2966
|
+
let column = 0;
|
|
2967
|
+
for (let i = 0; i < wantedColumn; i++) {
|
|
2968
|
+
if (text[i] === '\n') {
|
|
2969
|
+
row++;
|
|
2970
|
+
column = 0;
|
|
2971
|
+
} else {
|
|
2972
|
+
column++;
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
return {
|
|
2976
|
+
column,
|
|
2977
|
+
row
|
|
2797
2978
|
};
|
|
2798
|
-
|
|
2799
|
-
|
|
2979
|
+
};
|
|
2980
|
+
const goToPositionAndFocus = async (rowIndex, columnIndex) => {
|
|
2981
|
+
await setCursor(rowIndex, columnIndex);
|
|
2982
|
+
await invoke$2('Editor.handleFocus');
|
|
2983
|
+
};
|
|
2984
|
+
const selectPick$5 = async (item, value) => {
|
|
2985
|
+
if (value.startsWith('::')) {
|
|
2986
|
+
const columnString = value.slice(2);
|
|
2987
|
+
const wantedColumn = Number.parseInt(columnString, 10);
|
|
2988
|
+
const text = await getText();
|
|
2989
|
+
const position = getPosition(text, wantedColumn);
|
|
2990
|
+
await goToPositionAndFocus(position.row, position.column);
|
|
2991
|
+
return {
|
|
2992
|
+
command: Hide
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
const rowIndex = Number.parseInt(item.label);
|
|
2996
|
+
const columnIndex = 0;
|
|
2997
|
+
await goToPositionAndFocus(rowIndex, columnIndex);
|
|
2800
2998
|
return {
|
|
2801
2999
|
command: Hide
|
|
2802
3000
|
};
|
|
@@ -2902,7 +3100,7 @@ const setValue = async (state, newValue) => {
|
|
|
2902
3100
|
const prefix = getQuickPickPrefix(newValue);
|
|
2903
3101
|
const subId = getQuickPickSubProviderId(providerId, prefix);
|
|
2904
3102
|
const newPicks = await getPicks(subId, newValue, args);
|
|
2905
|
-
const filterValue = getFilterValue(providerId, newValue);
|
|
3103
|
+
const filterValue = getFilterValue(providerId, subId, newValue);
|
|
2906
3104
|
const items = filterQuickPickItems(newPicks, filterValue);
|
|
2907
3105
|
const focusedIndex = items.length === 0 ? -1 : 0;
|
|
2908
3106
|
const sliced = items.slice(minLineY, maxLineY);
|
|
@@ -2993,7 +3191,7 @@ const selectIndex = async (state, index, button = /* left */0) => {
|
|
|
2993
3191
|
const prefix = getQuickPickPrefix(value);
|
|
2994
3192
|
const subId = getQuickPickSubProviderId(providerId, prefix);
|
|
2995
3193
|
const fn = getSelect(subId);
|
|
2996
|
-
const selectPickResult = await fn(pick);
|
|
3194
|
+
const selectPickResult = await fn(pick, value);
|
|
2997
3195
|
object(selectPickResult);
|
|
2998
3196
|
string(selectPickResult.command);
|
|
2999
3197
|
const {
|
|
@@ -3037,6 +3235,17 @@ const handleFocus = async state => {
|
|
|
3037
3235
|
return state;
|
|
3038
3236
|
};
|
|
3039
3237
|
|
|
3238
|
+
const initialize = async () => {
|
|
3239
|
+
// TODO
|
|
3240
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
3241
|
+
commandMap: {},
|
|
3242
|
+
async send(port) {
|
|
3243
|
+
await sendMessagePortToEditorWorker(port, 0);
|
|
3244
|
+
}
|
|
3245
|
+
});
|
|
3246
|
+
set$3(rpc);
|
|
3247
|
+
};
|
|
3248
|
+
|
|
3040
3249
|
const getDefaultValue = id => {
|
|
3041
3250
|
switch (id) {
|
|
3042
3251
|
case EveryThing$1:
|
|
@@ -3092,7 +3301,7 @@ const loadContent = async state => {
|
|
|
3092
3301
|
const subId = getQuickPickSubProviderId(id, prefix);
|
|
3093
3302
|
const newPicks = await getPicks(subId, value, args);
|
|
3094
3303
|
array(newPicks);
|
|
3095
|
-
const filterValue = getFilterValue(id, value);
|
|
3304
|
+
const filterValue = getFilterValue(id, subId, value);
|
|
3096
3305
|
const items = filterQuickPickItems(newPicks, filterValue);
|
|
3097
3306
|
const minLineY = 0;
|
|
3098
3307
|
const maxLineY = Math.min(minLineY + state.maxVisibleItems, newPicks.length);
|
|
@@ -3617,6 +3826,7 @@ const commandMap = {
|
|
|
3617
3826
|
'QuickPick.handleFocus': wrapCommand(handleFocus),
|
|
3618
3827
|
'QuickPick.handleInput': wrapCommand(handleInput),
|
|
3619
3828
|
'QuickPick.handleWheel': wrapCommand(handleWheel),
|
|
3829
|
+
'QuickPick.initialize': initialize,
|
|
3620
3830
|
'QuickPick.loadContent': wrapCommand(loadContent),
|
|
3621
3831
|
'QuickPick.render2': render2,
|
|
3622
3832
|
'QuickPick.renderEventListeners': renderEventListeners,
|