@lvce-editor/text-search-worker 7.13.0 → 7.13.2
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 +47 -2
- package/package.json +1 -1
|
@@ -1438,17 +1438,29 @@ const textSearch$6 = async (root, query, options, assetDir, platform, searchId,
|
|
|
1438
1438
|
return results;
|
|
1439
1439
|
};
|
|
1440
1440
|
|
|
1441
|
+
const getContextArgs = contextLines => {
|
|
1442
|
+
if (contextLines && contextLines > 0) {
|
|
1443
|
+
return ['--context', `${Math.trunc(contextLines)}`];
|
|
1444
|
+
}
|
|
1445
|
+
return [];
|
|
1446
|
+
};
|
|
1447
|
+
const getIncludeArgs = include => {
|
|
1448
|
+
return (include || '').split(',').map(part => part.trim()).filter(Boolean).flatMap(pattern => ['--glob', pattern]);
|
|
1449
|
+
};
|
|
1441
1450
|
const getRipGrepArgs = ({
|
|
1451
|
+
contextLines,
|
|
1442
1452
|
defaultExcludes,
|
|
1443
1453
|
exclude,
|
|
1454
|
+
include,
|
|
1444
1455
|
isCaseSensitive,
|
|
1445
1456
|
matchWholeWord,
|
|
1457
|
+
paths,
|
|
1446
1458
|
searchString,
|
|
1447
1459
|
threads,
|
|
1448
1460
|
useIgnoreFiles = true,
|
|
1449
1461
|
useRegularExpression
|
|
1450
1462
|
}) => {
|
|
1451
|
-
const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json', '--threads', `${threads}
|
|
1463
|
+
const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json', '--threads', `${threads}`, ...getContextArgs(contextLines)];
|
|
1452
1464
|
if (!useIgnoreFiles) {
|
|
1453
1465
|
ripGrepArgs.push('--no-ignore');
|
|
1454
1466
|
}
|
|
@@ -1465,6 +1477,7 @@ const getRipGrepArgs = ({
|
|
|
1465
1477
|
ripGrepArgs.push('--glob', `!**/${excludePattern}/**`);
|
|
1466
1478
|
}
|
|
1467
1479
|
}
|
|
1480
|
+
ripGrepArgs.push(...getIncludeArgs(include));
|
|
1468
1481
|
if (isCaseSensitive) {
|
|
1469
1482
|
ripGrepArgs.push('--case-sensitive');
|
|
1470
1483
|
} else {
|
|
@@ -1480,7 +1493,7 @@ const getRipGrepArgs = ({
|
|
|
1480
1493
|
ripGrepArgs.push('--');
|
|
1481
1494
|
ripGrepArgs.push(searchString);
|
|
1482
1495
|
}
|
|
1483
|
-
ripGrepArgs.push('.');
|
|
1496
|
+
ripGrepArgs.push(...(paths || ['.']));
|
|
1484
1497
|
return ripGrepArgs;
|
|
1485
1498
|
};
|
|
1486
1499
|
|
|
@@ -1552,9 +1565,41 @@ const textSearch$2 = async (scheme, root, query, options, assetDir) => {
|
|
|
1552
1565
|
}
|
|
1553
1566
|
};
|
|
1554
1567
|
|
|
1568
|
+
const normalizeWindowsDrive = path => {
|
|
1569
|
+
return /^\/[A-Za-z]:\//.test(path) ? path.slice(1) : path;
|
|
1570
|
+
};
|
|
1571
|
+
const toPath = uri => {
|
|
1572
|
+
if (uri.startsWith('file://')) {
|
|
1573
|
+
return normalizeWindowsDrive(decodeURIComponent(new URL(uri).pathname)).replaceAll('\\', '/');
|
|
1574
|
+
}
|
|
1575
|
+
if (/^[A-Za-z]:[\\/]/.test(uri)) {
|
|
1576
|
+
return uri.replaceAll('\\', '/');
|
|
1577
|
+
}
|
|
1578
|
+
if (/^[A-Za-z][A-Za-z\d+.-]*:/.test(uri)) {
|
|
1579
|
+
return '';
|
|
1580
|
+
}
|
|
1581
|
+
return uri.replaceAll('\\', '/');
|
|
1582
|
+
};
|
|
1583
|
+
const getOpenEditorPaths = (root, openEditorUris) => {
|
|
1584
|
+
const rootPath = toPath(root).replace(/\/$/, '');
|
|
1585
|
+
const rootPrefix = `${rootPath}/`;
|
|
1586
|
+
const paths = openEditorUris.map(toPath).filter(path => path.startsWith(rootPrefix)).map(path => path.slice(rootPrefix.length));
|
|
1587
|
+
return [...new Set(paths)];
|
|
1588
|
+
};
|
|
1589
|
+
|
|
1555
1590
|
const textSearch$1 = async (scheme, root, query, options, assetDir, _platform, searchId, uid) => {
|
|
1591
|
+
const openEditorPaths = options.openEditorUris ? getOpenEditorPaths(root, options.openEditorUris) : undefined;
|
|
1592
|
+
if (openEditorPaths && openEditorPaths.length === 0) {
|
|
1593
|
+
return {
|
|
1594
|
+
limitHit: false,
|
|
1595
|
+
results: []
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1556
1598
|
const ripGrepArgs = getRipGrepArgs({
|
|
1557
1599
|
...options,
|
|
1600
|
+
...(openEditorPaths && {
|
|
1601
|
+
paths: openEditorPaths
|
|
1602
|
+
}),
|
|
1558
1603
|
searchString: query
|
|
1559
1604
|
});
|
|
1560
1605
|
if (options.usePullBasedSearch && searchId && (scheme === '' || scheme === 'file')) {
|