@lvce-editor/text-search-worker 3.19.0 → 3.21.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 +94 -573
- package/package.json +1 -1
|
@@ -184,14 +184,14 @@ const NewLine$1 = '\n';
|
|
|
184
184
|
const joinLines$1 = lines => {
|
|
185
185
|
return lines.join(NewLine$1);
|
|
186
186
|
};
|
|
187
|
-
const splitLines$
|
|
187
|
+
const splitLines$1 = lines => {
|
|
188
188
|
return lines.split(NewLine$1);
|
|
189
189
|
};
|
|
190
190
|
const isModuleNotFoundMessage = line => {
|
|
191
191
|
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
192
192
|
};
|
|
193
193
|
const getModuleNotFoundError = stderr => {
|
|
194
|
-
const lines = splitLines$
|
|
194
|
+
const lines = splitLines$1(stderr);
|
|
195
195
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
196
196
|
const message = lines[messageIndex];
|
|
197
197
|
return {
|
|
@@ -215,7 +215,7 @@ const isMessageCodeBlockEndIndex = line => {
|
|
|
215
215
|
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
216
216
|
};
|
|
217
217
|
const getMessageCodeBlock = stderr => {
|
|
218
|
-
const lines = splitLines$
|
|
218
|
+
const lines = splitLines$1(stderr);
|
|
219
219
|
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
220
220
|
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
221
221
|
const relevantLines = lines.slice(startIndex, endIndex);
|
|
@@ -279,7 +279,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
279
279
|
if (isModuleNotFoundError(stderr)) {
|
|
280
280
|
return getModuleNotFoundError(stderr);
|
|
281
281
|
}
|
|
282
|
-
const lines = splitLines$
|
|
282
|
+
const lines = splitLines$1(stderr);
|
|
283
283
|
const {
|
|
284
284
|
actualMessage,
|
|
285
285
|
rest
|
|
@@ -320,14 +320,14 @@ const readyMessage = 'ready';
|
|
|
320
320
|
const getData$2 = event => {
|
|
321
321
|
return event.data;
|
|
322
322
|
};
|
|
323
|
-
const listen$
|
|
323
|
+
const listen$7 = () => {
|
|
324
324
|
// @ts-ignore
|
|
325
325
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
326
326
|
throw new TypeError('module is not in web worker scope');
|
|
327
327
|
}
|
|
328
328
|
return globalThis;
|
|
329
329
|
};
|
|
330
|
-
const signal$
|
|
330
|
+
const signal$7 = global => {
|
|
331
331
|
global.postMessage(readyMessage);
|
|
332
332
|
};
|
|
333
333
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -353,7 +353,7 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
353
353
|
this._rawIpc.addEventListener('message', callback);
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
const wrap$
|
|
356
|
+
const wrap$e = global => {
|
|
357
357
|
return new IpcChildWithModuleWorker(global);
|
|
358
358
|
};
|
|
359
359
|
const withResolvers = () => {
|
|
@@ -378,10 +378,10 @@ const waitForFirstMessage = async port => {
|
|
|
378
378
|
// @ts-ignore
|
|
379
379
|
return event.data;
|
|
380
380
|
};
|
|
381
|
-
const listen$
|
|
382
|
-
const parentIpcRaw = listen$
|
|
383
|
-
signal$
|
|
384
|
-
const parentIpc = wrap$
|
|
381
|
+
const listen$6 = async () => {
|
|
382
|
+
const parentIpcRaw = listen$7();
|
|
383
|
+
signal$7(parentIpcRaw);
|
|
384
|
+
const parentIpc = wrap$e(parentIpcRaw);
|
|
385
385
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
386
386
|
if (firstMessage.method !== 'initialize') {
|
|
387
387
|
throw new IpcError('unexpected first message');
|
|
@@ -426,13 +426,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
426
426
|
this._rawIpc.start();
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
|
-
const wrap$
|
|
429
|
+
const wrap$d = port => {
|
|
430
430
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
431
431
|
};
|
|
432
432
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
433
433
|
__proto__: null,
|
|
434
|
-
listen: listen$
|
|
435
|
-
wrap: wrap$
|
|
434
|
+
listen: listen$6,
|
|
435
|
+
wrap: wrap$d
|
|
436
436
|
};
|
|
437
437
|
const Open = 1;
|
|
438
438
|
const Close = 2;
|
|
@@ -576,13 +576,13 @@ class IpcParentWithWebSocket extends Ipc {
|
|
|
576
576
|
this._rawIpc.addEventListener('message', callback);
|
|
577
577
|
}
|
|
578
578
|
}
|
|
579
|
-
const wrap
|
|
579
|
+
const wrap = webSocket => {
|
|
580
580
|
return new IpcParentWithWebSocket(webSocket);
|
|
581
581
|
};
|
|
582
582
|
const IpcParentWithWebSocket$1 = {
|
|
583
583
|
__proto__: null,
|
|
584
584
|
create: create$7,
|
|
585
|
-
wrap
|
|
585
|
+
wrap
|
|
586
586
|
};
|
|
587
587
|
|
|
588
588
|
const Two = '2.0';
|
|
@@ -714,14 +714,14 @@ const joinLines = lines => {
|
|
|
714
714
|
};
|
|
715
715
|
const MethodNotFound = -32601;
|
|
716
716
|
const Custom = -32001;
|
|
717
|
-
const splitLines
|
|
717
|
+
const splitLines = lines => {
|
|
718
718
|
return lines.split(NewLine);
|
|
719
719
|
};
|
|
720
720
|
const restoreJsonRpcError = error => {
|
|
721
721
|
if (error && error instanceof Error) {
|
|
722
722
|
return error;
|
|
723
723
|
}
|
|
724
|
-
const currentStack = joinLines(splitLines
|
|
724
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
725
725
|
if (error && error.code && error.code === MethodNotFound) {
|
|
726
726
|
const restoredError = new JsonRpcError(error.message);
|
|
727
727
|
const parentStack = getParentStack(error);
|
|
@@ -1078,21 +1078,21 @@ const clearSearchResults$1 = state => {
|
|
|
1078
1078
|
};
|
|
1079
1079
|
};
|
|
1080
1080
|
|
|
1081
|
-
const state$
|
|
1081
|
+
const state$2 = {
|
|
1082
1082
|
rpc: undefined
|
|
1083
1083
|
};
|
|
1084
1084
|
const invoke$2 = (method, ...params) => {
|
|
1085
|
-
const rpc = state$
|
|
1085
|
+
const rpc = state$2.rpc;
|
|
1086
1086
|
// @ts-ignore
|
|
1087
1087
|
return rpc.invoke(method, ...params);
|
|
1088
1088
|
};
|
|
1089
1089
|
const invokeAndTransfer = (method, ...params) => {
|
|
1090
|
-
const rpc = state$
|
|
1090
|
+
const rpc = state$2.rpc;
|
|
1091
1091
|
// @ts-ignore
|
|
1092
1092
|
return rpc.invokeAndTransfer(method, ...params);
|
|
1093
1093
|
};
|
|
1094
1094
|
const setRpc = rpc => {
|
|
1095
|
-
state$
|
|
1095
|
+
state$2.rpc = rpc;
|
|
1096
1096
|
};
|
|
1097
1097
|
|
|
1098
1098
|
const copy = async state => {
|
|
@@ -1217,13 +1217,6 @@ const lastIndex = array => {
|
|
|
1217
1217
|
const remove = (array, index, deleteCount) => {
|
|
1218
1218
|
return array.toSpliced(index, deleteCount);
|
|
1219
1219
|
};
|
|
1220
|
-
const fromAsync = async asyncIterable => {
|
|
1221
|
-
const children = [];
|
|
1222
|
-
for await (const value of asyncIterable) {
|
|
1223
|
-
children.push(value);
|
|
1224
|
-
}
|
|
1225
|
-
return children;
|
|
1226
|
-
};
|
|
1227
1220
|
|
|
1228
1221
|
const emptyObject = {};
|
|
1229
1222
|
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
@@ -1237,143 +1230,133 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1237
1230
|
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1238
1231
|
};
|
|
1239
1232
|
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
ReplacedOneOccurrenceInOneFile: "Replaced 1 occurrence across 1 file with '{PH1}'",
|
|
1269
|
-
ToggleReplace: 'Toggle Replace',
|
|
1270
|
-
UseRegularExpression: 'Use Regular Expression',
|
|
1271
|
-
ViewAsTree: 'View as Tree',
|
|
1272
|
-
FilesToInclude: 'Files to Include',
|
|
1273
|
-
FilesToExclude: 'Files to Exclude',
|
|
1274
|
-
ToggleSearchDetails: 'Toggle Search Details',
|
|
1275
|
-
SearchOnlyOpenEditors: 'Search Only Open Editors',
|
|
1276
|
-
UseExcludeSettings: 'Use Exclude Settings'
|
|
1277
|
-
};
|
|
1233
|
+
const ClearSearchResults = 'Clear Search Results';
|
|
1234
|
+
const CollapseAll$1 = 'Collapse All';
|
|
1235
|
+
const ConfirmReplaceManyOccurrencesInManyFiles = "Replace {PH1} occurrences across {PH2} files with '{PH3}'";
|
|
1236
|
+
const ConfirmReplaceManyOccurrencesInManyFilesNoValue = 'Replace {PH1} occurrences across {PH2} files';
|
|
1237
|
+
const ConfirmReplaceManyOccurrencesInOneFile = "Replace {PH1} occurrences across 1 file with '{PH2}'";
|
|
1238
|
+
const ConfirmReplaceManyOccurrencesInOneFileNoValue = 'Replace {PH1} occurrences across 1 file';
|
|
1239
|
+
const ConfirmReplaceOneOccurrenceInOneFile = "Replace 1 occurrence across 1 file with '{PH1}'";
|
|
1240
|
+
const ConfirmReplaceOneOccurrenceInOneFileNoValue = 'Replace 1 occurrence across 1 file';
|
|
1241
|
+
const ManyResultsInManyFiles = '{PH1} results in {PH2} files';
|
|
1242
|
+
const ManyResultsInOneFile = '{PH1} results in 1 file';
|
|
1243
|
+
const MatchCase$2 = 'Match Case';
|
|
1244
|
+
const MatchWholeWord$2 = 'Match Whole Word';
|
|
1245
|
+
const NoResults = 'No results found';
|
|
1246
|
+
const Oneresult = '1 result in 1 file';
|
|
1247
|
+
const OpenNewSearchEditor = 'Open New Search Editor';
|
|
1248
|
+
const PreserveCase$2 = 'Preserve Case';
|
|
1249
|
+
const Refresh$1 = 'Refresh';
|
|
1250
|
+
const Replace = 'Replace';
|
|
1251
|
+
const ReplaceAll$1 = 'Replace All';
|
|
1252
|
+
const ToggleReplace$1 = 'Toggle Replace';
|
|
1253
|
+
const UseRegularExpression$2 = 'Use Regular Expression';
|
|
1254
|
+
const ViewAsTree = 'View as Tree';
|
|
1255
|
+
const FilesToInclude$1 = 'Files to Include';
|
|
1256
|
+
const FilesToExclude$1 = 'Files to Exclude';
|
|
1257
|
+
const ToggleSearchDetails$1 = 'Toggle Search Details';
|
|
1258
|
+
const SearchOnlyOpenEditors$1 = 'Search Only Open Editors';
|
|
1259
|
+
const UseExcludeSettings$1 = 'Use Exclude Settings';
|
|
1260
|
+
|
|
1278
1261
|
const noResults = () => {
|
|
1279
|
-
return i18nString(
|
|
1262
|
+
return i18nString(NoResults);
|
|
1280
1263
|
};
|
|
1281
1264
|
const oneResult = () => {
|
|
1282
|
-
return i18nString(
|
|
1265
|
+
return i18nString(Oneresult);
|
|
1283
1266
|
};
|
|
1284
1267
|
const toggleReplace$1 = () => {
|
|
1285
|
-
return i18nString(
|
|
1268
|
+
return i18nString(ToggleReplace$1);
|
|
1286
1269
|
};
|
|
1287
1270
|
const matchCase = () => {
|
|
1288
|
-
return i18nString(
|
|
1271
|
+
return i18nString(MatchCase$2);
|
|
1289
1272
|
};
|
|
1290
1273
|
const preserveCase = () => {
|
|
1291
|
-
return i18nString(
|
|
1274
|
+
return i18nString(PreserveCase$2);
|
|
1292
1275
|
};
|
|
1293
1276
|
const matchWholeWord = () => {
|
|
1294
|
-
return i18nString(
|
|
1277
|
+
return i18nString(MatchWholeWord$2);
|
|
1295
1278
|
};
|
|
1296
1279
|
const toggleSearchDetails = () => {
|
|
1297
|
-
return i18nString(
|
|
1280
|
+
return i18nString(ToggleSearchDetails$1);
|
|
1298
1281
|
};
|
|
1299
1282
|
const useRegularExpression = () => {
|
|
1300
|
-
return i18nString(
|
|
1283
|
+
return i18nString(UseRegularExpression$2);
|
|
1301
1284
|
};
|
|
1302
1285
|
const manyResultsInOneFile = resultCount => {
|
|
1303
|
-
return i18nString(
|
|
1286
|
+
return i18nString(ManyResultsInOneFile, {
|
|
1304
1287
|
PH1: resultCount
|
|
1305
1288
|
});
|
|
1306
1289
|
};
|
|
1307
1290
|
const manyResultsInManyFiles = (resultCount, fileResultCount) => {
|
|
1308
|
-
return i18nString(
|
|
1291
|
+
return i18nString(ManyResultsInManyFiles, {
|
|
1309
1292
|
PH1: resultCount,
|
|
1310
1293
|
PH2: fileResultCount
|
|
1311
1294
|
});
|
|
1312
1295
|
};
|
|
1313
1296
|
const confirmReplaceOneOccurrenceInOneFile = replacement => {
|
|
1314
|
-
return i18nString(
|
|
1297
|
+
return i18nString(ConfirmReplaceOneOccurrenceInOneFile, {
|
|
1315
1298
|
PH1: replacement
|
|
1316
1299
|
});
|
|
1317
1300
|
};
|
|
1318
1301
|
const confirmReplaceOneOccurrenceInOneFileNoValue = () => {
|
|
1319
|
-
return i18nString(
|
|
1302
|
+
return i18nString(ConfirmReplaceOneOccurrenceInOneFileNoValue);
|
|
1320
1303
|
};
|
|
1321
1304
|
const confirmReplaceManyOccurrencesInOneFile = (matchCount, replacement) => {
|
|
1322
|
-
return i18nString(
|
|
1305
|
+
return i18nString(ConfirmReplaceManyOccurrencesInOneFile, {
|
|
1323
1306
|
PH1: matchCount,
|
|
1324
1307
|
PH2: replacement
|
|
1325
1308
|
});
|
|
1326
1309
|
};
|
|
1327
1310
|
const confirmReplaceManyOccurrencesInOneFileNoValue = matchCount => {
|
|
1328
|
-
return i18nString(
|
|
1311
|
+
return i18nString(ConfirmReplaceManyOccurrencesInOneFileNoValue, {
|
|
1329
1312
|
PH1: matchCount
|
|
1330
1313
|
});
|
|
1331
1314
|
};
|
|
1332
1315
|
const confirmReplaceManyOccurrencesInManyFiles = (matchCount, fileCount, replacement) => {
|
|
1333
|
-
return i18nString(
|
|
1316
|
+
return i18nString(ConfirmReplaceManyOccurrencesInManyFiles, {
|
|
1334
1317
|
PH1: matchCount,
|
|
1335
1318
|
PH2: fileCount,
|
|
1336
1319
|
PH3: replacement
|
|
1337
1320
|
});
|
|
1338
1321
|
};
|
|
1339
1322
|
const confirmReplaceManyOccurrencesInManyFilesNoValue = (matchCount, fileCount) => {
|
|
1340
|
-
return i18nString(
|
|
1323
|
+
return i18nString(ConfirmReplaceManyOccurrencesInManyFilesNoValue, {
|
|
1341
1324
|
PH1: matchCount,
|
|
1342
1325
|
PH2: fileCount
|
|
1343
1326
|
});
|
|
1344
1327
|
};
|
|
1345
1328
|
const replaceAll$1 = () => {
|
|
1346
|
-
return i18nString(
|
|
1329
|
+
return i18nString(ReplaceAll$1);
|
|
1347
1330
|
};
|
|
1348
1331
|
const replace = () => {
|
|
1349
|
-
return i18nString(
|
|
1332
|
+
return i18nString(Replace);
|
|
1350
1333
|
};
|
|
1351
1334
|
const refresh$1 = () => {
|
|
1352
|
-
return i18nString(
|
|
1335
|
+
return i18nString(Refresh$1);
|
|
1353
1336
|
};
|
|
1354
1337
|
const clearSearchResults = () => {
|
|
1355
|
-
return i18nString(
|
|
1338
|
+
return i18nString(ClearSearchResults);
|
|
1356
1339
|
};
|
|
1357
1340
|
const openNewSearchEditor = () => {
|
|
1358
|
-
return i18nString(
|
|
1341
|
+
return i18nString(OpenNewSearchEditor);
|
|
1359
1342
|
};
|
|
1360
1343
|
const viewAsTree = () => {
|
|
1361
|
-
return i18nString(
|
|
1344
|
+
return i18nString(ViewAsTree);
|
|
1362
1345
|
};
|
|
1363
1346
|
const collapseAll = () => {
|
|
1364
|
-
return i18nString(
|
|
1347
|
+
return i18nString(CollapseAll$1);
|
|
1365
1348
|
};
|
|
1366
1349
|
const filesToInclude = () => {
|
|
1367
|
-
return i18nString(
|
|
1350
|
+
return i18nString(FilesToInclude$1);
|
|
1368
1351
|
};
|
|
1369
1352
|
const filesToExclude = () => {
|
|
1370
|
-
return i18nString(
|
|
1353
|
+
return i18nString(FilesToExclude$1);
|
|
1371
1354
|
};
|
|
1372
1355
|
const searchOnlyOpenEditors = () => {
|
|
1373
|
-
return i18nString(
|
|
1356
|
+
return i18nString(SearchOnlyOpenEditors$1);
|
|
1374
1357
|
};
|
|
1375
1358
|
const useExcludeSettings = () => {
|
|
1376
|
-
return i18nString(
|
|
1359
|
+
return i18nString(UseExcludeSettings$1);
|
|
1377
1360
|
};
|
|
1378
1361
|
|
|
1379
1362
|
const getStatusMessage = (resultCount, fileResultCount) => {
|
|
@@ -1389,13 +1372,13 @@ const getStatusMessage = (resultCount, fileResultCount) => {
|
|
|
1389
1372
|
return manyResultsInManyFiles(resultCount, fileResultCount);
|
|
1390
1373
|
};
|
|
1391
1374
|
|
|
1392
|
-
const File
|
|
1375
|
+
const File = 1;
|
|
1393
1376
|
const Match = 2;
|
|
1394
1377
|
|
|
1395
1378
|
const getSetSize = (items, index) => {
|
|
1396
1379
|
let setSize = 0;
|
|
1397
1380
|
for (let i = index + 1; i < items.length; i++) {
|
|
1398
|
-
if (items[i].type === File
|
|
1381
|
+
if (items[i].type === File) {
|
|
1399
1382
|
break;
|
|
1400
1383
|
}
|
|
1401
1384
|
setSize++;
|
|
@@ -1414,7 +1397,7 @@ const getRemoveIndicesFile = (items, item, index, matchCount, fileCount) => {
|
|
|
1414
1397
|
};
|
|
1415
1398
|
const getRemoveIndicesMatch = (items, index, matchCount, fileCount) => {
|
|
1416
1399
|
for (let i = index; i >= 0; i--) {
|
|
1417
|
-
if (items[i].type === File
|
|
1400
|
+
if (items[i].type === File) {
|
|
1418
1401
|
const setSize = getSetSize(items, i);
|
|
1419
1402
|
if (setSize === 1) {
|
|
1420
1403
|
return {
|
|
@@ -1439,7 +1422,7 @@ const getRemoveIndicesMatch = (items, index, matchCount, fileCount) => {
|
|
|
1439
1422
|
const getRemoveIndices = (items, index, matchCount, fileCount) => {
|
|
1440
1423
|
const item = items[index];
|
|
1441
1424
|
switch (item.type) {
|
|
1442
|
-
case File
|
|
1425
|
+
case File:
|
|
1443
1426
|
return getRemoveIndicesFile(items, item, index, matchCount, fileCount);
|
|
1444
1427
|
case Match:
|
|
1445
1428
|
return getRemoveIndicesMatch(items, index, matchCount, fileCount);
|
|
@@ -1915,13 +1898,13 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1915
1898
|
const top = i * itemHeight;
|
|
1916
1899
|
const focused = i === focusedIndex;
|
|
1917
1900
|
switch (type) {
|
|
1918
|
-
case File
|
|
1901
|
+
case File:
|
|
1919
1902
|
const path = text;
|
|
1920
1903
|
const absolutePath = getAbsolutePath(path);
|
|
1921
1904
|
const baseName = pathBaseName(path);
|
|
1922
1905
|
return {
|
|
1923
1906
|
title: absolutePath,
|
|
1924
|
-
type: File
|
|
1907
|
+
type: File,
|
|
1925
1908
|
text: baseName,
|
|
1926
1909
|
icon: fileIcons[fileIconIndex],
|
|
1927
1910
|
posInSet,
|
|
@@ -1969,7 +1952,7 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
|
|
|
1969
1952
|
const result = results[i];
|
|
1970
1953
|
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
1971
1954
|
displayResults.push(displayResult);
|
|
1972
|
-
if (result.type === File
|
|
1955
|
+
if (result.type === File) {
|
|
1973
1956
|
fileResult = displayResult;
|
|
1974
1957
|
fileIconIndex++;
|
|
1975
1958
|
} else {
|
|
@@ -2325,13 +2308,13 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2325
2308
|
treeItem.className += ' ' + TreeItemActive;
|
|
2326
2309
|
}
|
|
2327
2310
|
switch (type) {
|
|
2328
|
-
case File
|
|
2311
|
+
case File:
|
|
2329
2312
|
treeItem.ariaExpanded = 'true';
|
|
2330
2313
|
break;
|
|
2331
2314
|
}
|
|
2332
2315
|
const dom = [];
|
|
2333
2316
|
dom.push(treeItem);
|
|
2334
|
-
if (type === File
|
|
2317
|
+
if (type === File) {
|
|
2335
2318
|
treeItem.childCount += 2;
|
|
2336
2319
|
dom.push(chevronDownVirtualDom, getFileIconVirtualDom(icon));
|
|
2337
2320
|
}
|
|
@@ -2379,7 +2362,7 @@ const handleError = error => {
|
|
|
2379
2362
|
};
|
|
2380
2363
|
|
|
2381
2364
|
const isFile = match => {
|
|
2382
|
-
return match.type === File
|
|
2365
|
+
return match.type === File;
|
|
2383
2366
|
};
|
|
2384
2367
|
const getFiles = matches => {
|
|
2385
2368
|
return matches.filter(isFile);
|
|
@@ -2410,7 +2393,7 @@ const getTextSearchResultCounts = results => {
|
|
|
2410
2393
|
let fileCount = 0;
|
|
2411
2394
|
for (const result of results) {
|
|
2412
2395
|
switch (result.type) {
|
|
2413
|
-
case File
|
|
2396
|
+
case File:
|
|
2414
2397
|
fileCount++;
|
|
2415
2398
|
break;
|
|
2416
2399
|
case Match:
|
|
@@ -2480,474 +2463,12 @@ const textSearch$5 = async (scheme, root, query) => {
|
|
|
2480
2463
|
return result;
|
|
2481
2464
|
};
|
|
2482
2465
|
|
|
2483
|
-
const getJson = async url => {
|
|
2484
|
-
try {
|
|
2485
|
-
const response = await fetch(url);
|
|
2486
|
-
if (!response.ok) {
|
|
2487
|
-
throw new Error(response.statusText);
|
|
2488
|
-
}
|
|
2489
|
-
const json = await response.json();
|
|
2490
|
-
return json;
|
|
2491
|
-
} catch (error) {
|
|
2492
|
-
throw new VError(error, `Failed to get json`);
|
|
2493
|
-
}
|
|
2494
|
-
};
|
|
2495
|
-
|
|
2496
|
-
const getText = async url => {
|
|
2497
|
-
try {
|
|
2498
|
-
const response = await fetch(url);
|
|
2499
|
-
if (!response.ok) {
|
|
2500
|
-
throw new Error(response.statusText);
|
|
2501
|
-
}
|
|
2502
|
-
const text = await response.text();
|
|
2503
|
-
return text;
|
|
2504
|
-
} catch (error) {
|
|
2505
|
-
throw new VError(error, `Failed to get text`);
|
|
2506
|
-
}
|
|
2507
|
-
};
|
|
2508
|
-
|
|
2509
|
-
const splitLines = lines => {
|
|
2510
|
-
return lines.split('\n');
|
|
2511
|
-
};
|
|
2512
|
-
|
|
2513
|
-
const textSearchInText = (file, content, query) => {
|
|
2514
|
-
const results = [];
|
|
2515
|
-
const lines = splitLines(content);
|
|
2516
|
-
for (let i = 0; i < lines.length; i++) {
|
|
2517
|
-
const line = lines[i];
|
|
2518
|
-
const index = line.indexOf(query);
|
|
2519
|
-
if (index !== -1) {
|
|
2520
|
-
results.push({
|
|
2521
|
-
type: Match,
|
|
2522
|
-
text: line,
|
|
2523
|
-
start: index,
|
|
2524
|
-
end: index + query.length,
|
|
2525
|
-
lineNumber: i
|
|
2526
|
-
});
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2529
|
-
if (results.length > 0) {
|
|
2530
|
-
results.unshift({
|
|
2531
|
-
type: File$1,
|
|
2532
|
-
text: file,
|
|
2533
|
-
start: 0,
|
|
2534
|
-
end: 0,
|
|
2535
|
-
lineNumber: 0
|
|
2536
|
-
});
|
|
2537
|
-
}
|
|
2538
|
-
return results;
|
|
2539
|
-
};
|
|
2540
|
-
|
|
2541
2466
|
const textSearch$4 = async (scheme, root, query, options, assetDir) => {
|
|
2542
|
-
|
|
2543
|
-
string(root);
|
|
2544
|
-
string(query);
|
|
2545
|
-
const fetchUri = `${assetDir}/config/fileMap.json`;
|
|
2546
|
-
const fileList = await getJson(fetchUri);
|
|
2547
|
-
const allResults = [];
|
|
2548
|
-
const relativeRoot = root.slice('fetch://'.length);
|
|
2549
|
-
for (const uri of fileList) {
|
|
2550
|
-
const fetchUri = `${assetDir}${uri}`;
|
|
2551
|
-
const content = await getText(fetchUri);
|
|
2552
|
-
const relativeUri = uri.slice(relativeRoot.length + 1);
|
|
2553
|
-
const results = textSearchInText(relativeUri, content, query);
|
|
2554
|
-
allResults.push(...results);
|
|
2555
|
-
}
|
|
2556
|
-
return allResults;
|
|
2557
|
-
};
|
|
2558
|
-
|
|
2559
|
-
class FileNotFoundError extends Error {
|
|
2560
|
-
constructor(message) {
|
|
2561
|
-
super(message);
|
|
2562
|
-
this.name = 'FileNotFoundError';
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
const Directory = 'directory';
|
|
2567
|
-
const File = 'file';
|
|
2568
|
-
|
|
2569
|
-
const getChildHandles$1 = async handle => {
|
|
2570
|
-
object(handle);
|
|
2571
|
-
// @ts-ignore
|
|
2572
|
-
const childHandles = handle.values();
|
|
2573
|
-
const handles = await fromAsync(childHandles);
|
|
2574
|
-
return handles;
|
|
2575
|
-
};
|
|
2576
|
-
|
|
2577
|
-
const getChildHandles = async handle => {
|
|
2578
|
-
try {
|
|
2579
|
-
return await getChildHandles$1(handle);
|
|
2580
|
-
} catch (error) {
|
|
2581
|
-
throw new VError(error, 'failed to get child handles');
|
|
2582
|
-
}
|
|
2583
|
-
};
|
|
2584
|
-
|
|
2585
|
-
const dirname = (pathSeparator, path) => {
|
|
2586
|
-
const index = path.lastIndexOf(pathSeparator);
|
|
2587
|
-
if (index === -1) {
|
|
2588
|
-
return path;
|
|
2589
|
-
}
|
|
2590
|
-
return path.slice(0, index);
|
|
2591
|
-
};
|
|
2592
|
-
|
|
2593
|
-
const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
|
|
2594
|
-
let idbProxyableTypes;
|
|
2595
|
-
let cursorAdvanceMethods;
|
|
2596
|
-
// This is a function to prevent it throwing up in node environments.
|
|
2597
|
-
function getIdbProxyableTypes() {
|
|
2598
|
-
return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
|
|
2599
|
-
}
|
|
2600
|
-
// This is a function to prevent it throwing up in node environments.
|
|
2601
|
-
function getCursorAdvanceMethods() {
|
|
2602
|
-
return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
|
|
2603
|
-
}
|
|
2604
|
-
const transactionDoneMap = new WeakMap();
|
|
2605
|
-
const transformCache = new WeakMap();
|
|
2606
|
-
const reverseTransformCache = new WeakMap();
|
|
2607
|
-
function promisifyRequest(request) {
|
|
2608
|
-
const promise = new Promise((resolve, reject) => {
|
|
2609
|
-
const unlisten = () => {
|
|
2610
|
-
request.removeEventListener('success', success);
|
|
2611
|
-
request.removeEventListener('error', error);
|
|
2612
|
-
};
|
|
2613
|
-
const success = () => {
|
|
2614
|
-
resolve(wrap(request.result));
|
|
2615
|
-
unlisten();
|
|
2616
|
-
};
|
|
2617
|
-
const error = () => {
|
|
2618
|
-
reject(request.error);
|
|
2619
|
-
unlisten();
|
|
2620
|
-
};
|
|
2621
|
-
request.addEventListener('success', success);
|
|
2622
|
-
request.addEventListener('error', error);
|
|
2623
|
-
});
|
|
2624
|
-
// This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
|
|
2625
|
-
// is because we create many promises from a single IDBRequest.
|
|
2626
|
-
reverseTransformCache.set(promise, request);
|
|
2627
|
-
return promise;
|
|
2628
|
-
}
|
|
2629
|
-
function cacheDonePromiseForTransaction(tx) {
|
|
2630
|
-
// Early bail if we've already created a done promise for this transaction.
|
|
2631
|
-
if (transactionDoneMap.has(tx)) return;
|
|
2632
|
-
const done = new Promise((resolve, reject) => {
|
|
2633
|
-
const unlisten = () => {
|
|
2634
|
-
tx.removeEventListener('complete', complete);
|
|
2635
|
-
tx.removeEventListener('error', error);
|
|
2636
|
-
tx.removeEventListener('abort', error);
|
|
2637
|
-
};
|
|
2638
|
-
const complete = () => {
|
|
2639
|
-
resolve();
|
|
2640
|
-
unlisten();
|
|
2641
|
-
};
|
|
2642
|
-
const error = () => {
|
|
2643
|
-
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
2644
|
-
unlisten();
|
|
2645
|
-
};
|
|
2646
|
-
tx.addEventListener('complete', complete);
|
|
2647
|
-
tx.addEventListener('error', error);
|
|
2648
|
-
tx.addEventListener('abort', error);
|
|
2649
|
-
});
|
|
2650
|
-
// Cache it for later retrieval.
|
|
2651
|
-
transactionDoneMap.set(tx, done);
|
|
2652
|
-
}
|
|
2653
|
-
let idbProxyTraps = {
|
|
2654
|
-
get(target, prop, receiver) {
|
|
2655
|
-
if (target instanceof IDBTransaction) {
|
|
2656
|
-
// Special handling for transaction.done.
|
|
2657
|
-
if (prop === 'done') return transactionDoneMap.get(target);
|
|
2658
|
-
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
2659
|
-
if (prop === 'store') {
|
|
2660
|
-
return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
|
|
2661
|
-
}
|
|
2662
|
-
}
|
|
2663
|
-
// Else transform whatever we get back.
|
|
2664
|
-
return wrap(target[prop]);
|
|
2665
|
-
},
|
|
2666
|
-
set(target, prop, value) {
|
|
2667
|
-
target[prop] = value;
|
|
2668
|
-
return true;
|
|
2669
|
-
},
|
|
2670
|
-
has(target, prop) {
|
|
2671
|
-
if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
|
|
2672
|
-
return true;
|
|
2673
|
-
}
|
|
2674
|
-
return prop in target;
|
|
2675
|
-
}
|
|
2676
|
-
};
|
|
2677
|
-
function replaceTraps(callback) {
|
|
2678
|
-
idbProxyTraps = callback(idbProxyTraps);
|
|
2679
|
-
}
|
|
2680
|
-
function wrapFunction(func) {
|
|
2681
|
-
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
2682
|
-
// only create one new func per func.
|
|
2683
|
-
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
2684
|
-
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
2685
|
-
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
2686
|
-
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
2687
|
-
// undefined if the end of the cursor has been reached.
|
|
2688
|
-
if (getCursorAdvanceMethods().includes(func)) {
|
|
2689
|
-
return function (...args) {
|
|
2690
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
2691
|
-
// the original object.
|
|
2692
|
-
func.apply(unwrap(this), args);
|
|
2693
|
-
return wrap(this.request);
|
|
2694
|
-
};
|
|
2695
|
-
}
|
|
2696
|
-
return function (...args) {
|
|
2697
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
2698
|
-
// the original object.
|
|
2699
|
-
return wrap(func.apply(unwrap(this), args));
|
|
2700
|
-
};
|
|
2701
|
-
}
|
|
2702
|
-
function transformCachableValue(value) {
|
|
2703
|
-
if (typeof value === 'function') return wrapFunction(value);
|
|
2704
|
-
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
2705
|
-
// which is later returned for transaction.done (see idbObjectHandler).
|
|
2706
|
-
if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
|
|
2707
|
-
if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
|
|
2708
|
-
// Return the same value back if we're not going to transform it.
|
|
2709
|
-
return value;
|
|
2710
|
-
}
|
|
2711
|
-
function wrap(value) {
|
|
2712
|
-
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
2713
|
-
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
2714
|
-
if (value instanceof IDBRequest) return promisifyRequest(value);
|
|
2715
|
-
// If we've already transformed this value before, reuse the transformed value.
|
|
2716
|
-
// This is faster, but it also provides object equality.
|
|
2717
|
-
if (transformCache.has(value)) return transformCache.get(value);
|
|
2718
|
-
const newValue = transformCachableValue(value);
|
|
2719
|
-
// Not all types are transformed.
|
|
2720
|
-
// These may be primitive types, so they can't be WeakMap keys.
|
|
2721
|
-
if (newValue !== value) {
|
|
2722
|
-
transformCache.set(value, newValue);
|
|
2723
|
-
reverseTransformCache.set(newValue, value);
|
|
2724
|
-
}
|
|
2725
|
-
return newValue;
|
|
2726
|
-
}
|
|
2727
|
-
const unwrap = value => reverseTransformCache.get(value);
|
|
2728
|
-
|
|
2729
|
-
/**
|
|
2730
|
-
* Open a database.
|
|
2731
|
-
*
|
|
2732
|
-
* @param name Name of the database.
|
|
2733
|
-
* @param version Schema version.
|
|
2734
|
-
* @param callbacks Additional callbacks.
|
|
2735
|
-
*/
|
|
2736
|
-
function openDB(name, version, {
|
|
2737
|
-
blocked,
|
|
2738
|
-
upgrade,
|
|
2739
|
-
blocking,
|
|
2740
|
-
terminated
|
|
2741
|
-
} = {}) {
|
|
2742
|
-
const request = indexedDB.open(name, version);
|
|
2743
|
-
const openPromise = wrap(request);
|
|
2744
|
-
if (upgrade) {
|
|
2745
|
-
request.addEventListener('upgradeneeded', event => {
|
|
2746
|
-
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
2747
|
-
});
|
|
2748
|
-
}
|
|
2749
|
-
if (blocked) {
|
|
2750
|
-
request.addEventListener('blocked', event => blocked(
|
|
2751
|
-
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
2752
|
-
event.oldVersion, event.newVersion, event));
|
|
2753
|
-
}
|
|
2754
|
-
openPromise.then(db => {
|
|
2755
|
-
if (terminated) db.addEventListener('close', () => terminated());
|
|
2756
|
-
if (blocking) {
|
|
2757
|
-
db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
|
|
2758
|
-
}
|
|
2759
|
-
}).catch(() => {});
|
|
2760
|
-
return openPromise;
|
|
2761
|
-
}
|
|
2762
|
-
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
2763
|
-
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
2764
|
-
const cachedMethods = new Map();
|
|
2765
|
-
function getMethod(target, prop) {
|
|
2766
|
-
if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
|
|
2767
|
-
return;
|
|
2768
|
-
}
|
|
2769
|
-
if (cachedMethods.get(prop)) return cachedMethods.get(prop);
|
|
2770
|
-
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
2771
|
-
const useIndex = prop !== targetFuncName;
|
|
2772
|
-
const isWrite = writeMethods.includes(targetFuncName);
|
|
2773
|
-
if (
|
|
2774
|
-
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
2775
|
-
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
|
|
2776
|
-
return;
|
|
2777
|
-
}
|
|
2778
|
-
const method = async function (storeName, ...args) {
|
|
2779
|
-
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
2780
|
-
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
2781
|
-
let target = tx.store;
|
|
2782
|
-
if (useIndex) target = target.index(args.shift());
|
|
2783
|
-
// Must reject if op rejects.
|
|
2784
|
-
// If it's a write operation, must reject if tx.done rejects.
|
|
2785
|
-
// Must reject with op rejection first.
|
|
2786
|
-
// Must resolve with op value.
|
|
2787
|
-
// Must handle both promises (no unhandled rejections)
|
|
2788
|
-
return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
|
|
2789
|
-
};
|
|
2790
|
-
cachedMethods.set(prop, method);
|
|
2791
|
-
return method;
|
|
2792
|
-
}
|
|
2793
|
-
replaceTraps(oldTraps => ({
|
|
2794
|
-
...oldTraps,
|
|
2795
|
-
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
2796
|
-
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
|
|
2797
|
-
}));
|
|
2798
|
-
const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
|
|
2799
|
-
const methodMap = {};
|
|
2800
|
-
const advanceResults = new WeakMap();
|
|
2801
|
-
const ittrProxiedCursorToOriginalProxy = new WeakMap();
|
|
2802
|
-
const cursorIteratorTraps = {
|
|
2803
|
-
get(target, prop) {
|
|
2804
|
-
if (!advanceMethodProps.includes(prop)) return target[prop];
|
|
2805
|
-
let cachedFunc = methodMap[prop];
|
|
2806
|
-
if (!cachedFunc) {
|
|
2807
|
-
cachedFunc = methodMap[prop] = function (...args) {
|
|
2808
|
-
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
|
|
2809
|
-
};
|
|
2810
|
-
}
|
|
2811
|
-
return cachedFunc;
|
|
2812
|
-
}
|
|
2813
|
-
};
|
|
2814
|
-
async function* iterate(...args) {
|
|
2815
|
-
// tslint:disable-next-line:no-this-assignment
|
|
2816
|
-
let cursor = this;
|
|
2817
|
-
if (!(cursor instanceof IDBCursor)) {
|
|
2818
|
-
cursor = await cursor.openCursor(...args);
|
|
2819
|
-
}
|
|
2820
|
-
if (!cursor) return;
|
|
2821
|
-
cursor = cursor;
|
|
2822
|
-
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
2823
|
-
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
2824
|
-
// Map this double-proxy back to the original, so other cursor methods work.
|
|
2825
|
-
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
2826
|
-
while (cursor) {
|
|
2827
|
-
yield proxiedCursor;
|
|
2828
|
-
// If one of the advancing methods was not called, call continue().
|
|
2829
|
-
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
2830
|
-
advanceResults.delete(proxiedCursor);
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
function isIteratorProp(target, prop) {
|
|
2834
|
-
return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
|
|
2835
|
-
}
|
|
2836
|
-
replaceTraps(oldTraps => ({
|
|
2837
|
-
...oldTraps,
|
|
2838
|
-
get(target, prop, receiver) {
|
|
2839
|
-
if (isIteratorProp(target, prop)) return iterate;
|
|
2840
|
-
return oldTraps.get(target, prop, receiver);
|
|
2841
|
-
},
|
|
2842
|
-
has(target, prop) {
|
|
2843
|
-
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
2844
|
-
}
|
|
2845
|
-
}));
|
|
2846
|
-
|
|
2847
|
-
const state$2 = {
|
|
2848
|
-
databases: Object.create(null),
|
|
2849
|
-
eventId: 0,
|
|
2850
|
-
dbVersion: 1,
|
|
2851
|
-
cachedDb: undefined
|
|
2852
|
-
};
|
|
2853
|
-
|
|
2854
|
-
// TODO high memory usage in idb because of transactionDoneMap
|
|
2855
|
-
|
|
2856
|
-
const getHandleDb = async () => {
|
|
2857
|
-
// @ts-ignore
|
|
2858
|
-
const db = await openDB('handle', state$2.dbVersion, {
|
|
2859
|
-
async upgrade(db) {
|
|
2860
|
-
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
2861
|
-
await db.createObjectStore('file-handles-store', {});
|
|
2862
|
-
}
|
|
2863
|
-
}
|
|
2864
|
-
});
|
|
2865
|
-
return db;
|
|
2866
|
-
};
|
|
2867
|
-
|
|
2868
|
-
const getHandle$1 = async uri => {
|
|
2869
|
-
const handleDb = await getHandleDb();
|
|
2870
|
-
const handle = await handleDb.get('file-handles-store', uri);
|
|
2871
|
-
return handle;
|
|
2872
|
-
};
|
|
2873
|
-
|
|
2874
|
-
const getHandle = async uri => {
|
|
2875
|
-
try {
|
|
2876
|
-
// TODO retrieve handle from state or from indexeddb
|
|
2877
|
-
// TODO if not found, throw error
|
|
2878
|
-
const handle = await getHandle$1(uri);
|
|
2879
|
-
return handle;
|
|
2880
|
-
} catch (error) {
|
|
2881
|
-
throw new VError(error, 'Failed to get handle');
|
|
2882
|
-
}
|
|
2467
|
+
return invoke$2('ExtensionHostTextSearch.textSearchFetch', scheme, root, query, options, assetDir);
|
|
2883
2468
|
};
|
|
2884
2469
|
|
|
2885
|
-
const getDirectoryHandle = async uri => {
|
|
2886
|
-
const handle = await getHandle(uri);
|
|
2887
|
-
if (handle) {
|
|
2888
|
-
return handle;
|
|
2889
|
-
}
|
|
2890
|
-
const dirname$1 = dirname('/', uri);
|
|
2891
|
-
if (uri === dirname$1) {
|
|
2892
|
-
return undefined;
|
|
2893
|
-
}
|
|
2894
|
-
return getDirectoryHandle(dirname$1);
|
|
2895
|
-
};
|
|
2896
|
-
|
|
2897
|
-
const NotReadableError = 'NotReadableError';
|
|
2898
|
-
|
|
2899
|
-
const isNotReadableError = error => {
|
|
2900
|
-
return error && error.name === NotReadableError;
|
|
2901
|
-
};
|
|
2902
|
-
|
|
2903
|
-
const getFile = handle => {
|
|
2904
|
-
return handle.getFile();
|
|
2905
|
-
};
|
|
2906
|
-
|
|
2907
|
-
const textSearchInFile = async (all, handle, absolutePath, query) => {
|
|
2908
|
-
try {
|
|
2909
|
-
const file = await getFile(handle);
|
|
2910
|
-
const content = await file.text();
|
|
2911
|
-
const results = textSearchInText(absolutePath, content, query);
|
|
2912
|
-
push(all, results);
|
|
2913
|
-
} catch (error) {
|
|
2914
|
-
if (isNotReadableError(error)) {
|
|
2915
|
-
// ignore
|
|
2916
|
-
return;
|
|
2917
|
-
}
|
|
2918
|
-
throw error;
|
|
2919
|
-
}
|
|
2920
|
-
};
|
|
2921
|
-
|
|
2922
|
-
const textSearchRecursively = async (all, parent, handle, query) => {
|
|
2923
|
-
const childHandles = await getChildHandles(handle);
|
|
2924
|
-
const promises = [];
|
|
2925
|
-
for (const childHandle of childHandles) {
|
|
2926
|
-
const absolutePath = parent + '/' + childHandle.name;
|
|
2927
|
-
switch (childHandle.kind) {
|
|
2928
|
-
case Directory:
|
|
2929
|
-
promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
|
|
2930
|
-
break;
|
|
2931
|
-
case File:
|
|
2932
|
-
// @ts-ignore
|
|
2933
|
-
promises.push(textSearchInFile(all, childHandle, absolutePath, query));
|
|
2934
|
-
break;
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
await Promise.all(promises);
|
|
2938
|
-
};
|
|
2939
2470
|
const textSearch$3 = async (scheme, root, query) => {
|
|
2940
|
-
|
|
2941
|
-
string(root);
|
|
2942
|
-
string(query);
|
|
2943
|
-
const relativeRoot = root.slice('html://'.length);
|
|
2944
|
-
const handle = await getDirectoryHandle(relativeRoot);
|
|
2945
|
-
if (!handle) {
|
|
2946
|
-
throw new FileNotFoundError(`Folder not found: ${relativeRoot}`);
|
|
2947
|
-
}
|
|
2948
|
-
const all = [];
|
|
2949
|
-
await textSearchRecursively(all, '', handle, query);
|
|
2950
|
-
return all;
|
|
2471
|
+
return invoke$2('ExtensionHostTextSearch.textSearchHtml', scheme, root, query);
|
|
2951
2472
|
};
|
|
2952
2473
|
|
|
2953
2474
|
const getRipGrepArgs = ({
|
|
@@ -3442,7 +2963,7 @@ const getFilteredResults = (results, collapsedPaths) => {
|
|
|
3442
2963
|
const filteredResults = [];
|
|
3443
2964
|
let isExcluded = false;
|
|
3444
2965
|
for (const result of results) {
|
|
3445
|
-
if (result.type === File
|
|
2966
|
+
if (result.type === File) {
|
|
3446
2967
|
if (collapsedPaths.includes(result.text)) {
|
|
3447
2968
|
isExcluded = true;
|
|
3448
2969
|
} else {
|
|
@@ -3485,7 +3006,7 @@ const openUri = async (path, focus = true, props = {}) => {
|
|
|
3485
3006
|
const getFileIndex = (items, index) => {
|
|
3486
3007
|
for (let i = index; i >= 0; i--) {
|
|
3487
3008
|
const item = items[i];
|
|
3488
|
-
if (item.type === File
|
|
3009
|
+
if (item.type === File) {
|
|
3489
3010
|
return i;
|
|
3490
3011
|
}
|
|
3491
3012
|
}
|
|
@@ -3528,7 +3049,7 @@ const selectIndex = async (state, index) => {
|
|
|
3528
3049
|
} = state;
|
|
3529
3050
|
const searchResult = items[index];
|
|
3530
3051
|
switch (searchResult.type) {
|
|
3531
|
-
case File
|
|
3052
|
+
case File:
|
|
3532
3053
|
return selectIndexFile(state, searchResult, index);
|
|
3533
3054
|
case Match:
|
|
3534
3055
|
return selectIndexPreview(state, searchResult, index);
|
|
@@ -3840,7 +3361,7 @@ const getBulkReplacementEdits = (workspacePath, matches) => {
|
|
|
3840
3361
|
text
|
|
3841
3362
|
} = match;
|
|
3842
3363
|
switch (type) {
|
|
3843
|
-
case File
|
|
3364
|
+
case File:
|
|
3844
3365
|
ranges.push(currentRanges.length);
|
|
3845
3366
|
push(ranges, currentRanges);
|
|
3846
3367
|
const absolutePath = `${workspacePath}/${text.slice(2)}`;
|