@lvce-editor/text-search-worker 3.14.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 +209 -337
- 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;
|
|
@@ -2266,7 +2377,7 @@ const string = value => {
|
|
|
2266
2377
|
};
|
|
2267
2378
|
|
|
2268
2379
|
const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
|
|
2269
|
-
const getProtocol = uri => {
|
|
2380
|
+
const getProtocol$1 = uri => {
|
|
2270
2381
|
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
2271
2382
|
if (protocolMatch) {
|
|
2272
2383
|
return protocolMatch[1];
|
|
@@ -2468,7 +2579,7 @@ function promisifyRequest(request) {
|
|
|
2468
2579
|
request.removeEventListener('error', error);
|
|
2469
2580
|
};
|
|
2470
2581
|
const success = () => {
|
|
2471
|
-
resolve(wrap
|
|
2582
|
+
resolve(wrap(request.result));
|
|
2472
2583
|
unlisten();
|
|
2473
2584
|
};
|
|
2474
2585
|
const error = () => {
|
|
@@ -2518,7 +2629,7 @@ let idbProxyTraps = {
|
|
|
2518
2629
|
}
|
|
2519
2630
|
}
|
|
2520
2631
|
// Else transform whatever we get back.
|
|
2521
|
-
return wrap
|
|
2632
|
+
return wrap(target[prop]);
|
|
2522
2633
|
},
|
|
2523
2634
|
set(target, prop, value) {
|
|
2524
2635
|
target[prop] = value;
|
|
@@ -2547,13 +2658,13 @@ function wrapFunction(func) {
|
|
|
2547
2658
|
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
2548
2659
|
// the original object.
|
|
2549
2660
|
func.apply(unwrap(this), args);
|
|
2550
|
-
return wrap
|
|
2661
|
+
return wrap(this.request);
|
|
2551
2662
|
};
|
|
2552
2663
|
}
|
|
2553
2664
|
return function (...args) {
|
|
2554
2665
|
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
2555
2666
|
// the original object.
|
|
2556
|
-
return wrap
|
|
2667
|
+
return wrap(func.apply(unwrap(this), args));
|
|
2557
2668
|
};
|
|
2558
2669
|
}
|
|
2559
2670
|
function transformCachableValue(value) {
|
|
@@ -2565,7 +2676,7 @@ function transformCachableValue(value) {
|
|
|
2565
2676
|
// Return the same value back if we're not going to transform it.
|
|
2566
2677
|
return value;
|
|
2567
2678
|
}
|
|
2568
|
-
function wrap
|
|
2679
|
+
function wrap(value) {
|
|
2569
2680
|
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
2570
2681
|
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
2571
2682
|
if (value instanceof IDBRequest) return promisifyRequest(value);
|
|
@@ -2597,10 +2708,10 @@ function openDB(name, version, {
|
|
|
2597
2708
|
terminated
|
|
2598
2709
|
} = {}) {
|
|
2599
2710
|
const request = indexedDB.open(name, version);
|
|
2600
|
-
const openPromise = wrap
|
|
2711
|
+
const openPromise = wrap(request);
|
|
2601
2712
|
if (upgrade) {
|
|
2602
2713
|
request.addEventListener('upgradeneeded', event => {
|
|
2603
|
-
upgrade(wrap
|
|
2714
|
+
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
2604
2715
|
});
|
|
2605
2716
|
}
|
|
2606
2717
|
if (blocked) {
|
|
@@ -2701,7 +2812,7 @@ replaceTraps(oldTraps => ({
|
|
|
2701
2812
|
}
|
|
2702
2813
|
}));
|
|
2703
2814
|
|
|
2704
|
-
const state = {
|
|
2815
|
+
const state$1 = {
|
|
2705
2816
|
databases: Object.create(null),
|
|
2706
2817
|
eventId: 0,
|
|
2707
2818
|
dbVersion: 1,
|
|
@@ -2712,7 +2823,7 @@ const state = {
|
|
|
2712
2823
|
|
|
2713
2824
|
const getHandleDb = async () => {
|
|
2714
2825
|
// @ts-ignore
|
|
2715
|
-
const db = await openDB('handle', state.dbVersion, {
|
|
2826
|
+
const db = await openDB('handle', state$1.dbVersion, {
|
|
2716
2827
|
async upgrade(db) {
|
|
2717
2828
|
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
2718
2829
|
await db.createObjectStore('file-handles-store', {});
|
|
@@ -2830,11 +2941,57 @@ const getRipGrepArgs = ({
|
|
|
2830
2941
|
return ripGrepArgs;
|
|
2831
2942
|
};
|
|
2832
2943
|
|
|
2833
|
-
const
|
|
2834
|
-
|
|
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;
|
|
2964
|
+
};
|
|
2965
|
+
|
|
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);
|
|
2835
2992
|
};
|
|
2836
2993
|
|
|
2837
|
-
const textSearch$2 = async (scheme, root, query, options) => {
|
|
2994
|
+
const textSearch$2 = async (scheme, root, query, options, assetDir, platform) => {
|
|
2838
2995
|
const ripGrepArgs = getRipGrepArgs({
|
|
2839
2996
|
...options,
|
|
2840
2997
|
searchString: query
|
|
@@ -2843,9 +3000,14 @@ const textSearch$2 = async (scheme, root, query, options) => {
|
|
|
2843
3000
|
ripGrepArgs,
|
|
2844
3001
|
searchDir: root
|
|
2845
3002
|
};
|
|
2846
|
-
|
|
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);
|
|
2847
3009
|
// TODO api is weird
|
|
2848
|
-
return
|
|
3010
|
+
return results.results;
|
|
2849
3011
|
};
|
|
2850
3012
|
|
|
2851
3013
|
const textSearch$1 = (scheme, root, query) => {
|
|
@@ -2879,12 +3041,12 @@ const getProvider = scheme => {
|
|
|
2879
3041
|
}
|
|
2880
3042
|
};
|
|
2881
3043
|
|
|
2882
|
-
const textSearch = async (root, query, options, assetDir) => {
|
|
3044
|
+
const textSearch = async (root, query, options, assetDir, platform) => {
|
|
2883
3045
|
string(root);
|
|
2884
3046
|
string(query);
|
|
2885
|
-
const scheme = getProtocol(root);
|
|
3047
|
+
const scheme = getProtocol$1(root);
|
|
2886
3048
|
const provider = getProvider(scheme);
|
|
2887
|
-
const results = await provider(scheme, root, query, options, assetDir);
|
|
3049
|
+
const results = await provider(scheme, root, query, options, assetDir, platform);
|
|
2888
3050
|
return results;
|
|
2889
3051
|
};
|
|
2890
3052
|
|
|
@@ -2921,7 +3083,7 @@ const handleUpdate = async (state, update) => {
|
|
|
2921
3083
|
threads,
|
|
2922
3084
|
isCaseSensitive: hasMatchCase(flags),
|
|
2923
3085
|
useRegularExpression: hasUseRegularExpression(flags)
|
|
2924
|
-
}, state.assetDir);
|
|
3086
|
+
}, state.assetDir, state.platform);
|
|
2925
3087
|
if (!Array.isArray(results)) {
|
|
2926
3088
|
throw new TypeError('results must be of type array');
|
|
2927
3089
|
}
|
|
@@ -3036,296 +3198,6 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
|
|
|
3036
3198
|
return fn(state, value, inputSource);
|
|
3037
3199
|
};
|
|
3038
3200
|
|
|
3039
|
-
const NodeAlternate = 8;
|
|
3040
|
-
|
|
3041
|
-
const getData = event => {
|
|
3042
|
-
const {
|
|
3043
|
-
data
|
|
3044
|
-
} = event;
|
|
3045
|
-
return data;
|
|
3046
|
-
};
|
|
3047
|
-
|
|
3048
|
-
const getPortTuple = () => {
|
|
3049
|
-
const {
|
|
3050
|
-
port1,
|
|
3051
|
-
port2
|
|
3052
|
-
} = new MessageChannel();
|
|
3053
|
-
return {
|
|
3054
|
-
port1,
|
|
3055
|
-
port2
|
|
3056
|
-
};
|
|
3057
|
-
};
|
|
3058
|
-
|
|
3059
|
-
const Open = 1;
|
|
3060
|
-
const Close = 2;
|
|
3061
|
-
|
|
3062
|
-
const Https = 'https:';
|
|
3063
|
-
const Ws = 'ws:';
|
|
3064
|
-
const Wss = 'wss:';
|
|
3065
|
-
|
|
3066
|
-
const getWebSocketProtocol = () => {
|
|
3067
|
-
return location.protocol === Https ? Wss : Ws;
|
|
3068
|
-
};
|
|
3069
|
-
|
|
3070
|
-
const getWebSocketUrl = (type, host) => {
|
|
3071
|
-
const wsProtocol = getWebSocketProtocol();
|
|
3072
|
-
return `${wsProtocol}//${host}/websocket/${type}`;
|
|
3073
|
-
};
|
|
3074
|
-
|
|
3075
|
-
class IpcError extends Error {
|
|
3076
|
-
constructor(message) {
|
|
3077
|
-
super(message);
|
|
3078
|
-
this.name = 'IpcError';
|
|
3079
|
-
}
|
|
3080
|
-
}
|
|
3081
|
-
|
|
3082
|
-
const stringifyCompact = value => {
|
|
3083
|
-
return JSON.stringify(value);
|
|
3084
|
-
};
|
|
3085
|
-
const parse = content => {
|
|
3086
|
-
if (content === 'undefined') {
|
|
3087
|
-
return null;
|
|
3088
|
-
}
|
|
3089
|
-
// TODO use better json parse to throw more helpful error messages if json is invalid
|
|
3090
|
-
try {
|
|
3091
|
-
return JSON.parse(content);
|
|
3092
|
-
} catch (error) {
|
|
3093
|
-
throw new VError(error, 'failed to parse json');
|
|
3094
|
-
}
|
|
3095
|
-
};
|
|
3096
|
-
|
|
3097
|
-
const create$3 = (url, args) => {
|
|
3098
|
-
const webSocket = new WebSocket(url, args);
|
|
3099
|
-
const reconnect = () => {
|
|
3100
|
-
const originalOnMessage = context.webSocket.onmessage;
|
|
3101
|
-
context.webSocket = new WebSocket(url, args);
|
|
3102
|
-
context.webSocket.onmessage = originalOnMessage;
|
|
3103
|
-
context.webSocket.onclose = handleClose;
|
|
3104
|
-
};
|
|
3105
|
-
const handleClose = () => {
|
|
3106
|
-
setTimeout(reconnect, 2000);
|
|
3107
|
-
};
|
|
3108
|
-
const context = {
|
|
3109
|
-
webSocket,
|
|
3110
|
-
get onmessage() {
|
|
3111
|
-
return this.webSocket.onmessage;
|
|
3112
|
-
},
|
|
3113
|
-
set onmessage(value) {
|
|
3114
|
-
this.webSocket.onmessage = value;
|
|
3115
|
-
},
|
|
3116
|
-
send(message) {
|
|
3117
|
-
this.webSocket.send(message);
|
|
3118
|
-
},
|
|
3119
|
-
addEventListener(type, listener) {
|
|
3120
|
-
this.webSocket.addEventListener(type, listener);
|
|
3121
|
-
},
|
|
3122
|
-
removeEventListener(type, listener) {
|
|
3123
|
-
this.webSocket.removeEventListener(type, listener);
|
|
3124
|
-
}
|
|
3125
|
-
};
|
|
3126
|
-
webSocket.onclose = handleClose;
|
|
3127
|
-
return context;
|
|
3128
|
-
};
|
|
3129
|
-
|
|
3130
|
-
const getFirstEvent = (eventTarget, eventMap) => {
|
|
3131
|
-
const {
|
|
3132
|
-
resolve,
|
|
3133
|
-
promise
|
|
3134
|
-
} = Promise.withResolvers();
|
|
3135
|
-
const listenerMap = Object.create(null);
|
|
3136
|
-
const cleanup = value => {
|
|
3137
|
-
for (const event of Object.keys(eventMap)) {
|
|
3138
|
-
eventTarget.removeEventListener(event, listenerMap[event]);
|
|
3139
|
-
}
|
|
3140
|
-
resolve(value);
|
|
3141
|
-
};
|
|
3142
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
3143
|
-
const listener = event => {
|
|
3144
|
-
cleanup({
|
|
3145
|
-
type,
|
|
3146
|
-
event
|
|
3147
|
-
});
|
|
3148
|
-
};
|
|
3149
|
-
eventTarget.addEventListener(event, listener);
|
|
3150
|
-
listenerMap[event] = listener;
|
|
3151
|
-
}
|
|
3152
|
-
return promise;
|
|
3153
|
-
};
|
|
3154
|
-
|
|
3155
|
-
const waitForWebSocketToBeOpen = webSocket => {
|
|
3156
|
-
return getFirstEvent(webSocket, {
|
|
3157
|
-
open: Open,
|
|
3158
|
-
close: Close
|
|
3159
|
-
});
|
|
3160
|
-
};
|
|
3161
|
-
|
|
3162
|
-
const getHost = () => {
|
|
3163
|
-
return location.host;
|
|
3164
|
-
};
|
|
3165
|
-
|
|
3166
|
-
const create$2 = async ({
|
|
3167
|
-
type
|
|
3168
|
-
}) => {
|
|
3169
|
-
string(type);
|
|
3170
|
-
const host = getHost();
|
|
3171
|
-
const wsUrl = getWebSocketUrl(type, host);
|
|
3172
|
-
const webSocket = create$3(wsUrl);
|
|
3173
|
-
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
3174
|
-
if (firstWebSocketEvent.type === Close) {
|
|
3175
|
-
throw new IpcError('Websocket connection was immediately closed');
|
|
3176
|
-
}
|
|
3177
|
-
return webSocket;
|
|
3178
|
-
};
|
|
3179
|
-
const getMessage = event => {
|
|
3180
|
-
return parse(event.data);
|
|
3181
|
-
};
|
|
3182
|
-
const wrap$1 = webSocket => {
|
|
3183
|
-
return {
|
|
3184
|
-
webSocket,
|
|
3185
|
-
/**
|
|
3186
|
-
* @type {any}
|
|
3187
|
-
*/
|
|
3188
|
-
listener: undefined,
|
|
3189
|
-
get onmessage() {
|
|
3190
|
-
return this.listener;
|
|
3191
|
-
},
|
|
3192
|
-
set onmessage(listener) {
|
|
3193
|
-
this.listener = listener;
|
|
3194
|
-
const wrappedListener = event => {
|
|
3195
|
-
const message = getMessage(event);
|
|
3196
|
-
const syntheticEvent = {
|
|
3197
|
-
data: message,
|
|
3198
|
-
target: this
|
|
3199
|
-
};
|
|
3200
|
-
listener(syntheticEvent);
|
|
3201
|
-
};
|
|
3202
|
-
this.webSocket.onmessage = wrappedListener;
|
|
3203
|
-
},
|
|
3204
|
-
send(message) {
|
|
3205
|
-
const stringifiedMessage = stringifyCompact(message);
|
|
3206
|
-
this.webSocket.send(stringifiedMessage);
|
|
3207
|
-
}
|
|
3208
|
-
};
|
|
3209
|
-
};
|
|
3210
|
-
|
|
3211
|
-
const IpcParentWithWebSocket = {
|
|
3212
|
-
__proto__: null,
|
|
3213
|
-
create: create$2,
|
|
3214
|
-
wrap: wrap$1
|
|
3215
|
-
};
|
|
3216
|
-
|
|
3217
|
-
const Web = 1;
|
|
3218
|
-
const Electron = 2;
|
|
3219
|
-
const Remote = 3;
|
|
3220
|
-
|
|
3221
|
-
const sendMessagePortToElectron = async (port, initialCommand, ipcId) => {
|
|
3222
|
-
object(port);
|
|
3223
|
-
string(initialCommand);
|
|
3224
|
-
await invokeAndTransfer(initialCommand, port, ipcId);
|
|
3225
|
-
};
|
|
3226
|
-
|
|
3227
|
-
const create$1 = async options => {
|
|
3228
|
-
switch (options.platform) {
|
|
3229
|
-
case Web:
|
|
3230
|
-
case Remote:
|
|
3231
|
-
const module = IpcParentWithWebSocket;
|
|
3232
|
-
const rawIpc = await module.create(options);
|
|
3233
|
-
if (options.raw) {
|
|
3234
|
-
return rawIpc;
|
|
3235
|
-
}
|
|
3236
|
-
return {
|
|
3237
|
-
rawIpc,
|
|
3238
|
-
module
|
|
3239
|
-
};
|
|
3240
|
-
case Electron:
|
|
3241
|
-
const {
|
|
3242
|
-
port1,
|
|
3243
|
-
port2
|
|
3244
|
-
} = getPortTuple();
|
|
3245
|
-
await sendMessagePortToElectron(port2, options.initialCommand, options.ipcId);
|
|
3246
|
-
return port1;
|
|
3247
|
-
default:
|
|
3248
|
-
throw new Error('unsupported platform');
|
|
3249
|
-
}
|
|
3250
|
-
};
|
|
3251
|
-
const wrap = port => {
|
|
3252
|
-
if (!(port instanceof MessagePort)) {
|
|
3253
|
-
return port.module.wrap(port.rawIpc);
|
|
3254
|
-
}
|
|
3255
|
-
return {
|
|
3256
|
-
port,
|
|
3257
|
-
/**
|
|
3258
|
-
* @type {any}
|
|
3259
|
-
*/
|
|
3260
|
-
listener: undefined,
|
|
3261
|
-
get onmessage() {
|
|
3262
|
-
return this.listener;
|
|
3263
|
-
},
|
|
3264
|
-
set onmessage(listener) {
|
|
3265
|
-
this.listener = listener;
|
|
3266
|
-
const wrappedListener = event => {
|
|
3267
|
-
const data = getData(event);
|
|
3268
|
-
const syntheticEvent = {
|
|
3269
|
-
data,
|
|
3270
|
-
target: this
|
|
3271
|
-
};
|
|
3272
|
-
listener(syntheticEvent);
|
|
3273
|
-
};
|
|
3274
|
-
this.port.onmessage = wrappedListener;
|
|
3275
|
-
},
|
|
3276
|
-
send(message) {
|
|
3277
|
-
this.port.postMessage(message);
|
|
3278
|
-
},
|
|
3279
|
-
sendAndTransfer(message, transfer) {
|
|
3280
|
-
this.port.postMessage(message, transfer);
|
|
3281
|
-
}
|
|
3282
|
-
};
|
|
3283
|
-
};
|
|
3284
|
-
|
|
3285
|
-
const IpcParentWithNodeAlternate = {
|
|
3286
|
-
__proto__: null,
|
|
3287
|
-
create: create$1,
|
|
3288
|
-
wrap
|
|
3289
|
-
};
|
|
3290
|
-
|
|
3291
|
-
const getModule = method => {
|
|
3292
|
-
switch (method) {
|
|
3293
|
-
case NodeAlternate:
|
|
3294
|
-
return IpcParentWithNodeAlternate;
|
|
3295
|
-
default:
|
|
3296
|
-
throw new Error('unexpected ipc type');
|
|
3297
|
-
}
|
|
3298
|
-
};
|
|
3299
|
-
|
|
3300
|
-
const create = async ({
|
|
3301
|
-
method,
|
|
3302
|
-
...options
|
|
3303
|
-
}) => {
|
|
3304
|
-
const module = getModule(method);
|
|
3305
|
-
// @ts-ignore
|
|
3306
|
-
const rawIpc = await module.create(options);
|
|
3307
|
-
if (options.noReturn) {
|
|
3308
|
-
return undefined;
|
|
3309
|
-
}
|
|
3310
|
-
if (options.raw) {
|
|
3311
|
-
return rawIpc;
|
|
3312
|
-
}
|
|
3313
|
-
const ipc = module.wrap(rawIpc);
|
|
3314
|
-
return ipc;
|
|
3315
|
-
};
|
|
3316
|
-
|
|
3317
|
-
const launchSearchProcess = async () => {
|
|
3318
|
-
const ipc = await create({
|
|
3319
|
-
method: NodeAlternate,
|
|
3320
|
-
type: 'search-process',
|
|
3321
|
-
name: 'Search Process',
|
|
3322
|
-
initialCommand: 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess'
|
|
3323
|
-
});
|
|
3324
|
-
// TODO
|
|
3325
|
-
// HandleIpc.handleIpc(ipc)
|
|
3326
|
-
return ipc;
|
|
3327
|
-
};
|
|
3328
|
-
|
|
3329
3201
|
const first = () => {
|
|
3330
3202
|
return 0;
|
|
3331
3203
|
};
|
|
@@ -4246,7 +4118,7 @@ const commandMap = {
|
|
|
4246
4118
|
'TextSearch.toggleUseIgnoreFiles': wrapCommand(toggleUseIgnoreFiles),
|
|
4247
4119
|
'TextSearch.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
|
|
4248
4120
|
// not wrapped
|
|
4249
|
-
'TextSearch.create': create
|
|
4121
|
+
'TextSearch.create': create,
|
|
4250
4122
|
'TextSearch.getFlags': getFlags,
|
|
4251
4123
|
'TextSearch.getFocus': getFocus,
|
|
4252
4124
|
'TextSearch.getKeyBindings': getKeyBindings,
|