@lvce-editor/text-search-worker 3.15.0 → 3.17.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 +308 -178
- package/package.json +1 -1
|
@@ -1,3 +1,112 @@
|
|
|
1
|
+
const normalizeLine$1 = line => {
|
|
2
|
+
if (line.startsWith('Error: ')) {
|
|
3
|
+
return line.slice('Error: '.length);
|
|
4
|
+
}
|
|
5
|
+
if (line.startsWith('VError: ')) {
|
|
6
|
+
return line.slice('VError: '.length);
|
|
7
|
+
}
|
|
8
|
+
return line;
|
|
9
|
+
};
|
|
10
|
+
const getCombinedMessage$1 = (error, message) => {
|
|
11
|
+
const stringifiedError = normalizeLine$1(`${error}`);
|
|
12
|
+
if (message) {
|
|
13
|
+
return `${message}: ${stringifiedError}`;
|
|
14
|
+
}
|
|
15
|
+
return stringifiedError;
|
|
16
|
+
};
|
|
17
|
+
const NewLine$3 = '\n';
|
|
18
|
+
const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
19
|
+
return string.indexOf(NewLine$3, startIndex);
|
|
20
|
+
};
|
|
21
|
+
const mergeStacks$1 = (parent, child) => {
|
|
22
|
+
if (!child) {
|
|
23
|
+
return parent;
|
|
24
|
+
}
|
|
25
|
+
const parentNewLineIndex = getNewLineIndex$2(parent);
|
|
26
|
+
const childNewLineIndex = getNewLineIndex$2(child);
|
|
27
|
+
if (childNewLineIndex === -1) {
|
|
28
|
+
return parent;
|
|
29
|
+
}
|
|
30
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
31
|
+
const childRest = child.slice(childNewLineIndex);
|
|
32
|
+
const childFirstLine = normalizeLine$1(child.slice(0, childNewLineIndex));
|
|
33
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
34
|
+
return parentFirstLine + childRest;
|
|
35
|
+
}
|
|
36
|
+
return child;
|
|
37
|
+
};
|
|
38
|
+
let VError$1 = class VError extends Error {
|
|
39
|
+
constructor(error, message) {
|
|
40
|
+
const combinedMessage = getCombinedMessage$1(error, message);
|
|
41
|
+
super(combinedMessage);
|
|
42
|
+
this.name = 'VError';
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
this.stack = mergeStacks$1(this.stack, error.stack);
|
|
45
|
+
}
|
|
46
|
+
if (error.codeFrame) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
this.codeFrame = error.codeFrame;
|
|
49
|
+
}
|
|
50
|
+
if (error.code) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
this.code = error.code;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
class AssertionError extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'AssertionError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const getType = value => {
|
|
64
|
+
switch (typeof value) {
|
|
65
|
+
case 'number':
|
|
66
|
+
return 'number';
|
|
67
|
+
case 'function':
|
|
68
|
+
return 'function';
|
|
69
|
+
case 'string':
|
|
70
|
+
return 'string';
|
|
71
|
+
case 'object':
|
|
72
|
+
if (value === null) {
|
|
73
|
+
return 'null';
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
return 'array';
|
|
77
|
+
}
|
|
78
|
+
return 'object';
|
|
79
|
+
case 'boolean':
|
|
80
|
+
return 'boolean';
|
|
81
|
+
default:
|
|
82
|
+
return 'unknown';
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const object = value => {
|
|
86
|
+
const type = getType(value);
|
|
87
|
+
if (type !== 'object') {
|
|
88
|
+
throw new AssertionError('expected value to be of type object');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const number = value => {
|
|
92
|
+
const type = getType(value);
|
|
93
|
+
if (type !== 'number') {
|
|
94
|
+
throw new AssertionError('expected value to be of type number');
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const array = value => {
|
|
98
|
+
const type = getType(value);
|
|
99
|
+
if (type !== 'array') {
|
|
100
|
+
throw new AssertionError('expected value to be of type array');
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const string = value => {
|
|
104
|
+
const type = getType(value);
|
|
105
|
+
if (type !== 'string') {
|
|
106
|
+
throw new AssertionError('expected value to be of type string');
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
1
110
|
const Two = '2.0';
|
|
2
111
|
const create$4 = (method, params) => {
|
|
3
112
|
return {
|
|
@@ -6,17 +115,17 @@ const create$4 = (method, params) => {
|
|
|
6
115
|
params
|
|
7
116
|
};
|
|
8
117
|
};
|
|
9
|
-
const state$
|
|
118
|
+
const state$4 = {
|
|
10
119
|
callbacks: Object.create(null)
|
|
11
120
|
};
|
|
12
121
|
const set$1 = (id, fn) => {
|
|
13
|
-
state$
|
|
122
|
+
state$4.callbacks[id] = fn;
|
|
14
123
|
};
|
|
15
124
|
const get$1 = id => {
|
|
16
|
-
return state$
|
|
125
|
+
return state$4.callbacks[id];
|
|
17
126
|
};
|
|
18
127
|
const remove$1 = id => {
|
|
19
|
-
delete state$
|
|
128
|
+
delete state$4.callbacks[id];
|
|
20
129
|
};
|
|
21
130
|
let id = 0;
|
|
22
131
|
const create$3$1 = () => {
|
|
@@ -47,7 +156,7 @@ const resolve = (id, response) => {
|
|
|
47
156
|
fn(response);
|
|
48
157
|
remove$1(id);
|
|
49
158
|
};
|
|
50
|
-
const create$2$
|
|
159
|
+
const create$2$2 = (method, params) => {
|
|
51
160
|
const {
|
|
52
161
|
id,
|
|
53
162
|
promise
|
|
@@ -69,7 +178,7 @@ class JsonRpcError extends Error {
|
|
|
69
178
|
this.name = 'JsonRpcError';
|
|
70
179
|
}
|
|
71
180
|
}
|
|
72
|
-
const NewLine$
|
|
181
|
+
const NewLine$2 = '\n';
|
|
73
182
|
const DomException = 'DOMException';
|
|
74
183
|
const ReferenceError$1 = 'ReferenceError';
|
|
75
184
|
const SyntaxError$1 = 'SyntaxError';
|
|
@@ -114,23 +223,23 @@ const constructError = (message, type, name) => {
|
|
|
114
223
|
}
|
|
115
224
|
return new ErrorConstructor(message);
|
|
116
225
|
};
|
|
117
|
-
const getNewLineIndex$
|
|
118
|
-
return string.indexOf(NewLine$
|
|
226
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
227
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
119
228
|
};
|
|
120
229
|
const getParentStack = error => {
|
|
121
230
|
let parentStack = error.stack || error.data || error.message || '';
|
|
122
231
|
if (parentStack.startsWith(' at')) {
|
|
123
|
-
parentStack = error.message + NewLine$
|
|
232
|
+
parentStack = error.message + NewLine$2 + parentStack;
|
|
124
233
|
}
|
|
125
234
|
return parentStack;
|
|
126
235
|
};
|
|
127
236
|
const joinLines$1 = lines => {
|
|
128
|
-
return lines.join(NewLine$
|
|
237
|
+
return lines.join(NewLine$2);
|
|
129
238
|
};
|
|
130
239
|
const MethodNotFound = -32601;
|
|
131
240
|
const Custom = -32001;
|
|
132
241
|
const splitLines$2 = lines => {
|
|
133
|
-
return lines.split(NewLine$
|
|
242
|
+
return lines.split(NewLine$2);
|
|
134
243
|
};
|
|
135
244
|
const restoreJsonRpcError = error => {
|
|
136
245
|
if (error && error instanceof Error) {
|
|
@@ -140,14 +249,14 @@ const restoreJsonRpcError = error => {
|
|
|
140
249
|
if (error && error.code && error.code === MethodNotFound) {
|
|
141
250
|
const restoredError = new JsonRpcError(error.message);
|
|
142
251
|
const parentStack = getParentStack(error);
|
|
143
|
-
restoredError.stack = parentStack + NewLine$
|
|
252
|
+
restoredError.stack = parentStack + NewLine$2 + currentStack;
|
|
144
253
|
return restoredError;
|
|
145
254
|
}
|
|
146
255
|
if (error && error.message) {
|
|
147
256
|
const restoredError = constructError(error.message, error.type, error.name);
|
|
148
257
|
if (error.data) {
|
|
149
258
|
if (error.data.stack && error.data.type && error.message) {
|
|
150
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine$
|
|
259
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine$2 + error.data.stack + NewLine$2 + currentStack;
|
|
151
260
|
} else if (error.data.stack) {
|
|
152
261
|
restoredError.stack = error.data.stack;
|
|
153
262
|
}
|
|
@@ -167,7 +276,7 @@ const restoreJsonRpcError = error => {
|
|
|
167
276
|
if (error.stack) {
|
|
168
277
|
const lowerStack = restoredError.stack || '';
|
|
169
278
|
// @ts-ignore
|
|
170
|
-
const indexNewLine = getNewLineIndex$
|
|
279
|
+
const indexNewLine = getNewLineIndex$1(lowerStack);
|
|
171
280
|
const parentStack = getParentStack(error);
|
|
172
281
|
// @ts-ignore
|
|
173
282
|
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
@@ -237,7 +346,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
237
346
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
238
347
|
return create$1$2(message, errorProperty);
|
|
239
348
|
};
|
|
240
|
-
const create$
|
|
349
|
+
const create$6 = (message, result) => {
|
|
241
350
|
return {
|
|
242
351
|
jsonrpc: Two,
|
|
243
352
|
id: message.id,
|
|
@@ -246,7 +355,7 @@ const create$5 = (message, result) => {
|
|
|
246
355
|
};
|
|
247
356
|
const getSuccessResponse = (message, result) => {
|
|
248
357
|
const resultProperty = result ?? null;
|
|
249
|
-
return create$
|
|
358
|
+
return create$6(message, resultProperty);
|
|
250
359
|
};
|
|
251
360
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
252
361
|
try {
|
|
@@ -326,7 +435,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
326
435
|
const {
|
|
327
436
|
message,
|
|
328
437
|
promise
|
|
329
|
-
} = create$2$
|
|
438
|
+
} = create$2$2(method, params);
|
|
330
439
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
331
440
|
ipc.sendAndTransfer(message);
|
|
332
441
|
} else {
|
|
@@ -339,10 +448,10 @@ const send = (transport, method, ...params) => {
|
|
|
339
448
|
const message = create$4(method, params);
|
|
340
449
|
transport.send(message);
|
|
341
450
|
};
|
|
342
|
-
const invoke$
|
|
451
|
+
const invoke$3 = (ipc, method, ...params) => {
|
|
343
452
|
return invokeHelper(ipc, method, params, false);
|
|
344
453
|
};
|
|
345
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
454
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
346
455
|
return invokeHelper(ipc, method, params, true);
|
|
347
456
|
};
|
|
348
457
|
|
|
@@ -584,7 +693,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
584
693
|
stack: rest
|
|
585
694
|
};
|
|
586
695
|
};
|
|
587
|
-
const normalizeLine
|
|
696
|
+
const normalizeLine = line => {
|
|
588
697
|
if (line.startsWith('Error: ')) {
|
|
589
698
|
return line.slice('Error: '.length);
|
|
590
699
|
}
|
|
@@ -593,41 +702,41 @@ const normalizeLine$1 = line => {
|
|
|
593
702
|
}
|
|
594
703
|
return line;
|
|
595
704
|
};
|
|
596
|
-
const getCombinedMessage
|
|
597
|
-
const stringifiedError = normalizeLine
|
|
705
|
+
const getCombinedMessage = (error, message) => {
|
|
706
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
598
707
|
if (message) {
|
|
599
708
|
return `${message}: ${stringifiedError}`;
|
|
600
709
|
}
|
|
601
710
|
return stringifiedError;
|
|
602
711
|
};
|
|
603
|
-
const NewLine
|
|
604
|
-
const getNewLineIndex
|
|
605
|
-
return string.indexOf(NewLine
|
|
712
|
+
const NewLine = '\n';
|
|
713
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
714
|
+
return string.indexOf(NewLine, startIndex);
|
|
606
715
|
};
|
|
607
|
-
const mergeStacks
|
|
716
|
+
const mergeStacks = (parent, child) => {
|
|
608
717
|
if (!child) {
|
|
609
718
|
return parent;
|
|
610
719
|
}
|
|
611
|
-
const parentNewLineIndex = getNewLineIndex
|
|
612
|
-
const childNewLineIndex = getNewLineIndex
|
|
720
|
+
const parentNewLineIndex = getNewLineIndex(parent);
|
|
721
|
+
const childNewLineIndex = getNewLineIndex(child);
|
|
613
722
|
if (childNewLineIndex === -1) {
|
|
614
723
|
return parent;
|
|
615
724
|
}
|
|
616
725
|
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
617
726
|
const childRest = child.slice(childNewLineIndex);
|
|
618
|
-
const childFirstLine = normalizeLine
|
|
727
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
619
728
|
if (parentFirstLine.includes(childFirstLine)) {
|
|
620
729
|
return parentFirstLine + childRest;
|
|
621
730
|
}
|
|
622
731
|
return child;
|
|
623
732
|
};
|
|
624
|
-
|
|
733
|
+
class VError extends Error {
|
|
625
734
|
constructor(error, message) {
|
|
626
|
-
const combinedMessage = getCombinedMessage
|
|
735
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
627
736
|
super(combinedMessage);
|
|
628
737
|
this.name = 'VError';
|
|
629
738
|
if (error instanceof Error) {
|
|
630
|
-
this.stack = mergeStacks
|
|
739
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
631
740
|
}
|
|
632
741
|
if (error.codeFrame) {
|
|
633
742
|
// @ts-ignore
|
|
@@ -638,8 +747,8 @@ let VError$1 = class VError extends Error {
|
|
|
638
747
|
this.code = error.code;
|
|
639
748
|
}
|
|
640
749
|
}
|
|
641
|
-
}
|
|
642
|
-
class IpcError extends VError
|
|
750
|
+
}
|
|
751
|
+
class IpcError extends VError {
|
|
643
752
|
// @ts-ignore
|
|
644
753
|
constructor(betterMessage, stdout = '', stderr = '') {
|
|
645
754
|
if (stdout || stderr) {
|
|
@@ -743,6 +852,7 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
743
852
|
listen: listen$1$1,
|
|
744
853
|
wrap: wrap$4
|
|
745
854
|
};
|
|
855
|
+
const Message$1 = 3;
|
|
746
856
|
const addListener = (emitter, type, callback) => {
|
|
747
857
|
if ('addEventListener' in emitter) {
|
|
748
858
|
emitter.addEventListener(type, callback);
|
|
@@ -781,6 +891,58 @@ const getFirstEvent = (eventEmitter, eventMap) => {
|
|
|
781
891
|
}
|
|
782
892
|
return promise;
|
|
783
893
|
};
|
|
894
|
+
const create$2$1 = async ({
|
|
895
|
+
messagePort,
|
|
896
|
+
isMessagePortOpen
|
|
897
|
+
}) => {
|
|
898
|
+
if (!isMessagePort(messagePort)) {
|
|
899
|
+
throw new IpcError('port must be of type MessagePort');
|
|
900
|
+
}
|
|
901
|
+
if (isMessagePortOpen) {
|
|
902
|
+
return messagePort;
|
|
903
|
+
}
|
|
904
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
905
|
+
message: Message$1
|
|
906
|
+
});
|
|
907
|
+
messagePort.start();
|
|
908
|
+
const event = await eventPromise;
|
|
909
|
+
// @ts-ignore
|
|
910
|
+
if (event.data !== readyMessage) {
|
|
911
|
+
throw new IpcError('unexpected first message');
|
|
912
|
+
}
|
|
913
|
+
return messagePort;
|
|
914
|
+
};
|
|
915
|
+
const signal = messagePort => {
|
|
916
|
+
messagePort.start();
|
|
917
|
+
};
|
|
918
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
919
|
+
constructor(port) {
|
|
920
|
+
super(port);
|
|
921
|
+
}
|
|
922
|
+
getData = getData$1;
|
|
923
|
+
send(message) {
|
|
924
|
+
this._rawIpc.postMessage(message);
|
|
925
|
+
}
|
|
926
|
+
sendAndTransfer(message) {
|
|
927
|
+
throw new Error('not implemented');
|
|
928
|
+
}
|
|
929
|
+
dispose() {
|
|
930
|
+
this._rawIpc.close();
|
|
931
|
+
}
|
|
932
|
+
onMessage(callback) {
|
|
933
|
+
this._rawIpc.addEventListener('message', callback);
|
|
934
|
+
}
|
|
935
|
+
onClose(callback) {}
|
|
936
|
+
}
|
|
937
|
+
const wrap$2 = messagePort => {
|
|
938
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
939
|
+
};
|
|
940
|
+
const IpcParentWithMessagePort$1 = {
|
|
941
|
+
__proto__: null,
|
|
942
|
+
create: create$2$1,
|
|
943
|
+
signal,
|
|
944
|
+
wrap: wrap$2
|
|
945
|
+
};
|
|
784
946
|
const Open = 1;
|
|
785
947
|
const Close = 2;
|
|
786
948
|
const stringifyCompact = value => {
|
|
@@ -793,7 +955,7 @@ const parse = content => {
|
|
|
793
955
|
try {
|
|
794
956
|
return JSON.parse(content);
|
|
795
957
|
} catch (error) {
|
|
796
|
-
throw new VError
|
|
958
|
+
throw new VError(error, 'failed to parse json');
|
|
797
959
|
}
|
|
798
960
|
};
|
|
799
961
|
const waitForWebSocketToBeOpen = webSocket => {
|
|
@@ -850,10 +1012,10 @@ const createRpc = ipc => {
|
|
|
850
1012
|
send(ipc, method, ...params);
|
|
851
1013
|
},
|
|
852
1014
|
invoke(method, ...params) {
|
|
853
|
-
return invoke$
|
|
1015
|
+
return invoke$3(ipc, method, ...params);
|
|
854
1016
|
},
|
|
855
1017
|
invokeAndTransfer(method, ...params) {
|
|
856
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
1018
|
+
return invokeAndTransfer$1(ipc, method, ...params);
|
|
857
1019
|
}
|
|
858
1020
|
};
|
|
859
1021
|
return rpc;
|
|
@@ -871,7 +1033,40 @@ const handleMessage = event => {
|
|
|
871
1033
|
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
|
|
872
1034
|
};
|
|
873
1035
|
const handleIpc = ipc => {
|
|
874
|
-
|
|
1036
|
+
if ('addEventListener' in ipc) {
|
|
1037
|
+
ipc.addEventListener('message', handleMessage);
|
|
1038
|
+
} else if ('on' in ipc) {
|
|
1039
|
+
// deprecated
|
|
1040
|
+
ipc.on('message', handleMessage);
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
const listen$1 = async (module, options) => {
|
|
1044
|
+
const rawIpc = await module.listen(options);
|
|
1045
|
+
if (module.signal) {
|
|
1046
|
+
module.signal(rawIpc);
|
|
1047
|
+
}
|
|
1048
|
+
const ipc = module.wrap(rawIpc);
|
|
1049
|
+
return ipc;
|
|
1050
|
+
};
|
|
1051
|
+
const create$5 = async ({
|
|
1052
|
+
commandMap,
|
|
1053
|
+
messagePort,
|
|
1054
|
+
isMessagePortOpen
|
|
1055
|
+
}) => {
|
|
1056
|
+
// TODO create a commandMap per rpc instance
|
|
1057
|
+
register(commandMap);
|
|
1058
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
1059
|
+
messagePort,
|
|
1060
|
+
isMessagePortOpen
|
|
1061
|
+
});
|
|
1062
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
1063
|
+
handleIpc(ipc);
|
|
1064
|
+
const rpc = createRpc(ipc);
|
|
1065
|
+
return rpc;
|
|
1066
|
+
};
|
|
1067
|
+
const MessagePortRpcParent = {
|
|
1068
|
+
__proto__: null,
|
|
1069
|
+
create: create$5
|
|
875
1070
|
};
|
|
876
1071
|
const create$1$1 = async ({
|
|
877
1072
|
commandMap,
|
|
@@ -891,20 +1086,12 @@ const WebSocketRpcParent = {
|
|
|
891
1086
|
__proto__: null,
|
|
892
1087
|
create: create$1$1
|
|
893
1088
|
};
|
|
894
|
-
|
|
895
|
-
// @ts-ignore
|
|
896
|
-
const listen$1 = async () => {
|
|
897
|
-
const module = IpcChildWithModuleWorkerAndMessagePort$1;
|
|
898
|
-
const rawIpc = await module.listen();
|
|
899
|
-
const ipc = module.wrap(rawIpc);
|
|
900
|
-
return ipc;
|
|
901
|
-
};
|
|
902
1089
|
const create$2 = async ({
|
|
903
1090
|
commandMap
|
|
904
1091
|
}) => {
|
|
905
1092
|
// TODO create a commandMap per rpc instance
|
|
906
1093
|
register(commandMap);
|
|
907
|
-
const ipc = await listen$1();
|
|
1094
|
+
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
908
1095
|
handleIpc(ipc);
|
|
909
1096
|
const rpc = createRpc(ipc);
|
|
910
1097
|
return rpc;
|
|
@@ -947,16 +1134,21 @@ const clearSearchResults$1 = state => {
|
|
|
947
1134
|
};
|
|
948
1135
|
};
|
|
949
1136
|
|
|
950
|
-
const state$
|
|
1137
|
+
const state$3 = {
|
|
951
1138
|
rpc: undefined
|
|
952
1139
|
};
|
|
953
|
-
const invoke$
|
|
954
|
-
const rpc = state$
|
|
1140
|
+
const invoke$2 = (method, ...params) => {
|
|
1141
|
+
const rpc = state$3.rpc;
|
|
955
1142
|
// @ts-ignore
|
|
956
1143
|
return rpc.invoke(method, ...params);
|
|
957
1144
|
};
|
|
1145
|
+
const invokeAndTransfer = (method, ...params) => {
|
|
1146
|
+
const rpc = state$3.rpc;
|
|
1147
|
+
// @ts-ignore
|
|
1148
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1149
|
+
};
|
|
958
1150
|
const setRpc = rpc => {
|
|
959
|
-
state$
|
|
1151
|
+
state$3.rpc = rpc;
|
|
960
1152
|
};
|
|
961
1153
|
|
|
962
1154
|
const copy = async state => {
|
|
@@ -968,7 +1160,7 @@ const copy = async state => {
|
|
|
968
1160
|
return state;
|
|
969
1161
|
}
|
|
970
1162
|
const item = items[listFocusedIndex];
|
|
971
|
-
await invoke$
|
|
1163
|
+
await invoke$2('ClipBoard.writeText', item.text);
|
|
972
1164
|
return state;
|
|
973
1165
|
};
|
|
974
1166
|
|
|
@@ -2249,7 +2441,7 @@ const getFileIcons = async files => {
|
|
|
2249
2441
|
if (file.type === Match) {
|
|
2250
2442
|
continue;
|
|
2251
2443
|
}
|
|
2252
|
-
promises.push(invoke$
|
|
2444
|
+
promises.push(invoke$2('IconTheme.getFileIcon', {
|
|
2253
2445
|
name: file.text
|
|
2254
2446
|
}));
|
|
2255
2447
|
}
|
|
@@ -2323,59 +2515,6 @@ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
|
|
|
2323
2515
|
};
|
|
2324
2516
|
};
|
|
2325
2517
|
|
|
2326
|
-
class AssertionError extends Error {
|
|
2327
|
-
constructor(message) {
|
|
2328
|
-
super(message);
|
|
2329
|
-
this.name = 'AssertionError';
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
const getType = value => {
|
|
2333
|
-
switch (typeof value) {
|
|
2334
|
-
case 'number':
|
|
2335
|
-
return 'number';
|
|
2336
|
-
case 'function':
|
|
2337
|
-
return 'function';
|
|
2338
|
-
case 'string':
|
|
2339
|
-
return 'string';
|
|
2340
|
-
case 'object':
|
|
2341
|
-
if (value === null) {
|
|
2342
|
-
return 'null';
|
|
2343
|
-
}
|
|
2344
|
-
if (Array.isArray(value)) {
|
|
2345
|
-
return 'array';
|
|
2346
|
-
}
|
|
2347
|
-
return 'object';
|
|
2348
|
-
case 'boolean':
|
|
2349
|
-
return 'boolean';
|
|
2350
|
-
default:
|
|
2351
|
-
return 'unknown';
|
|
2352
|
-
}
|
|
2353
|
-
};
|
|
2354
|
-
const object = value => {
|
|
2355
|
-
const type = getType(value);
|
|
2356
|
-
if (type !== 'object') {
|
|
2357
|
-
throw new AssertionError('expected value to be of type object');
|
|
2358
|
-
}
|
|
2359
|
-
};
|
|
2360
|
-
const number = value => {
|
|
2361
|
-
const type = getType(value);
|
|
2362
|
-
if (type !== 'number') {
|
|
2363
|
-
throw new AssertionError('expected value to be of type number');
|
|
2364
|
-
}
|
|
2365
|
-
};
|
|
2366
|
-
const array = value => {
|
|
2367
|
-
const type = getType(value);
|
|
2368
|
-
if (type !== 'array') {
|
|
2369
|
-
throw new AssertionError('expected value to be of type array');
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
const string = value => {
|
|
2373
|
-
const type = getType(value);
|
|
2374
|
-
if (type !== 'string') {
|
|
2375
|
-
throw new AssertionError('expected value to be of type string');
|
|
2376
|
-
}
|
|
2377
|
-
};
|
|
2378
|
-
|
|
2379
2518
|
const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
|
|
2380
2519
|
const getProtocol$1 = uri => {
|
|
2381
2520
|
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
@@ -2388,66 +2527,10 @@ const getProtocol$1 = uri => {
|
|
|
2388
2527
|
const textSearch$5 = async (scheme, root, query) => {
|
|
2389
2528
|
string(scheme);
|
|
2390
2529
|
string(query);
|
|
2391
|
-
const result = await invoke$
|
|
2530
|
+
const result = await invoke$2('ExtensionHostTextSearch.executeTextSearchProvider', scheme, query);
|
|
2392
2531
|
return result;
|
|
2393
2532
|
};
|
|
2394
2533
|
|
|
2395
|
-
const normalizeLine = line => {
|
|
2396
|
-
if (line.startsWith('Error: ')) {
|
|
2397
|
-
return line.slice('Error: '.length);
|
|
2398
|
-
}
|
|
2399
|
-
if (line.startsWith('VError: ')) {
|
|
2400
|
-
return line.slice('VError: '.length);
|
|
2401
|
-
}
|
|
2402
|
-
return line;
|
|
2403
|
-
};
|
|
2404
|
-
const getCombinedMessage = (error, message) => {
|
|
2405
|
-
const stringifiedError = normalizeLine(`${error}`);
|
|
2406
|
-
if (message) {
|
|
2407
|
-
return `${message}: ${stringifiedError}`;
|
|
2408
|
-
}
|
|
2409
|
-
return stringifiedError;
|
|
2410
|
-
};
|
|
2411
|
-
const NewLine = '\n';
|
|
2412
|
-
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
2413
|
-
return string.indexOf(NewLine, startIndex);
|
|
2414
|
-
};
|
|
2415
|
-
const mergeStacks = (parent, child) => {
|
|
2416
|
-
if (!child) {
|
|
2417
|
-
return parent;
|
|
2418
|
-
}
|
|
2419
|
-
const parentNewLineIndex = getNewLineIndex(parent);
|
|
2420
|
-
const childNewLineIndex = getNewLineIndex(child);
|
|
2421
|
-
if (childNewLineIndex === -1) {
|
|
2422
|
-
return parent;
|
|
2423
|
-
}
|
|
2424
|
-
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
2425
|
-
const childRest = child.slice(childNewLineIndex);
|
|
2426
|
-
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
2427
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
2428
|
-
return parentFirstLine + childRest;
|
|
2429
|
-
}
|
|
2430
|
-
return child;
|
|
2431
|
-
};
|
|
2432
|
-
class VError extends Error {
|
|
2433
|
-
constructor(error, message) {
|
|
2434
|
-
const combinedMessage = getCombinedMessage(error, message);
|
|
2435
|
-
super(combinedMessage);
|
|
2436
|
-
this.name = 'VError';
|
|
2437
|
-
if (error instanceof Error) {
|
|
2438
|
-
this.stack = mergeStacks(this.stack, error.stack);
|
|
2439
|
-
}
|
|
2440
|
-
if (error.codeFrame) {
|
|
2441
|
-
// @ts-ignore
|
|
2442
|
-
this.codeFrame = error.codeFrame;
|
|
2443
|
-
}
|
|
2444
|
-
if (error.code) {
|
|
2445
|
-
// @ts-ignore
|
|
2446
|
-
this.code = error.code;
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
|
|
2451
2534
|
const getJson = async url => {
|
|
2452
2535
|
try {
|
|
2453
2536
|
const response = await fetch(url);
|
|
@@ -2457,7 +2540,7 @@ const getJson = async url => {
|
|
|
2457
2540
|
const json = await response.json();
|
|
2458
2541
|
return json;
|
|
2459
2542
|
} catch (error) {
|
|
2460
|
-
throw new VError(error, `Failed to get json`);
|
|
2543
|
+
throw new VError$1(error, `Failed to get json`);
|
|
2461
2544
|
}
|
|
2462
2545
|
};
|
|
2463
2546
|
|
|
@@ -2470,7 +2553,7 @@ const getText = async url => {
|
|
|
2470
2553
|
const text = await response.text();
|
|
2471
2554
|
return text;
|
|
2472
2555
|
} catch (error) {
|
|
2473
|
-
throw new VError(error, `Failed to get text`);
|
|
2556
|
+
throw new VError$1(error, `Failed to get text`);
|
|
2474
2557
|
}
|
|
2475
2558
|
};
|
|
2476
2559
|
|
|
@@ -2546,7 +2629,7 @@ const getChildHandles = async handle => {
|
|
|
2546
2629
|
try {
|
|
2547
2630
|
return await getChildHandles$1(handle);
|
|
2548
2631
|
} catch (error) {
|
|
2549
|
-
throw new VError(error, 'failed to get child handles');
|
|
2632
|
+
throw new VError$1(error, 'failed to get child handles');
|
|
2550
2633
|
}
|
|
2551
2634
|
};
|
|
2552
2635
|
|
|
@@ -2812,7 +2895,7 @@ replaceTraps(oldTraps => ({
|
|
|
2812
2895
|
}
|
|
2813
2896
|
}));
|
|
2814
2897
|
|
|
2815
|
-
const state$
|
|
2898
|
+
const state$2 = {
|
|
2816
2899
|
databases: Object.create(null),
|
|
2817
2900
|
eventId: 0,
|
|
2818
2901
|
dbVersion: 1,
|
|
@@ -2823,7 +2906,7 @@ const state$1 = {
|
|
|
2823
2906
|
|
|
2824
2907
|
const getHandleDb = async () => {
|
|
2825
2908
|
// @ts-ignore
|
|
2826
|
-
const db = await openDB('handle', state$
|
|
2909
|
+
const db = await openDB('handle', state$2.dbVersion, {
|
|
2827
2910
|
async upgrade(db) {
|
|
2828
2911
|
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
2829
2912
|
await db.createObjectStore('file-handles-store', {});
|
|
@@ -2845,7 +2928,7 @@ const getHandle = async uri => {
|
|
|
2845
2928
|
const handle = await getHandle$1(uri);
|
|
2846
2929
|
return handle;
|
|
2847
2930
|
} catch (error) {
|
|
2848
|
-
throw new VError(error, 'Failed to get handle');
|
|
2931
|
+
throw new VError$1(error, 'Failed to get handle');
|
|
2849
2932
|
}
|
|
2850
2933
|
};
|
|
2851
2934
|
|
|
@@ -2941,6 +3024,7 @@ const getRipGrepArgs = ({
|
|
|
2941
3024
|
return ripGrepArgs;
|
|
2942
3025
|
};
|
|
2943
3026
|
|
|
3027
|
+
const Electron = 2;
|
|
2944
3028
|
const Remote = 3;
|
|
2945
3029
|
|
|
2946
3030
|
const Https = 'https:';
|
|
@@ -2975,13 +3059,56 @@ const launchSearchProcess = async () => {
|
|
|
2975
3059
|
return rpc;
|
|
2976
3060
|
};
|
|
2977
3061
|
|
|
3062
|
+
const state$1 = {
|
|
3063
|
+
rpc: undefined
|
|
3064
|
+
};
|
|
3065
|
+
const getOrCreate$1 = () => {
|
|
3066
|
+
if (!state$1.rpc) {
|
|
3067
|
+
// @ts-ignore
|
|
3068
|
+
state$1.rpc = launchSearchProcess();
|
|
3069
|
+
}
|
|
3070
|
+
return state$1.rpc;
|
|
3071
|
+
};
|
|
3072
|
+
|
|
3073
|
+
const invoke$1 = async (method, ...params) => {
|
|
3074
|
+
const rpc = await getOrCreate$1();
|
|
3075
|
+
return rpc.invoke(method, ...params);
|
|
3076
|
+
};
|
|
3077
|
+
|
|
3078
|
+
const getPortTuple = () => {
|
|
3079
|
+
const {
|
|
3080
|
+
port1,
|
|
3081
|
+
port2
|
|
3082
|
+
} = new MessageChannel();
|
|
3083
|
+
return {
|
|
3084
|
+
port1,
|
|
3085
|
+
port2
|
|
3086
|
+
};
|
|
3087
|
+
};
|
|
3088
|
+
|
|
3089
|
+
const launchSearchProcessElectron = async () => {
|
|
3090
|
+
const {
|
|
3091
|
+
port1,
|
|
3092
|
+
port2
|
|
3093
|
+
} = getPortTuple();
|
|
3094
|
+
const rpcPromise = MessagePortRpcParent.create({
|
|
3095
|
+
messagePort: port2,
|
|
3096
|
+
commandMap: {},
|
|
3097
|
+
isMessagePortOpen: true
|
|
3098
|
+
});
|
|
3099
|
+
await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port1, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
|
|
3100
|
+
port2.start();
|
|
3101
|
+
const rpc = await rpcPromise;
|
|
3102
|
+
return rpc;
|
|
3103
|
+
};
|
|
3104
|
+
|
|
2978
3105
|
const state = {
|
|
2979
3106
|
rpc: undefined
|
|
2980
3107
|
};
|
|
2981
3108
|
const getOrCreate = () => {
|
|
2982
3109
|
if (!state.rpc) {
|
|
2983
3110
|
// @ts-ignore
|
|
2984
|
-
state.rpc =
|
|
3111
|
+
state.rpc = launchSearchProcessElectron();
|
|
2985
3112
|
}
|
|
2986
3113
|
return state.rpc;
|
|
2987
3114
|
};
|
|
@@ -3001,11 +3128,15 @@ const textSearch$2 = async (scheme, root, query, options, assetDir, platform) =>
|
|
|
3001
3128
|
searchDir: root
|
|
3002
3129
|
};
|
|
3003
3130
|
if (platform === Remote) {
|
|
3004
|
-
const result = await invoke('TextSearch.search', actualOptions);
|
|
3131
|
+
const result = await invoke$1('TextSearch.search', actualOptions);
|
|
3005
3132
|
// TODO api is weird
|
|
3006
3133
|
return result.results;
|
|
3007
3134
|
}
|
|
3008
|
-
|
|
3135
|
+
if (platform === Electron) {
|
|
3136
|
+
const result = await invoke('TextSearch.search', actualOptions);
|
|
3137
|
+
return result.results;
|
|
3138
|
+
}
|
|
3139
|
+
const results = await invoke$2('SearchProcess.invoke', 'TextSearch.search', actualOptions);
|
|
3009
3140
|
// TODO api is weird
|
|
3010
3141
|
return results.results;
|
|
3011
3142
|
};
|
|
@@ -3398,7 +3529,7 @@ const selectIndexFile = (state, searchResult, index) => {
|
|
|
3398
3529
|
};
|
|
3399
3530
|
|
|
3400
3531
|
const openUri = async (path, focus = true, props = {}) => {
|
|
3401
|
-
await invoke$
|
|
3532
|
+
await invoke$2(/* Main.openUri */'Main.openUri', /* uri */path, /* focus */focus, props);
|
|
3402
3533
|
};
|
|
3403
3534
|
|
|
3404
3535
|
const getFileIndex = (items, index) => {
|
|
@@ -3421,7 +3552,6 @@ const selectIndexPreview = async (state, searchResult, index) => {
|
|
|
3421
3552
|
const {
|
|
3422
3553
|
lineNumber
|
|
3423
3554
|
} = searchResult;
|
|
3424
|
-
// console.log({ searchResult })
|
|
3425
3555
|
const fileResult = items[fileIndex];
|
|
3426
3556
|
const path = getAbsolutePath(fileResult.text);
|
|
3427
3557
|
string(path);
|
|
@@ -3790,7 +3920,7 @@ const replaceAll = async state => {
|
|
|
3790
3920
|
files,
|
|
3791
3921
|
ranges
|
|
3792
3922
|
} = getBulkReplacementEdits(workspacePath, items);
|
|
3793
|
-
await invoke$
|
|
3923
|
+
await invoke$2('BulkReplacement.applyBulkReplacement', files, ranges, replacement);
|
|
3794
3924
|
return state;
|
|
3795
3925
|
};
|
|
3796
3926
|
|
|
@@ -3822,7 +3952,7 @@ const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount
|
|
|
3822
3952
|
const confirmTitle = replaceAll$1();
|
|
3823
3953
|
const confirmAccept = replace();
|
|
3824
3954
|
const confirmText = getReplaceAllConfirmText(matchCount, fileCount, replacement);
|
|
3825
|
-
const shouldReplace = await invoke$
|
|
3955
|
+
const shouldReplace = await invoke$2('ConfirmPrompt.prompt', confirmText, {
|
|
3826
3956
|
title: confirmTitle,
|
|
3827
3957
|
confirmMessage: confirmAccept
|
|
3828
3958
|
});
|
|
@@ -3863,7 +3993,7 @@ const focusElement = (state, focusKey) => {
|
|
|
3863
3993
|
};
|
|
3864
3994
|
|
|
3865
3995
|
const setFocus = async focusKey => {
|
|
3866
|
-
await invoke$
|
|
3996
|
+
await invoke$2('Focus.setFocus', focusKey);
|
|
3867
3997
|
};
|
|
3868
3998
|
|
|
3869
3999
|
const getSearchFocusKey = key => {
|
|
@@ -4022,7 +4152,7 @@ const show = async (x, y, id, ...args) => {
|
|
|
4022
4152
|
number(y);
|
|
4023
4153
|
number(id);
|
|
4024
4154
|
// TODO
|
|
4025
|
-
await invoke$
|
|
4155
|
+
await invoke$2('ContextMenu.show', x, y, id, ...args);
|
|
4026
4156
|
};
|
|
4027
4157
|
|
|
4028
4158
|
const Search = 18;
|