@lvce-editor/text-search-worker 1.0.0 → 1.2.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 +482 -260
- package/package.json +1 -1
|
@@ -62,13 +62,483 @@ const getProtocol = uri => {
|
|
|
62
62
|
return '';
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
const state$3 = {
|
|
66
|
+
/**
|
|
67
|
+
* @type {any}
|
|
68
|
+
*/
|
|
69
|
+
ipc: undefined
|
|
70
|
+
};
|
|
71
|
+
const get$1 = () => {
|
|
72
|
+
return state$3.ipc;
|
|
73
|
+
};
|
|
74
|
+
const set$1 = ipc => {
|
|
75
|
+
state$3.ipc = ipc;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const Two = '2.0';
|
|
79
|
+
class AssertionError extends Error {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = 'AssertionError';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const getType$1 = value => {
|
|
86
|
+
switch (typeof value) {
|
|
87
|
+
case 'number':
|
|
88
|
+
return 'number';
|
|
89
|
+
case 'function':
|
|
90
|
+
return 'function';
|
|
91
|
+
case 'string':
|
|
92
|
+
return 'string';
|
|
93
|
+
case 'object':
|
|
94
|
+
if (value === null) {
|
|
95
|
+
return 'null';
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(value)) {
|
|
98
|
+
return 'array';
|
|
99
|
+
}
|
|
100
|
+
return 'object';
|
|
101
|
+
case 'boolean':
|
|
102
|
+
return 'boolean';
|
|
103
|
+
default:
|
|
104
|
+
return 'unknown';
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const number = value => {
|
|
108
|
+
const type = getType$1(value);
|
|
109
|
+
if (type !== 'number') {
|
|
110
|
+
throw new AssertionError('expected value to be of type number');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const state$1 = {
|
|
114
|
+
callbacks: Object.create(null)
|
|
115
|
+
};
|
|
116
|
+
const set = (id, fn) => {
|
|
117
|
+
state$1.callbacks[id] = fn;
|
|
118
|
+
};
|
|
119
|
+
const get = id => {
|
|
120
|
+
return state$1.callbacks[id];
|
|
121
|
+
};
|
|
122
|
+
const remove = id => {
|
|
123
|
+
delete state$1.callbacks[id];
|
|
124
|
+
};
|
|
125
|
+
const state$2 = {
|
|
126
|
+
id: 0
|
|
127
|
+
};
|
|
128
|
+
const create$3 = () => {
|
|
129
|
+
return ++state$2.id;
|
|
130
|
+
};
|
|
131
|
+
const warn = (...args) => {
|
|
132
|
+
console.warn(...args);
|
|
133
|
+
};
|
|
134
|
+
const withResolvers$1 = () => {
|
|
135
|
+
/**
|
|
136
|
+
* @type {any}
|
|
137
|
+
*/
|
|
138
|
+
let _resolve;
|
|
139
|
+
const promise = new Promise(resolve => {
|
|
140
|
+
_resolve = resolve;
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
resolve: _resolve,
|
|
144
|
+
promise
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const registerPromise = () => {
|
|
148
|
+
const id = create$3();
|
|
149
|
+
const {
|
|
150
|
+
resolve,
|
|
151
|
+
promise
|
|
152
|
+
} = withResolvers$1();
|
|
153
|
+
set(id, resolve);
|
|
154
|
+
return {
|
|
155
|
+
id,
|
|
156
|
+
promise
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
const resolve = (id, args) => {
|
|
160
|
+
number(id);
|
|
161
|
+
const fn = get(id);
|
|
162
|
+
if (!fn) {
|
|
163
|
+
console.log(args);
|
|
164
|
+
warn(`callback ${id} may already be disposed`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
fn(args);
|
|
168
|
+
remove(id);
|
|
169
|
+
};
|
|
170
|
+
const create$2 = (method, params) => {
|
|
171
|
+
const {
|
|
172
|
+
id,
|
|
173
|
+
promise
|
|
174
|
+
} = registerPromise();
|
|
175
|
+
const message = {
|
|
176
|
+
jsonrpc: Two,
|
|
177
|
+
method,
|
|
178
|
+
params,
|
|
179
|
+
id
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
message,
|
|
183
|
+
promise
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
class JsonRpcError extends Error {
|
|
187
|
+
constructor(message) {
|
|
188
|
+
super(message);
|
|
189
|
+
this.name = 'JsonRpcError';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const NewLine$3 = '\n';
|
|
193
|
+
const DomException = 'DOMException';
|
|
194
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
195
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
196
|
+
const TypeError$1 = 'TypeError';
|
|
197
|
+
const getErrorConstructor = (message, type) => {
|
|
198
|
+
if (type) {
|
|
199
|
+
switch (type) {
|
|
200
|
+
case DomException:
|
|
201
|
+
return DOMException;
|
|
202
|
+
case TypeError$1:
|
|
203
|
+
return TypeError;
|
|
204
|
+
case SyntaxError$1:
|
|
205
|
+
return SyntaxError;
|
|
206
|
+
case ReferenceError$1:
|
|
207
|
+
return ReferenceError;
|
|
208
|
+
default:
|
|
209
|
+
return Error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (message.startsWith('TypeError: ')) {
|
|
213
|
+
return TypeError;
|
|
214
|
+
}
|
|
215
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
216
|
+
return SyntaxError;
|
|
217
|
+
}
|
|
218
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
219
|
+
return ReferenceError;
|
|
220
|
+
}
|
|
221
|
+
return Error;
|
|
222
|
+
};
|
|
223
|
+
const constructError = (message, type, name) => {
|
|
224
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
225
|
+
if (ErrorConstructor === DOMException && name) {
|
|
226
|
+
return new ErrorConstructor(message, name);
|
|
227
|
+
}
|
|
228
|
+
if (ErrorConstructor === Error) {
|
|
229
|
+
const error = new Error(message);
|
|
230
|
+
if (name && name !== 'VError') {
|
|
231
|
+
error.name = name;
|
|
232
|
+
}
|
|
233
|
+
return error;
|
|
234
|
+
}
|
|
235
|
+
return new ErrorConstructor(message);
|
|
236
|
+
};
|
|
237
|
+
const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
238
|
+
return string.indexOf(NewLine$3, startIndex);
|
|
239
|
+
};
|
|
240
|
+
const getParentStack = error => {
|
|
241
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
242
|
+
if (parentStack.startsWith(' at')) {
|
|
243
|
+
parentStack = error.message + NewLine$3 + parentStack;
|
|
244
|
+
}
|
|
245
|
+
return parentStack;
|
|
246
|
+
};
|
|
247
|
+
const joinLines$1 = lines => {
|
|
248
|
+
return lines.join(NewLine$3);
|
|
249
|
+
};
|
|
250
|
+
const MethodNotFound = -32601;
|
|
251
|
+
const Custom = -32001;
|
|
252
|
+
const splitLines$2 = lines => {
|
|
253
|
+
return lines.split(NewLine$3);
|
|
254
|
+
};
|
|
255
|
+
const restoreJsonRpcError = error => {
|
|
256
|
+
if (error && error instanceof Error) {
|
|
257
|
+
return error;
|
|
258
|
+
}
|
|
259
|
+
const currentStack = joinLines$1(splitLines$2(new Error().stack || '').slice(1));
|
|
260
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
261
|
+
const restoredError = new JsonRpcError(error.message);
|
|
262
|
+
const parentStack = getParentStack(error);
|
|
263
|
+
restoredError.stack = parentStack + NewLine$3 + currentStack;
|
|
264
|
+
return restoredError;
|
|
265
|
+
}
|
|
266
|
+
if (error && error.message) {
|
|
267
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
268
|
+
if (error.data) {
|
|
269
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
270
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine$3 + error.data.stack + NewLine$3 + currentStack;
|
|
271
|
+
} else if (error.data.stack) {
|
|
272
|
+
restoredError.stack = error.data.stack;
|
|
273
|
+
}
|
|
274
|
+
if (error.data.codeFrame) {
|
|
275
|
+
// @ts-ignore
|
|
276
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
277
|
+
}
|
|
278
|
+
if (error.data.code) {
|
|
279
|
+
// @ts-ignore
|
|
280
|
+
restoredError.code = error.data.code;
|
|
281
|
+
}
|
|
282
|
+
if (error.data.type) {
|
|
283
|
+
// @ts-ignore
|
|
284
|
+
restoredError.name = error.data.type;
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
if (error.stack) {
|
|
288
|
+
const lowerStack = restoredError.stack || '';
|
|
289
|
+
// @ts-ignore
|
|
290
|
+
const indexNewLine = getNewLineIndex$2(lowerStack);
|
|
291
|
+
const parentStack = getParentStack(error);
|
|
292
|
+
// @ts-ignore
|
|
293
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
294
|
+
}
|
|
295
|
+
if (error.codeFrame) {
|
|
296
|
+
// @ts-ignore
|
|
297
|
+
restoredError.codeFrame = error.codeFrame;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return restoredError;
|
|
301
|
+
}
|
|
302
|
+
if (typeof error === 'string') {
|
|
303
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
304
|
+
}
|
|
305
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
306
|
+
};
|
|
307
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
308
|
+
if ('error' in responseMessage) {
|
|
309
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
310
|
+
throw restoredError;
|
|
311
|
+
}
|
|
312
|
+
if ('result' in responseMessage) {
|
|
313
|
+
return responseMessage.result;
|
|
314
|
+
}
|
|
315
|
+
throw new JsonRpcError('unexpected response message');
|
|
316
|
+
};
|
|
317
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
318
|
+
const getType = prettyError => {
|
|
319
|
+
if (prettyError && prettyError.type) {
|
|
320
|
+
return prettyError.type;
|
|
321
|
+
}
|
|
322
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
323
|
+
return prettyError.constructor.name;
|
|
324
|
+
}
|
|
325
|
+
return undefined;
|
|
326
|
+
};
|
|
327
|
+
const getErrorProperty = (error, prettyError) => {
|
|
328
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
329
|
+
return {
|
|
330
|
+
code: MethodNotFound,
|
|
331
|
+
message: error.message,
|
|
332
|
+
data: error.stack
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
code: Custom,
|
|
337
|
+
message: prettyError.message,
|
|
338
|
+
data: {
|
|
339
|
+
stack: prettyError.stack,
|
|
340
|
+
codeFrame: prettyError.codeFrame,
|
|
341
|
+
type: getType(prettyError),
|
|
342
|
+
code: prettyError.code,
|
|
343
|
+
name: prettyError.name
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
const create$1 = (message, error) => {
|
|
348
|
+
return {
|
|
349
|
+
jsonrpc: Two,
|
|
350
|
+
id: message.id,
|
|
351
|
+
error
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
355
|
+
const prettyError = preparePrettyError(error);
|
|
356
|
+
logError(error, prettyError);
|
|
357
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
358
|
+
return create$1(message, errorProperty);
|
|
359
|
+
};
|
|
360
|
+
const create = (message, result) => {
|
|
361
|
+
return {
|
|
362
|
+
jsonrpc: Two,
|
|
363
|
+
id: message.id,
|
|
364
|
+
result: result ?? null
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
const getSuccessResponse = (message, result) => {
|
|
368
|
+
const resultProperty = result ?? null;
|
|
369
|
+
return create(message, resultProperty);
|
|
370
|
+
};
|
|
371
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
372
|
+
try {
|
|
373
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
374
|
+
return getSuccessResponse(message, result);
|
|
375
|
+
} catch (error) {
|
|
376
|
+
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const defaultPreparePrettyError = error => {
|
|
380
|
+
return error;
|
|
381
|
+
};
|
|
382
|
+
const defaultLogError = () => {
|
|
383
|
+
// ignore
|
|
384
|
+
};
|
|
385
|
+
const defaultRequiresSocket = () => {
|
|
386
|
+
return false;
|
|
387
|
+
};
|
|
388
|
+
const defaultResolve = resolve;
|
|
389
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
390
|
+
let message;
|
|
391
|
+
let ipc;
|
|
392
|
+
let execute;
|
|
393
|
+
let preparePrettyError;
|
|
394
|
+
let logError;
|
|
395
|
+
let resolve;
|
|
396
|
+
let requiresSocket;
|
|
397
|
+
if (args.length === 1) {
|
|
398
|
+
const arg = args[0];
|
|
399
|
+
message = arg.message;
|
|
400
|
+
ipc = arg.ipc;
|
|
401
|
+
execute = arg.execute;
|
|
402
|
+
preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
|
|
403
|
+
logError = arg.logError || defaultLogError;
|
|
404
|
+
requiresSocket = arg.requiresSocket || defaultRequiresSocket;
|
|
405
|
+
resolve = arg.resolve || defaultResolve;
|
|
406
|
+
} else {
|
|
407
|
+
ipc = args[0];
|
|
408
|
+
message = args[1];
|
|
409
|
+
execute = args[2];
|
|
410
|
+
resolve = args[3];
|
|
411
|
+
preparePrettyError = args[4];
|
|
412
|
+
logError = args[5];
|
|
413
|
+
requiresSocket = args[6];
|
|
414
|
+
}
|
|
415
|
+
if ('id' in message) {
|
|
416
|
+
if ('method' in message) {
|
|
417
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
418
|
+
try {
|
|
419
|
+
ipc.send(response);
|
|
420
|
+
} catch (error) {
|
|
421
|
+
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
422
|
+
ipc.send(errorResponse);
|
|
423
|
+
}
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
resolve(message.id, message);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if ('method' in message) {
|
|
430
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
throw new JsonRpcError('unexpected message');
|
|
434
|
+
};
|
|
435
|
+
const invoke$2 = async (ipc, method, ...params) => {
|
|
436
|
+
const {
|
|
437
|
+
message,
|
|
438
|
+
promise
|
|
439
|
+
} = create$2(method, params);
|
|
440
|
+
ipc.send(message);
|
|
441
|
+
const responseMessage = await promise;
|
|
442
|
+
const result = unwrapJsonRpcResult(responseMessage);
|
|
443
|
+
return result;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const invoke$1 = (method, ...params) => {
|
|
447
|
+
const ipc = get$1();
|
|
448
|
+
return invoke$2(ipc, method, ...params);
|
|
449
|
+
};
|
|
450
|
+
const listen$2 = ipc => {
|
|
451
|
+
set$1(ipc);
|
|
452
|
+
};
|
|
453
|
+
|
|
65
454
|
const textSearch$5 = async (scheme, root, query) => {
|
|
66
455
|
string(scheme);
|
|
67
456
|
string(query);
|
|
68
|
-
|
|
457
|
+
const result = await invoke$1('ExtensionHostTextSearch.executeTextSearchProvider', scheme, query);
|
|
458
|
+
return result;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const normalizeLine$1 = line => {
|
|
462
|
+
if (line.startsWith('Error: ')) {
|
|
463
|
+
return line.slice(`Error: `.length);
|
|
464
|
+
}
|
|
465
|
+
if (line.startsWith('VError: ')) {
|
|
466
|
+
return line.slice(`VError: `.length);
|
|
467
|
+
}
|
|
468
|
+
return line;
|
|
469
|
+
};
|
|
470
|
+
const getCombinedMessage$1 = (error, message) => {
|
|
471
|
+
const stringifiedError = normalizeLine$1(`${error}`);
|
|
472
|
+
if (message) {
|
|
473
|
+
return `${message}: ${stringifiedError}`;
|
|
474
|
+
}
|
|
475
|
+
return stringifiedError;
|
|
476
|
+
};
|
|
477
|
+
const NewLine$2 = '\n';
|
|
478
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
479
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
480
|
+
};
|
|
481
|
+
const mergeStacks$1 = (parent, child) => {
|
|
482
|
+
if (!child) {
|
|
483
|
+
return parent;
|
|
484
|
+
}
|
|
485
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
486
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
487
|
+
if (childNewLineIndex === -1) {
|
|
488
|
+
return parent;
|
|
489
|
+
}
|
|
490
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
491
|
+
const childRest = child.slice(childNewLineIndex);
|
|
492
|
+
const childFirstLine = normalizeLine$1(child.slice(0, childNewLineIndex));
|
|
493
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
494
|
+
return parentFirstLine + childRest;
|
|
495
|
+
}
|
|
496
|
+
return child;
|
|
497
|
+
};
|
|
498
|
+
let VError$1 = class VError extends Error {
|
|
499
|
+
constructor(error, message) {
|
|
500
|
+
const combinedMessage = getCombinedMessage$1(error, message);
|
|
501
|
+
super(combinedMessage);
|
|
502
|
+
this.name = 'VError';
|
|
503
|
+
if (error instanceof Error) {
|
|
504
|
+
this.stack = mergeStacks$1(this.stack, error.stack);
|
|
505
|
+
}
|
|
506
|
+
if (error.codeFrame) {
|
|
507
|
+
// @ts-ignore
|
|
508
|
+
this.codeFrame = error.codeFrame;
|
|
509
|
+
}
|
|
510
|
+
if (error.code) {
|
|
511
|
+
// @ts-ignore
|
|
512
|
+
this.code = error.code;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
const getJson = async url => {
|
|
518
|
+
try {
|
|
519
|
+
const response = await fetch(url);
|
|
520
|
+
if (!response.ok) {
|
|
521
|
+
throw new Error(response.statusText);
|
|
522
|
+
}
|
|
523
|
+
const json = await response.json();
|
|
524
|
+
return json;
|
|
525
|
+
} catch (error) {
|
|
526
|
+
throw new VError$1(error, `Failed to get json`);
|
|
527
|
+
}
|
|
69
528
|
};
|
|
70
529
|
|
|
71
|
-
const
|
|
530
|
+
const getText = async url => {
|
|
531
|
+
try {
|
|
532
|
+
const response = await fetch(url);
|
|
533
|
+
if (!response.ok) {
|
|
534
|
+
throw new Error(response.statusText);
|
|
535
|
+
}
|
|
536
|
+
const text = await response.text();
|
|
537
|
+
return text;
|
|
538
|
+
} catch (error) {
|
|
539
|
+
throw new VError$1(error, `Failed to get text`);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
72
542
|
|
|
73
543
|
const splitLines$1 = lines => {
|
|
74
544
|
return lines.split('\n');
|
|
@@ -104,17 +574,17 @@ const textSearchInFile$1 = (file, content, query) => {
|
|
|
104
574
|
}
|
|
105
575
|
return results;
|
|
106
576
|
};
|
|
107
|
-
const textSearch$4 = async (scheme, root, query, options) => {
|
|
577
|
+
const textSearch$4 = async (scheme, root, query, options, assetDir) => {
|
|
108
578
|
string(scheme);
|
|
109
579
|
string(root);
|
|
110
580
|
string(query);
|
|
111
581
|
const fetchUri = `${assetDir}/config/fileMap.json`;
|
|
112
|
-
const fileList = await
|
|
582
|
+
const fileList = await getJson(fetchUri);
|
|
113
583
|
const allResults = [];
|
|
114
584
|
const relativeRoot = root.slice('fetch://'.length);
|
|
115
585
|
for (const uri of fileList) {
|
|
116
586
|
const fetchUri = `${assetDir}${uri}`;
|
|
117
|
-
const content = await
|
|
587
|
+
const content = await getText(fetchUri);
|
|
118
588
|
const relativeUri = uri.slice(relativeRoot.length + 1);
|
|
119
589
|
const results = textSearchInFile$1(relativeUri, content, query);
|
|
120
590
|
allResults.push(...results);
|
|
@@ -420,62 +890,6 @@ replaceTraps(oldTraps => ({
|
|
|
420
890
|
}
|
|
421
891
|
}));
|
|
422
892
|
|
|
423
|
-
const normalizeLine$1 = line => {
|
|
424
|
-
if (line.startsWith('Error: ')) {
|
|
425
|
-
return line.slice(`Error: `.length);
|
|
426
|
-
}
|
|
427
|
-
if (line.startsWith('VError: ')) {
|
|
428
|
-
return line.slice(`VError: `.length);
|
|
429
|
-
}
|
|
430
|
-
return line;
|
|
431
|
-
};
|
|
432
|
-
const getCombinedMessage$1 = (error, message) => {
|
|
433
|
-
const stringifiedError = normalizeLine$1(`${error}`);
|
|
434
|
-
if (message) {
|
|
435
|
-
return `${message}: ${stringifiedError}`;
|
|
436
|
-
}
|
|
437
|
-
return stringifiedError;
|
|
438
|
-
};
|
|
439
|
-
const NewLine$2 = '\n';
|
|
440
|
-
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
441
|
-
return string.indexOf(NewLine$2, startIndex);
|
|
442
|
-
};
|
|
443
|
-
const mergeStacks$1 = (parent, child) => {
|
|
444
|
-
if (!child) {
|
|
445
|
-
return parent;
|
|
446
|
-
}
|
|
447
|
-
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
448
|
-
const childNewLineIndex = getNewLineIndex$1(child);
|
|
449
|
-
if (childNewLineIndex === -1) {
|
|
450
|
-
return parent;
|
|
451
|
-
}
|
|
452
|
-
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
453
|
-
const childRest = child.slice(childNewLineIndex);
|
|
454
|
-
const childFirstLine = normalizeLine$1(child.slice(0, childNewLineIndex));
|
|
455
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
456
|
-
return parentFirstLine + childRest;
|
|
457
|
-
}
|
|
458
|
-
return child;
|
|
459
|
-
};
|
|
460
|
-
let VError$1 = class VError extends Error {
|
|
461
|
-
constructor(error, message) {
|
|
462
|
-
const combinedMessage = getCombinedMessage$1(error, message);
|
|
463
|
-
super(combinedMessage);
|
|
464
|
-
this.name = 'VError';
|
|
465
|
-
if (error instanceof Error) {
|
|
466
|
-
this.stack = mergeStacks$1(this.stack, error.stack);
|
|
467
|
-
}
|
|
468
|
-
if (error.codeFrame) {
|
|
469
|
-
// @ts-ignore
|
|
470
|
-
this.codeFrame = error.codeFrame;
|
|
471
|
-
}
|
|
472
|
-
if (error.code) {
|
|
473
|
-
// @ts-ignore
|
|
474
|
-
this.code = error.code;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
|
|
479
893
|
const state = {
|
|
480
894
|
databases: Object.create(null),
|
|
481
895
|
eventId: 0,
|
|
@@ -623,17 +1037,10 @@ const getRipGrepArgs = ({
|
|
|
623
1037
|
return ripGrepArgs;
|
|
624
1038
|
};
|
|
625
1039
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
const SearchProcess = {
|
|
630
|
-
// TODO connect to search process
|
|
631
|
-
invoke() {
|
|
632
|
-
return {
|
|
633
|
-
results: []
|
|
634
|
-
};
|
|
635
|
-
}
|
|
1040
|
+
const invoke = (method, ...params) => {
|
|
1041
|
+
return invoke$1('SearchProcess.invoke', method, ...params);
|
|
636
1042
|
};
|
|
1043
|
+
|
|
637
1044
|
const textSearch$2 = async (scheme, root, query, options) => {
|
|
638
1045
|
const ripGrepArgs = getRipGrepArgs({
|
|
639
1046
|
...options,
|
|
@@ -643,8 +1050,7 @@ const textSearch$2 = async (scheme, root, query, options) => {
|
|
|
643
1050
|
ripGrepArgs,
|
|
644
1051
|
searchDir: root
|
|
645
1052
|
};
|
|
646
|
-
|
|
647
|
-
const result = await SearchProcess.invoke(SharedProcessCommandType.TextSearchSearch, actualOptions);
|
|
1053
|
+
const result = await invoke('TextSearch.search', actualOptions);
|
|
648
1054
|
// TODO api is weird
|
|
649
1055
|
return result.results;
|
|
650
1056
|
};
|
|
@@ -680,12 +1086,12 @@ const getProvider = scheme => {
|
|
|
680
1086
|
}
|
|
681
1087
|
};
|
|
682
1088
|
|
|
683
|
-
const textSearch = async (root, query, options) => {
|
|
1089
|
+
const textSearch = async (root, query, options, assetDir) => {
|
|
684
1090
|
string(root);
|
|
685
1091
|
string(query);
|
|
686
1092
|
const scheme = getProtocol(root);
|
|
687
1093
|
const provider = getProvider(scheme);
|
|
688
|
-
const results = await provider(scheme, root, query, options);
|
|
1094
|
+
const results = await provider(scheme, root, query, options, assetDir);
|
|
689
1095
|
return results;
|
|
690
1096
|
};
|
|
691
1097
|
|
|
@@ -693,191 +1099,6 @@ const commandMap = {
|
|
|
693
1099
|
'TextSearch.textSearch': textSearch
|
|
694
1100
|
};
|
|
695
1101
|
|
|
696
|
-
const Two = '2.0';
|
|
697
|
-
class AssertionError extends Error {
|
|
698
|
-
constructor(message) {
|
|
699
|
-
super(message);
|
|
700
|
-
this.name = 'AssertionError';
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
const getType$1 = value => {
|
|
704
|
-
switch (typeof value) {
|
|
705
|
-
case 'number':
|
|
706
|
-
return 'number';
|
|
707
|
-
case 'function':
|
|
708
|
-
return 'function';
|
|
709
|
-
case 'string':
|
|
710
|
-
return 'string';
|
|
711
|
-
case 'object':
|
|
712
|
-
if (value === null) {
|
|
713
|
-
return 'null';
|
|
714
|
-
}
|
|
715
|
-
if (Array.isArray(value)) {
|
|
716
|
-
return 'array';
|
|
717
|
-
}
|
|
718
|
-
return 'object';
|
|
719
|
-
case 'boolean':
|
|
720
|
-
return 'boolean';
|
|
721
|
-
default:
|
|
722
|
-
return 'unknown';
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
const number = value => {
|
|
726
|
-
const type = getType$1(value);
|
|
727
|
-
if (type !== 'number') {
|
|
728
|
-
throw new AssertionError('expected value to be of type number');
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
const state$1 = {
|
|
732
|
-
callbacks: Object.create(null)
|
|
733
|
-
};
|
|
734
|
-
const get = id => {
|
|
735
|
-
return state$1.callbacks[id];
|
|
736
|
-
};
|
|
737
|
-
const remove = id => {
|
|
738
|
-
delete state$1.callbacks[id];
|
|
739
|
-
};
|
|
740
|
-
const warn = (...args) => {
|
|
741
|
-
console.warn(...args);
|
|
742
|
-
};
|
|
743
|
-
const resolve = (id, args) => {
|
|
744
|
-
number(id);
|
|
745
|
-
const fn = get(id);
|
|
746
|
-
if (!fn) {
|
|
747
|
-
console.log(args);
|
|
748
|
-
warn(`callback ${id} may already be disposed`);
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
fn(args);
|
|
752
|
-
remove(id);
|
|
753
|
-
};
|
|
754
|
-
class JsonRpcError extends Error {
|
|
755
|
-
constructor(message) {
|
|
756
|
-
super(message);
|
|
757
|
-
this.name = 'JsonRpcError';
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
const MethodNotFound = -32601;
|
|
761
|
-
const Custom = -32001;
|
|
762
|
-
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
763
|
-
const getType = prettyError => {
|
|
764
|
-
if (prettyError && prettyError.type) {
|
|
765
|
-
return prettyError.type;
|
|
766
|
-
}
|
|
767
|
-
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
768
|
-
return prettyError.constructor.name;
|
|
769
|
-
}
|
|
770
|
-
return undefined;
|
|
771
|
-
};
|
|
772
|
-
const getErrorProperty = (error, prettyError) => {
|
|
773
|
-
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
774
|
-
return {
|
|
775
|
-
code: MethodNotFound,
|
|
776
|
-
message: error.message,
|
|
777
|
-
data: error.stack
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
return {
|
|
781
|
-
code: Custom,
|
|
782
|
-
message: prettyError.message,
|
|
783
|
-
data: {
|
|
784
|
-
stack: prettyError.stack,
|
|
785
|
-
codeFrame: prettyError.codeFrame,
|
|
786
|
-
type: getType(prettyError),
|
|
787
|
-
code: prettyError.code,
|
|
788
|
-
name: prettyError.name
|
|
789
|
-
}
|
|
790
|
-
};
|
|
791
|
-
};
|
|
792
|
-
const create$1 = (message, error) => {
|
|
793
|
-
return {
|
|
794
|
-
jsonrpc: Two,
|
|
795
|
-
id: message.id,
|
|
796
|
-
error
|
|
797
|
-
};
|
|
798
|
-
};
|
|
799
|
-
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
800
|
-
const prettyError = preparePrettyError(error);
|
|
801
|
-
logError(error, prettyError);
|
|
802
|
-
const errorProperty = getErrorProperty(error, prettyError);
|
|
803
|
-
return create$1(message, errorProperty);
|
|
804
|
-
};
|
|
805
|
-
const create = (message, result) => {
|
|
806
|
-
return {
|
|
807
|
-
jsonrpc: Two,
|
|
808
|
-
id: message.id,
|
|
809
|
-
result: result ?? null
|
|
810
|
-
};
|
|
811
|
-
};
|
|
812
|
-
const getSuccessResponse = (message, result) => {
|
|
813
|
-
const resultProperty = result ?? null;
|
|
814
|
-
return create(message, resultProperty);
|
|
815
|
-
};
|
|
816
|
-
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
817
|
-
try {
|
|
818
|
-
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
819
|
-
return getSuccessResponse(message, result);
|
|
820
|
-
} catch (error) {
|
|
821
|
-
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
822
|
-
}
|
|
823
|
-
};
|
|
824
|
-
const defaultPreparePrettyError = error => {
|
|
825
|
-
return error;
|
|
826
|
-
};
|
|
827
|
-
const defaultLogError = () => {
|
|
828
|
-
// ignore
|
|
829
|
-
};
|
|
830
|
-
const defaultRequiresSocket = () => {
|
|
831
|
-
return false;
|
|
832
|
-
};
|
|
833
|
-
const defaultResolve = resolve;
|
|
834
|
-
const handleJsonRpcMessage = async (...args) => {
|
|
835
|
-
let message;
|
|
836
|
-
let ipc;
|
|
837
|
-
let execute;
|
|
838
|
-
let preparePrettyError;
|
|
839
|
-
let logError;
|
|
840
|
-
let resolve;
|
|
841
|
-
let requiresSocket;
|
|
842
|
-
if (args.length === 1) {
|
|
843
|
-
const arg = args[0];
|
|
844
|
-
message = arg.message;
|
|
845
|
-
ipc = arg.ipc;
|
|
846
|
-
execute = arg.execute;
|
|
847
|
-
preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
|
|
848
|
-
logError = arg.logError || defaultLogError;
|
|
849
|
-
requiresSocket = arg.requiresSocket || defaultRequiresSocket;
|
|
850
|
-
resolve = arg.resolve || defaultResolve;
|
|
851
|
-
} else {
|
|
852
|
-
ipc = args[0];
|
|
853
|
-
message = args[1];
|
|
854
|
-
execute = args[2];
|
|
855
|
-
resolve = args[3];
|
|
856
|
-
preparePrettyError = args[4];
|
|
857
|
-
logError = args[5];
|
|
858
|
-
requiresSocket = args[6];
|
|
859
|
-
}
|
|
860
|
-
if ('id' in message) {
|
|
861
|
-
if ('method' in message) {
|
|
862
|
-
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
863
|
-
try {
|
|
864
|
-
ipc.send(response);
|
|
865
|
-
} catch (error) {
|
|
866
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
867
|
-
ipc.send(errorResponse);
|
|
868
|
-
}
|
|
869
|
-
return;
|
|
870
|
-
}
|
|
871
|
-
resolve(message.id, message);
|
|
872
|
-
return;
|
|
873
|
-
}
|
|
874
|
-
if ('method' in message) {
|
|
875
|
-
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
throw new JsonRpcError('unexpected message');
|
|
879
|
-
};
|
|
880
|
-
|
|
881
1102
|
const requiresSocket = () => {
|
|
882
1103
|
return false;
|
|
883
1104
|
};
|
|
@@ -1329,6 +1550,7 @@ const listen = async () => {
|
|
|
1329
1550
|
method: Auto()
|
|
1330
1551
|
});
|
|
1331
1552
|
handleIpc(ipc);
|
|
1553
|
+
listen$2(ipc);
|
|
1332
1554
|
};
|
|
1333
1555
|
|
|
1334
1556
|
const main = async () => {
|