@lvce-editor/text-search-worker 3.13.0 → 3.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/textSearchWorkerMain.js +226 -339
- package/package.json +1 -1
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
const Two = '2.0';
|
|
2
|
-
const create$4
|
|
2
|
+
const create$4 = (method, params) => {
|
|
3
3
|
return {
|
|
4
4
|
jsonrpc: Two,
|
|
5
5
|
method,
|
|
6
6
|
params
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
const state$
|
|
9
|
+
const state$3 = {
|
|
10
10
|
callbacks: Object.create(null)
|
|
11
11
|
};
|
|
12
12
|
const set$1 = (id, fn) => {
|
|
13
|
-
state$
|
|
13
|
+
state$3.callbacks[id] = fn;
|
|
14
14
|
};
|
|
15
15
|
const get$1 = id => {
|
|
16
|
-
return state$
|
|
16
|
+
return state$3.callbacks[id];
|
|
17
17
|
};
|
|
18
18
|
const remove$1 = id => {
|
|
19
|
-
delete state$
|
|
19
|
+
delete state$3.callbacks[id];
|
|
20
20
|
};
|
|
21
21
|
let id = 0;
|
|
22
22
|
const create$3$1 = () => {
|
|
@@ -237,7 +237,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
237
237
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
238
238
|
return create$1$2(message, errorProperty);
|
|
239
239
|
};
|
|
240
|
-
const create$
|
|
240
|
+
const create$5 = (message, result) => {
|
|
241
241
|
return {
|
|
242
242
|
jsonrpc: Two,
|
|
243
243
|
id: message.id,
|
|
@@ -246,7 +246,7 @@ const create$6 = (message, result) => {
|
|
|
246
246
|
};
|
|
247
247
|
const getSuccessResponse = (message, result) => {
|
|
248
248
|
const resultProperty = result ?? null;
|
|
249
|
-
return create$
|
|
249
|
+
return create$5(message, resultProperty);
|
|
250
250
|
};
|
|
251
251
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
252
252
|
try {
|
|
@@ -336,13 +336,13 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
336
336
|
return unwrapJsonRpcResult(responseMessage);
|
|
337
337
|
};
|
|
338
338
|
const send = (transport, method, ...params) => {
|
|
339
|
-
const message = create$4
|
|
339
|
+
const message = create$4(method, params);
|
|
340
340
|
transport.send(message);
|
|
341
341
|
};
|
|
342
342
|
const invoke$2 = (ipc, method, ...params) => {
|
|
343
343
|
return invokeHelper(ipc, method, params, false);
|
|
344
344
|
};
|
|
345
|
-
const invokeAndTransfer
|
|
345
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
346
346
|
return invokeHelper(ipc, method, params, true);
|
|
347
347
|
};
|
|
348
348
|
|
|
@@ -639,7 +639,7 @@ let VError$1 = class VError extends Error {
|
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
};
|
|
642
|
-
|
|
642
|
+
class IpcError extends VError$1 {
|
|
643
643
|
// @ts-ignore
|
|
644
644
|
constructor(betterMessage, stdout = '', stderr = '') {
|
|
645
645
|
if (stdout || stderr) {
|
|
@@ -664,7 +664,7 @@ let IpcError$1 = class IpcError extends VError$1 {
|
|
|
664
664
|
// @ts-ignore
|
|
665
665
|
this.stderr = stderr;
|
|
666
666
|
}
|
|
667
|
-
}
|
|
667
|
+
}
|
|
668
668
|
const withResolvers = () => {
|
|
669
669
|
let _resolve;
|
|
670
670
|
const promise = new Promise(resolve => {
|
|
@@ -693,7 +693,7 @@ const listen$1$1 = async () => {
|
|
|
693
693
|
const parentIpc = wrap$5(parentIpcRaw);
|
|
694
694
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
695
695
|
if (firstMessage.method !== 'initialize') {
|
|
696
|
-
throw new IpcError
|
|
696
|
+
throw new IpcError('unexpected first message');
|
|
697
697
|
}
|
|
698
698
|
const type = firstMessage.params[0];
|
|
699
699
|
if (type === 'message-port') {
|
|
@@ -743,6 +743,103 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
743
743
|
listen: listen$1$1,
|
|
744
744
|
wrap: wrap$4
|
|
745
745
|
};
|
|
746
|
+
const addListener = (emitter, type, callback) => {
|
|
747
|
+
if ('addEventListener' in emitter) {
|
|
748
|
+
emitter.addEventListener(type, callback);
|
|
749
|
+
} else {
|
|
750
|
+
emitter.on(type, callback);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
const removeListener = (emitter, type, callback) => {
|
|
754
|
+
if ('removeEventListener' in emitter) {
|
|
755
|
+
emitter.removeEventListener(type, callback);
|
|
756
|
+
} else {
|
|
757
|
+
emitter.off(type, callback);
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
761
|
+
const {
|
|
762
|
+
resolve,
|
|
763
|
+
promise
|
|
764
|
+
} = withResolvers();
|
|
765
|
+
const listenerMap = Object.create(null);
|
|
766
|
+
const cleanup = value => {
|
|
767
|
+
for (const event of Object.keys(eventMap)) {
|
|
768
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
769
|
+
}
|
|
770
|
+
resolve(value);
|
|
771
|
+
};
|
|
772
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
773
|
+
const listener = event => {
|
|
774
|
+
cleanup({
|
|
775
|
+
type,
|
|
776
|
+
event
|
|
777
|
+
});
|
|
778
|
+
};
|
|
779
|
+
addListener(eventEmitter, event, listener);
|
|
780
|
+
listenerMap[event] = listener;
|
|
781
|
+
}
|
|
782
|
+
return promise;
|
|
783
|
+
};
|
|
784
|
+
const Open = 1;
|
|
785
|
+
const Close = 2;
|
|
786
|
+
const stringifyCompact = value => {
|
|
787
|
+
return JSON.stringify(value);
|
|
788
|
+
};
|
|
789
|
+
const parse = content => {
|
|
790
|
+
if (content === 'undefined') {
|
|
791
|
+
return null;
|
|
792
|
+
}
|
|
793
|
+
try {
|
|
794
|
+
return JSON.parse(content);
|
|
795
|
+
} catch (error) {
|
|
796
|
+
throw new VError$1(error, 'failed to parse json');
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
const waitForWebSocketToBeOpen = webSocket => {
|
|
800
|
+
return getFirstEvent(webSocket, {
|
|
801
|
+
open: Open,
|
|
802
|
+
close: Close
|
|
803
|
+
});
|
|
804
|
+
};
|
|
805
|
+
const create$3 = async ({
|
|
806
|
+
webSocket
|
|
807
|
+
}) => {
|
|
808
|
+
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
809
|
+
// @ts-ignore
|
|
810
|
+
if (firstWebSocketEvent.type === Close) {
|
|
811
|
+
throw new IpcError('Websocket connection was immediately closed');
|
|
812
|
+
}
|
|
813
|
+
return webSocket;
|
|
814
|
+
};
|
|
815
|
+
class IpcParentWithWebSocket extends Ipc {
|
|
816
|
+
getData(event) {
|
|
817
|
+
return parse(event.data);
|
|
818
|
+
}
|
|
819
|
+
send(message) {
|
|
820
|
+
this._rawIpc.send(stringifyCompact(message));
|
|
821
|
+
}
|
|
822
|
+
sendAndTransfer(message) {
|
|
823
|
+
throw new Error('sendAndTransfer not supported');
|
|
824
|
+
}
|
|
825
|
+
dispose() {
|
|
826
|
+
this._rawIpc.close();
|
|
827
|
+
}
|
|
828
|
+
onClose(callback) {
|
|
829
|
+
this._rawIpc.addEventListener('close', callback);
|
|
830
|
+
}
|
|
831
|
+
onMessage(callback) {
|
|
832
|
+
this._rawIpc.addEventListener('message', callback);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const wrap$1 = webSocket => {
|
|
836
|
+
return new IpcParentWithWebSocket(webSocket);
|
|
837
|
+
};
|
|
838
|
+
const IpcParentWithWebSocket$1 = {
|
|
839
|
+
__proto__: null,
|
|
840
|
+
create: create$3,
|
|
841
|
+
wrap: wrap$1
|
|
842
|
+
};
|
|
746
843
|
|
|
747
844
|
const createRpc = ipc => {
|
|
748
845
|
const rpc = {
|
|
@@ -756,7 +853,7 @@ const createRpc = ipc => {
|
|
|
756
853
|
return invoke$2(ipc, method, ...params);
|
|
757
854
|
},
|
|
758
855
|
invokeAndTransfer(method, ...params) {
|
|
759
|
-
return invokeAndTransfer
|
|
856
|
+
return invokeAndTransfer(ipc, method, ...params);
|
|
760
857
|
}
|
|
761
858
|
};
|
|
762
859
|
return rpc;
|
|
@@ -776,6 +873,24 @@ const handleMessage = event => {
|
|
|
776
873
|
const handleIpc = ipc => {
|
|
777
874
|
ipc.addEventListener('message', handleMessage);
|
|
778
875
|
};
|
|
876
|
+
const create$1$1 = async ({
|
|
877
|
+
commandMap,
|
|
878
|
+
webSocket
|
|
879
|
+
}) => {
|
|
880
|
+
// TODO create a commandMap per rpc instance
|
|
881
|
+
register(commandMap);
|
|
882
|
+
const rawIpc = await IpcParentWithWebSocket$1.create({
|
|
883
|
+
webSocket
|
|
884
|
+
});
|
|
885
|
+
const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
|
|
886
|
+
handleIpc(ipc);
|
|
887
|
+
const rpc = createRpc(ipc);
|
|
888
|
+
return rpc;
|
|
889
|
+
};
|
|
890
|
+
const WebSocketRpcParent = {
|
|
891
|
+
__proto__: null,
|
|
892
|
+
create: create$1$1
|
|
893
|
+
};
|
|
779
894
|
|
|
780
895
|
// @ts-ignore
|
|
781
896
|
const listen$1 = async () => {
|
|
@@ -784,7 +899,7 @@ const listen$1 = async () => {
|
|
|
784
899
|
const ipc = module.wrap(rawIpc);
|
|
785
900
|
return ipc;
|
|
786
901
|
};
|
|
787
|
-
const create$
|
|
902
|
+
const create$2 = async ({
|
|
788
903
|
commandMap
|
|
789
904
|
}) => {
|
|
790
905
|
// TODO create a commandMap per rpc instance
|
|
@@ -796,7 +911,7 @@ const create$1$1 = async ({
|
|
|
796
911
|
};
|
|
797
912
|
const WebWorkerRpcClient = {
|
|
798
913
|
__proto__: null,
|
|
799
|
-
create: create$
|
|
914
|
+
create: create$2
|
|
800
915
|
};
|
|
801
916
|
|
|
802
917
|
const Empty$1 = 0;
|
|
@@ -832,21 +947,16 @@ const clearSearchResults$1 = state => {
|
|
|
832
947
|
};
|
|
833
948
|
};
|
|
834
949
|
|
|
835
|
-
const state$
|
|
950
|
+
const state$2 = {
|
|
836
951
|
rpc: undefined
|
|
837
952
|
};
|
|
838
953
|
const invoke$1 = (method, ...params) => {
|
|
839
|
-
const rpc = state$
|
|
954
|
+
const rpc = state$2.rpc;
|
|
840
955
|
// @ts-ignore
|
|
841
956
|
return rpc.invoke(method, ...params);
|
|
842
957
|
};
|
|
843
|
-
const invokeAndTransfer = (method, ...params) => {
|
|
844
|
-
const rpc = state$1.rpc;
|
|
845
|
-
// @ts-ignore
|
|
846
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
847
|
-
};
|
|
848
958
|
const setRpc = rpc => {
|
|
849
|
-
state$
|
|
959
|
+
state$2.rpc = rpc;
|
|
850
960
|
};
|
|
851
961
|
|
|
852
962
|
const copy = async state => {
|
|
@@ -875,7 +985,7 @@ const set = (uid, oldState, newState) => {
|
|
|
875
985
|
};
|
|
876
986
|
};
|
|
877
987
|
|
|
878
|
-
const create$
|
|
988
|
+
const create$1 = ({
|
|
879
989
|
itemHeight,
|
|
880
990
|
headerHeight = 0,
|
|
881
991
|
minimumSliderSize = 20
|
|
@@ -899,7 +1009,7 @@ const create$5 = ({
|
|
|
899
1009
|
};
|
|
900
1010
|
};
|
|
901
1011
|
|
|
902
|
-
const create
|
|
1012
|
+
const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, value = '', replacement = '', platform) => {
|
|
903
1013
|
const state = {
|
|
904
1014
|
uid,
|
|
905
1015
|
searchResults: [],
|
|
@@ -912,7 +1022,7 @@ const create$4 = (uid, x, y, width, height, workspacePath, assetDir, itemHeight,
|
|
|
912
1022
|
y,
|
|
913
1023
|
width,
|
|
914
1024
|
height,
|
|
915
|
-
...create$
|
|
1025
|
+
...create$1({
|
|
916
1026
|
itemHeight: itemHeight || 22,
|
|
917
1027
|
minimumSliderSize: minimumSliderSize,
|
|
918
1028
|
headerHeight: 61 // TODO
|
|
@@ -938,7 +1048,8 @@ const create$4 = (uid, x, y, width, height, workspacePath, assetDir, itemHeight,
|
|
|
938
1048
|
focusedIndex: -1,
|
|
939
1049
|
handleOffset: 0,
|
|
940
1050
|
focusSource: User,
|
|
941
|
-
flags: 0
|
|
1051
|
+
flags: 0,
|
|
1052
|
+
platform
|
|
942
1053
|
};
|
|
943
1054
|
set(uid, state, state);
|
|
944
1055
|
return state;
|
|
@@ -985,7 +1096,6 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
985
1096
|
return key;
|
|
986
1097
|
}
|
|
987
1098
|
const replacer = (match, rest) => {
|
|
988
|
-
// @ts-ignore
|
|
989
1099
|
return placeholders[rest];
|
|
990
1100
|
};
|
|
991
1101
|
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
@@ -1537,6 +1647,20 @@ const getActionsVirtualDom = actions => {
|
|
|
1537
1647
|
}, ...actions.flatMap(getActionVirtualDom)];
|
|
1538
1648
|
};
|
|
1539
1649
|
|
|
1650
|
+
const getFlags = uid => {
|
|
1651
|
+
const {
|
|
1652
|
+
newState
|
|
1653
|
+
} = get(uid);
|
|
1654
|
+
return newState.flags;
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
const getFocus = uid => {
|
|
1658
|
+
const {
|
|
1659
|
+
newState
|
|
1660
|
+
} = get(uid);
|
|
1661
|
+
return newState.focus;
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1540
1664
|
const Tab = 2;
|
|
1541
1665
|
const Enter = 3;
|
|
1542
1666
|
const End = 255;
|
|
@@ -2253,7 +2377,7 @@ const string = value => {
|
|
|
2253
2377
|
};
|
|
2254
2378
|
|
|
2255
2379
|
const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
|
|
2256
|
-
const getProtocol = uri => {
|
|
2380
|
+
const getProtocol$1 = uri => {
|
|
2257
2381
|
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
2258
2382
|
if (protocolMatch) {
|
|
2259
2383
|
return protocolMatch[1];
|
|
@@ -2455,7 +2579,7 @@ function promisifyRequest(request) {
|
|
|
2455
2579
|
request.removeEventListener('error', error);
|
|
2456
2580
|
};
|
|
2457
2581
|
const success = () => {
|
|
2458
|
-
resolve(wrap
|
|
2582
|
+
resolve(wrap(request.result));
|
|
2459
2583
|
unlisten();
|
|
2460
2584
|
};
|
|
2461
2585
|
const error = () => {
|
|
@@ -2505,7 +2629,7 @@ let idbProxyTraps = {
|
|
|
2505
2629
|
}
|
|
2506
2630
|
}
|
|
2507
2631
|
// Else transform whatever we get back.
|
|
2508
|
-
return wrap
|
|
2632
|
+
return wrap(target[prop]);
|
|
2509
2633
|
},
|
|
2510
2634
|
set(target, prop, value) {
|
|
2511
2635
|
target[prop] = value;
|
|
@@ -2534,13 +2658,13 @@ function wrapFunction(func) {
|
|
|
2534
2658
|
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
2535
2659
|
// the original object.
|
|
2536
2660
|
func.apply(unwrap(this), args);
|
|
2537
|
-
return wrap
|
|
2661
|
+
return wrap(this.request);
|
|
2538
2662
|
};
|
|
2539
2663
|
}
|
|
2540
2664
|
return function (...args) {
|
|
2541
2665
|
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
2542
2666
|
// the original object.
|
|
2543
|
-
return wrap
|
|
2667
|
+
return wrap(func.apply(unwrap(this), args));
|
|
2544
2668
|
};
|
|
2545
2669
|
}
|
|
2546
2670
|
function transformCachableValue(value) {
|
|
@@ -2552,7 +2676,7 @@ function transformCachableValue(value) {
|
|
|
2552
2676
|
// Return the same value back if we're not going to transform it.
|
|
2553
2677
|
return value;
|
|
2554
2678
|
}
|
|
2555
|
-
function wrap
|
|
2679
|
+
function wrap(value) {
|
|
2556
2680
|
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
2557
2681
|
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
2558
2682
|
if (value instanceof IDBRequest) return promisifyRequest(value);
|
|
@@ -2584,10 +2708,10 @@ function openDB(name, version, {
|
|
|
2584
2708
|
terminated
|
|
2585
2709
|
} = {}) {
|
|
2586
2710
|
const request = indexedDB.open(name, version);
|
|
2587
|
-
const openPromise = wrap
|
|
2711
|
+
const openPromise = wrap(request);
|
|
2588
2712
|
if (upgrade) {
|
|
2589
2713
|
request.addEventListener('upgradeneeded', event => {
|
|
2590
|
-
upgrade(wrap
|
|
2714
|
+
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
2591
2715
|
});
|
|
2592
2716
|
}
|
|
2593
2717
|
if (blocked) {
|
|
@@ -2688,7 +2812,7 @@ replaceTraps(oldTraps => ({
|
|
|
2688
2812
|
}
|
|
2689
2813
|
}));
|
|
2690
2814
|
|
|
2691
|
-
const state = {
|
|
2815
|
+
const state$1 = {
|
|
2692
2816
|
databases: Object.create(null),
|
|
2693
2817
|
eventId: 0,
|
|
2694
2818
|
dbVersion: 1,
|
|
@@ -2699,7 +2823,7 @@ const state = {
|
|
|
2699
2823
|
|
|
2700
2824
|
const getHandleDb = async () => {
|
|
2701
2825
|
// @ts-ignore
|
|
2702
|
-
const db = await openDB('handle', state.dbVersion, {
|
|
2826
|
+
const db = await openDB('handle', state$1.dbVersion, {
|
|
2703
2827
|
async upgrade(db) {
|
|
2704
2828
|
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
2705
2829
|
await db.createObjectStore('file-handles-store', {});
|
|
@@ -2817,11 +2941,57 @@ const getRipGrepArgs = ({
|
|
|
2817
2941
|
return ripGrepArgs;
|
|
2818
2942
|
};
|
|
2819
2943
|
|
|
2820
|
-
const
|
|
2821
|
-
|
|
2944
|
+
const Remote = 3;
|
|
2945
|
+
|
|
2946
|
+
const Https = 'https:';
|
|
2947
|
+
const Ws = 'ws:';
|
|
2948
|
+
const Wss = 'wss:';
|
|
2949
|
+
|
|
2950
|
+
const getWebSocketProtocol = locationProtocol => {
|
|
2951
|
+
return locationProtocol === Https ? Wss : Ws;
|
|
2952
|
+
};
|
|
2953
|
+
|
|
2954
|
+
const getWebSocketUrl = (type, host, locationProtocol) => {
|
|
2955
|
+
const wsProtocol = getWebSocketProtocol(locationProtocol);
|
|
2956
|
+
return `${wsProtocol}//${host}/websocket/${type}`;
|
|
2957
|
+
};
|
|
2958
|
+
|
|
2959
|
+
const getHost = () => {
|
|
2960
|
+
return location.host;
|
|
2961
|
+
};
|
|
2962
|
+
const getProtocol = () => {
|
|
2963
|
+
return location.protocol;
|
|
2822
2964
|
};
|
|
2823
2965
|
|
|
2824
|
-
const
|
|
2966
|
+
const launchSearchProcess = async () => {
|
|
2967
|
+
const host = getHost();
|
|
2968
|
+
const protocol = getProtocol();
|
|
2969
|
+
const wsUrl = getWebSocketUrl('search-process', host, protocol);
|
|
2970
|
+
const webSocket = new WebSocket(wsUrl);
|
|
2971
|
+
const rpc = await WebSocketRpcParent.create({
|
|
2972
|
+
webSocket,
|
|
2973
|
+
commandMap: {}
|
|
2974
|
+
});
|
|
2975
|
+
return rpc;
|
|
2976
|
+
};
|
|
2977
|
+
|
|
2978
|
+
const state = {
|
|
2979
|
+
rpc: undefined
|
|
2980
|
+
};
|
|
2981
|
+
const getOrCreate = () => {
|
|
2982
|
+
if (!state.rpc) {
|
|
2983
|
+
// @ts-ignore
|
|
2984
|
+
state.rpc = launchSearchProcess();
|
|
2985
|
+
}
|
|
2986
|
+
return state.rpc;
|
|
2987
|
+
};
|
|
2988
|
+
|
|
2989
|
+
const invoke = async (method, ...params) => {
|
|
2990
|
+
const rpc = await getOrCreate();
|
|
2991
|
+
return rpc.invoke(method, ...params);
|
|
2992
|
+
};
|
|
2993
|
+
|
|
2994
|
+
const textSearch$2 = async (scheme, root, query, options, assetDir, platform) => {
|
|
2825
2995
|
const ripGrepArgs = getRipGrepArgs({
|
|
2826
2996
|
...options,
|
|
2827
2997
|
searchString: query
|
|
@@ -2830,9 +3000,14 @@ const textSearch$2 = async (scheme, root, query, options) => {
|
|
|
2830
3000
|
ripGrepArgs,
|
|
2831
3001
|
searchDir: root
|
|
2832
3002
|
};
|
|
2833
|
-
|
|
3003
|
+
if (platform === Remote) {
|
|
3004
|
+
const result = await invoke('TextSearch.search', actualOptions);
|
|
3005
|
+
// TODO api is weird
|
|
3006
|
+
return result.results;
|
|
3007
|
+
}
|
|
3008
|
+
const results = await invoke$1('SearchProcess.invoke', 'TextSearch.search', actualOptions);
|
|
2834
3009
|
// TODO api is weird
|
|
2835
|
-
return
|
|
3010
|
+
return results.results;
|
|
2836
3011
|
};
|
|
2837
3012
|
|
|
2838
3013
|
const textSearch$1 = (scheme, root, query) => {
|
|
@@ -2866,12 +3041,12 @@ const getProvider = scheme => {
|
|
|
2866
3041
|
}
|
|
2867
3042
|
};
|
|
2868
3043
|
|
|
2869
|
-
const textSearch = async (root, query, options, assetDir) => {
|
|
3044
|
+
const textSearch = async (root, query, options, assetDir, platform) => {
|
|
2870
3045
|
string(root);
|
|
2871
3046
|
string(query);
|
|
2872
|
-
const scheme = getProtocol(root);
|
|
3047
|
+
const scheme = getProtocol$1(root);
|
|
2873
3048
|
const provider = getProvider(scheme);
|
|
2874
|
-
const results = await provider(scheme, root, query, options, assetDir);
|
|
3049
|
+
const results = await provider(scheme, root, query, options, assetDir, platform);
|
|
2875
3050
|
return results;
|
|
2876
3051
|
};
|
|
2877
3052
|
|
|
@@ -2908,7 +3083,7 @@ const handleUpdate = async (state, update) => {
|
|
|
2908
3083
|
threads,
|
|
2909
3084
|
isCaseSensitive: hasMatchCase(flags),
|
|
2910
3085
|
useRegularExpression: hasUseRegularExpression(flags)
|
|
2911
|
-
}, state.assetDir);
|
|
3086
|
+
}, state.assetDir, state.platform);
|
|
2912
3087
|
if (!Array.isArray(results)) {
|
|
2913
3088
|
throw new TypeError('results must be of type array');
|
|
2914
3089
|
}
|
|
@@ -3023,296 +3198,6 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
|
|
|
3023
3198
|
return fn(state, value, inputSource);
|
|
3024
3199
|
};
|
|
3025
3200
|
|
|
3026
|
-
const NodeAlternate = 8;
|
|
3027
|
-
|
|
3028
|
-
const getData = event => {
|
|
3029
|
-
const {
|
|
3030
|
-
data
|
|
3031
|
-
} = event;
|
|
3032
|
-
return data;
|
|
3033
|
-
};
|
|
3034
|
-
|
|
3035
|
-
const getPortTuple = () => {
|
|
3036
|
-
const {
|
|
3037
|
-
port1,
|
|
3038
|
-
port2
|
|
3039
|
-
} = new MessageChannel();
|
|
3040
|
-
return {
|
|
3041
|
-
port1,
|
|
3042
|
-
port2
|
|
3043
|
-
};
|
|
3044
|
-
};
|
|
3045
|
-
|
|
3046
|
-
const Open = 1;
|
|
3047
|
-
const Close = 2;
|
|
3048
|
-
|
|
3049
|
-
const Https = 'https:';
|
|
3050
|
-
const Ws = 'ws:';
|
|
3051
|
-
const Wss = 'wss:';
|
|
3052
|
-
|
|
3053
|
-
const getWebSocketProtocol = () => {
|
|
3054
|
-
return location.protocol === Https ? Wss : Ws;
|
|
3055
|
-
};
|
|
3056
|
-
|
|
3057
|
-
const getWebSocketUrl = (type, host) => {
|
|
3058
|
-
const wsProtocol = getWebSocketProtocol();
|
|
3059
|
-
return `${wsProtocol}//${host}/websocket/${type}`;
|
|
3060
|
-
};
|
|
3061
|
-
|
|
3062
|
-
class IpcError extends Error {
|
|
3063
|
-
constructor(message) {
|
|
3064
|
-
super(message);
|
|
3065
|
-
this.name = 'IpcError';
|
|
3066
|
-
}
|
|
3067
|
-
}
|
|
3068
|
-
|
|
3069
|
-
const stringifyCompact = value => {
|
|
3070
|
-
return JSON.stringify(value);
|
|
3071
|
-
};
|
|
3072
|
-
const parse = content => {
|
|
3073
|
-
if (content === 'undefined') {
|
|
3074
|
-
return null;
|
|
3075
|
-
}
|
|
3076
|
-
// TODO use better json parse to throw more helpful error messages if json is invalid
|
|
3077
|
-
try {
|
|
3078
|
-
return JSON.parse(content);
|
|
3079
|
-
} catch (error) {
|
|
3080
|
-
throw new VError(error, 'failed to parse json');
|
|
3081
|
-
}
|
|
3082
|
-
};
|
|
3083
|
-
|
|
3084
|
-
const create$3 = (url, args) => {
|
|
3085
|
-
const webSocket = new WebSocket(url, args);
|
|
3086
|
-
const reconnect = () => {
|
|
3087
|
-
const originalOnMessage = context.webSocket.onmessage;
|
|
3088
|
-
context.webSocket = new WebSocket(url, args);
|
|
3089
|
-
context.webSocket.onmessage = originalOnMessage;
|
|
3090
|
-
context.webSocket.onclose = handleClose;
|
|
3091
|
-
};
|
|
3092
|
-
const handleClose = () => {
|
|
3093
|
-
setTimeout(reconnect, 2000);
|
|
3094
|
-
};
|
|
3095
|
-
const context = {
|
|
3096
|
-
webSocket,
|
|
3097
|
-
get onmessage() {
|
|
3098
|
-
return this.webSocket.onmessage;
|
|
3099
|
-
},
|
|
3100
|
-
set onmessage(value) {
|
|
3101
|
-
this.webSocket.onmessage = value;
|
|
3102
|
-
},
|
|
3103
|
-
send(message) {
|
|
3104
|
-
this.webSocket.send(message);
|
|
3105
|
-
},
|
|
3106
|
-
addEventListener(type, listener) {
|
|
3107
|
-
this.webSocket.addEventListener(type, listener);
|
|
3108
|
-
},
|
|
3109
|
-
removeEventListener(type, listener) {
|
|
3110
|
-
this.webSocket.removeEventListener(type, listener);
|
|
3111
|
-
}
|
|
3112
|
-
};
|
|
3113
|
-
webSocket.onclose = handleClose;
|
|
3114
|
-
return context;
|
|
3115
|
-
};
|
|
3116
|
-
|
|
3117
|
-
const getFirstEvent = (eventTarget, eventMap) => {
|
|
3118
|
-
const {
|
|
3119
|
-
resolve,
|
|
3120
|
-
promise
|
|
3121
|
-
} = Promise.withResolvers();
|
|
3122
|
-
const listenerMap = Object.create(null);
|
|
3123
|
-
const cleanup = value => {
|
|
3124
|
-
for (const event of Object.keys(eventMap)) {
|
|
3125
|
-
eventTarget.removeEventListener(event, listenerMap[event]);
|
|
3126
|
-
}
|
|
3127
|
-
resolve(value);
|
|
3128
|
-
};
|
|
3129
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
3130
|
-
const listener = event => {
|
|
3131
|
-
cleanup({
|
|
3132
|
-
type,
|
|
3133
|
-
event
|
|
3134
|
-
});
|
|
3135
|
-
};
|
|
3136
|
-
eventTarget.addEventListener(event, listener);
|
|
3137
|
-
listenerMap[event] = listener;
|
|
3138
|
-
}
|
|
3139
|
-
return promise;
|
|
3140
|
-
};
|
|
3141
|
-
|
|
3142
|
-
const waitForWebSocketToBeOpen = webSocket => {
|
|
3143
|
-
return getFirstEvent(webSocket, {
|
|
3144
|
-
open: Open,
|
|
3145
|
-
close: Close
|
|
3146
|
-
});
|
|
3147
|
-
};
|
|
3148
|
-
|
|
3149
|
-
const getHost = () => {
|
|
3150
|
-
return location.host;
|
|
3151
|
-
};
|
|
3152
|
-
|
|
3153
|
-
const create$2 = async ({
|
|
3154
|
-
type
|
|
3155
|
-
}) => {
|
|
3156
|
-
string(type);
|
|
3157
|
-
const host = getHost();
|
|
3158
|
-
const wsUrl = getWebSocketUrl(type, host);
|
|
3159
|
-
const webSocket = create$3(wsUrl);
|
|
3160
|
-
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
3161
|
-
if (firstWebSocketEvent.type === Close) {
|
|
3162
|
-
throw new IpcError('Websocket connection was immediately closed');
|
|
3163
|
-
}
|
|
3164
|
-
return webSocket;
|
|
3165
|
-
};
|
|
3166
|
-
const getMessage = event => {
|
|
3167
|
-
return parse(event.data);
|
|
3168
|
-
};
|
|
3169
|
-
const wrap$1 = webSocket => {
|
|
3170
|
-
return {
|
|
3171
|
-
webSocket,
|
|
3172
|
-
/**
|
|
3173
|
-
* @type {any}
|
|
3174
|
-
*/
|
|
3175
|
-
listener: undefined,
|
|
3176
|
-
get onmessage() {
|
|
3177
|
-
return this.listener;
|
|
3178
|
-
},
|
|
3179
|
-
set onmessage(listener) {
|
|
3180
|
-
this.listener = listener;
|
|
3181
|
-
const wrappedListener = event => {
|
|
3182
|
-
const message = getMessage(event);
|
|
3183
|
-
const syntheticEvent = {
|
|
3184
|
-
data: message,
|
|
3185
|
-
target: this
|
|
3186
|
-
};
|
|
3187
|
-
listener(syntheticEvent);
|
|
3188
|
-
};
|
|
3189
|
-
this.webSocket.onmessage = wrappedListener;
|
|
3190
|
-
},
|
|
3191
|
-
send(message) {
|
|
3192
|
-
const stringifiedMessage = stringifyCompact(message);
|
|
3193
|
-
this.webSocket.send(stringifiedMessage);
|
|
3194
|
-
}
|
|
3195
|
-
};
|
|
3196
|
-
};
|
|
3197
|
-
|
|
3198
|
-
const IpcParentWithWebSocket = {
|
|
3199
|
-
__proto__: null,
|
|
3200
|
-
create: create$2,
|
|
3201
|
-
wrap: wrap$1
|
|
3202
|
-
};
|
|
3203
|
-
|
|
3204
|
-
const Web = 1;
|
|
3205
|
-
const Electron = 2;
|
|
3206
|
-
const Remote = 3;
|
|
3207
|
-
|
|
3208
|
-
const sendMessagePortToElectron = async (port, initialCommand, ipcId) => {
|
|
3209
|
-
object(port);
|
|
3210
|
-
string(initialCommand);
|
|
3211
|
-
await invokeAndTransfer(initialCommand, port, ipcId);
|
|
3212
|
-
};
|
|
3213
|
-
|
|
3214
|
-
const create$1 = async options => {
|
|
3215
|
-
switch (options.platform) {
|
|
3216
|
-
case Web:
|
|
3217
|
-
case Remote:
|
|
3218
|
-
const module = IpcParentWithWebSocket;
|
|
3219
|
-
const rawIpc = await module.create(options);
|
|
3220
|
-
if (options.raw) {
|
|
3221
|
-
return rawIpc;
|
|
3222
|
-
}
|
|
3223
|
-
return {
|
|
3224
|
-
rawIpc,
|
|
3225
|
-
module
|
|
3226
|
-
};
|
|
3227
|
-
case Electron:
|
|
3228
|
-
const {
|
|
3229
|
-
port1,
|
|
3230
|
-
port2
|
|
3231
|
-
} = getPortTuple();
|
|
3232
|
-
await sendMessagePortToElectron(port2, options.initialCommand, options.ipcId);
|
|
3233
|
-
return port1;
|
|
3234
|
-
default:
|
|
3235
|
-
throw new Error('unsupported platform');
|
|
3236
|
-
}
|
|
3237
|
-
};
|
|
3238
|
-
const wrap = port => {
|
|
3239
|
-
if (!(port instanceof MessagePort)) {
|
|
3240
|
-
return port.module.wrap(port.rawIpc);
|
|
3241
|
-
}
|
|
3242
|
-
return {
|
|
3243
|
-
port,
|
|
3244
|
-
/**
|
|
3245
|
-
* @type {any}
|
|
3246
|
-
*/
|
|
3247
|
-
listener: undefined,
|
|
3248
|
-
get onmessage() {
|
|
3249
|
-
return this.listener;
|
|
3250
|
-
},
|
|
3251
|
-
set onmessage(listener) {
|
|
3252
|
-
this.listener = listener;
|
|
3253
|
-
const wrappedListener = event => {
|
|
3254
|
-
const data = getData(event);
|
|
3255
|
-
const syntheticEvent = {
|
|
3256
|
-
data,
|
|
3257
|
-
target: this
|
|
3258
|
-
};
|
|
3259
|
-
listener(syntheticEvent);
|
|
3260
|
-
};
|
|
3261
|
-
this.port.onmessage = wrappedListener;
|
|
3262
|
-
},
|
|
3263
|
-
send(message) {
|
|
3264
|
-
this.port.postMessage(message);
|
|
3265
|
-
},
|
|
3266
|
-
sendAndTransfer(message, transfer) {
|
|
3267
|
-
this.port.postMessage(message, transfer);
|
|
3268
|
-
}
|
|
3269
|
-
};
|
|
3270
|
-
};
|
|
3271
|
-
|
|
3272
|
-
const IpcParentWithNodeAlternate = {
|
|
3273
|
-
__proto__: null,
|
|
3274
|
-
create: create$1,
|
|
3275
|
-
wrap
|
|
3276
|
-
};
|
|
3277
|
-
|
|
3278
|
-
const getModule = method => {
|
|
3279
|
-
switch (method) {
|
|
3280
|
-
case NodeAlternate:
|
|
3281
|
-
return IpcParentWithNodeAlternate;
|
|
3282
|
-
default:
|
|
3283
|
-
throw new Error('unexpected ipc type');
|
|
3284
|
-
}
|
|
3285
|
-
};
|
|
3286
|
-
|
|
3287
|
-
const create = async ({
|
|
3288
|
-
method,
|
|
3289
|
-
...options
|
|
3290
|
-
}) => {
|
|
3291
|
-
const module = getModule(method);
|
|
3292
|
-
// @ts-ignore
|
|
3293
|
-
const rawIpc = await module.create(options);
|
|
3294
|
-
if (options.noReturn) {
|
|
3295
|
-
return undefined;
|
|
3296
|
-
}
|
|
3297
|
-
if (options.raw) {
|
|
3298
|
-
return rawIpc;
|
|
3299
|
-
}
|
|
3300
|
-
const ipc = module.wrap(rawIpc);
|
|
3301
|
-
return ipc;
|
|
3302
|
-
};
|
|
3303
|
-
|
|
3304
|
-
const launchSearchProcess = async () => {
|
|
3305
|
-
const ipc = await create({
|
|
3306
|
-
method: NodeAlternate,
|
|
3307
|
-
type: 'search-process',
|
|
3308
|
-
name: 'Search Process',
|
|
3309
|
-
initialCommand: 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess'
|
|
3310
|
-
});
|
|
3311
|
-
// TODO
|
|
3312
|
-
// HandleIpc.handleIpc(ipc)
|
|
3313
|
-
return ipc;
|
|
3314
|
-
};
|
|
3315
|
-
|
|
3316
3201
|
const first = () => {
|
|
3317
3202
|
return 0;
|
|
3318
3203
|
};
|
|
@@ -4233,10 +4118,12 @@ const commandMap = {
|
|
|
4233
4118
|
'TextSearch.toggleUseIgnoreFiles': wrapCommand(toggleUseIgnoreFiles),
|
|
4234
4119
|
'TextSearch.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
|
|
4235
4120
|
// not wrapped
|
|
4236
|
-
'TextSearch.create': create
|
|
4121
|
+
'TextSearch.create': create,
|
|
4122
|
+
'TextSearch.getFlags': getFlags,
|
|
4123
|
+
'TextSearch.getFocus': getFocus,
|
|
4124
|
+
'TextSearch.getKeyBindings': getKeyBindings,
|
|
4237
4125
|
'TextSearch.render': doRender,
|
|
4238
4126
|
'TextSearch.saveState': saveState,
|
|
4239
|
-
'TextSearch.getKeyBindings': getKeyBindings,
|
|
4240
4127
|
// TODO needed?
|
|
4241
4128
|
'TextSearch.textSearch': textSearch
|
|
4242
4129
|
};
|