@lvce-editor/file-search-worker 6.6.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.
@@ -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$4 = (id, fn) => {
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$1 = () => {
546
+ const create$3$2 = () => {
453
547
  return ++id;
454
548
  };
455
549
  const registerPromise = () => {
456
- const id = create$3$1();
550
+ const id = create$3$2();
457
551
  const {
458
552
  resolve,
459
553
  promise
460
554
  } = Promise.withResolvers();
461
- set$4(id, resolve);
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$5 = (message, result) => {
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$5(message, resultProperty);
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$3 = (ipc, method, ...params) => {
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) => {
@@ -842,7 +936,7 @@ const createRpc = ipc => {
842
936
  send(ipc, method, ...params);
843
937
  },
844
938
  invoke(method, ...params) {
845
- return invoke$3(ipc, method, ...params);
939
+ return invoke$4(ipc, method, ...params);
846
940
  },
847
941
  invokeAndTransfer(method, ...params) {
848
942
  return invokeAndTransfer$1(ipc, method, ...params);
@@ -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$3 = (id, rpc) => {
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$3(rpcId, rpc);
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 getPicks$8 = async () => {
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,
@@ -2789,10 +2961,40 @@ const setCursor = async (rowIndex, columnIndex) => {
2789
2961
  await invoke$2('Editor.cursorSet', rowIndex, columnIndex);
2790
2962
  };
2791
2963
 
2792
- const selectPick$5 = async item => {
2793
- const rowIndex = Number.parseInt(item.label);
2794
- const columnIndex = 5;
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
2978
+ };
2979
+ };
2980
+ const goToPositionAndFocus = async (rowIndex, columnIndex) => {
2795
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);
2796
2998
  return {
2797
2999
  command: Hide
2798
3000
  };
@@ -2898,7 +3100,7 @@ const setValue = async (state, newValue) => {
2898
3100
  const prefix = getQuickPickPrefix(newValue);
2899
3101
  const subId = getQuickPickSubProviderId(providerId, prefix);
2900
3102
  const newPicks = await getPicks(subId, newValue, args);
2901
- const filterValue = getFilterValue(providerId, newValue);
3103
+ const filterValue = getFilterValue(providerId, subId, newValue);
2902
3104
  const items = filterQuickPickItems(newPicks, filterValue);
2903
3105
  const focusedIndex = items.length === 0 ? -1 : 0;
2904
3106
  const sliced = items.slice(minLineY, maxLineY);
@@ -2989,7 +3191,7 @@ const selectIndex = async (state, index, button = /* left */0) => {
2989
3191
  const prefix = getQuickPickPrefix(value);
2990
3192
  const subId = getQuickPickSubProviderId(providerId, prefix);
2991
3193
  const fn = getSelect(subId);
2992
- const selectPickResult = await fn(pick);
3194
+ const selectPickResult = await fn(pick, value);
2993
3195
  object(selectPickResult);
2994
3196
  string(selectPickResult.command);
2995
3197
  const {
@@ -3033,6 +3235,17 @@ const handleFocus = async state => {
3033
3235
  return state;
3034
3236
  };
3035
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
+
3036
3249
  const getDefaultValue = id => {
3037
3250
  switch (id) {
3038
3251
  case EveryThing$1:
@@ -3088,7 +3301,7 @@ const loadContent = async state => {
3088
3301
  const subId = getQuickPickSubProviderId(id, prefix);
3089
3302
  const newPicks = await getPicks(subId, value, args);
3090
3303
  array(newPicks);
3091
- const filterValue = getFilterValue(id, value);
3304
+ const filterValue = getFilterValue(id, subId, value);
3092
3305
  const items = filterQuickPickItems(newPicks, filterValue);
3093
3306
  const minLineY = 0;
3094
3307
  const maxLineY = Math.min(minLineY + state.maxVisibleItems, newPicks.length);
@@ -3613,6 +3826,7 @@ const commandMap = {
3613
3826
  'QuickPick.handleFocus': wrapCommand(handleFocus),
3614
3827
  'QuickPick.handleInput': wrapCommand(handleInput),
3615
3828
  'QuickPick.handleWheel': wrapCommand(handleWheel),
3829
+ 'QuickPick.initialize': initialize,
3616
3830
  'QuickPick.loadContent': wrapCommand(loadContent),
3617
3831
  'QuickPick.render2': render2,
3618
3832
  'QuickPick.renderEventListeners': renderEventListeners,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "6.6.0",
3
+ "version": "6.7.0",
4
4
  "keywords": [
5
5
  "text-search"
6
6
  ],