@lvce-editor/text-search-worker 7.22.0 → 7.23.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.
@@ -63,7 +63,7 @@ class AssertionError extends Error {
63
63
  const Object$1 = 1;
64
64
  const Number = 2;
65
65
  const Array$1 = 3;
66
- const String = 4;
66
+ const String$1 = 4;
67
67
  const Boolean$1 = 5;
68
68
  const Function = 6;
69
69
  const Null = 7;
@@ -75,7 +75,7 @@ const getType = value => {
75
75
  case 'function':
76
76
  return Function;
77
77
  case 'string':
78
- return String;
78
+ return String$1;
79
79
  case 'object':
80
80
  if (value === null) {
81
81
  return Null;
@@ -92,7 +92,7 @@ const getType = value => {
92
92
  };
93
93
  const string = value => {
94
94
  const type = getType(value);
95
- if (type !== String) {
95
+ if (type !== String$1) {
96
96
  throw new AssertionError('expected value to be of type string');
97
97
  }
98
98
  };
@@ -738,9 +738,12 @@ const applyDataProperties = (restoredError, error) => {
738
738
  writable: true
739
739
  });
740
740
  }
741
- if (error.data.type) {
742
- // @ts-ignore
743
- restoredError.name = error.data.type;
741
+ const name = error.data.name || error.data.type;
742
+ if (name) {
743
+ Object.defineProperty(restoredError, 'name', {
744
+ configurable: true,
745
+ value: name
746
+ });
744
747
  }
745
748
  };
746
749
  const applyDirectProperties = (restoredError, error) => {
@@ -757,7 +760,7 @@ const applyDirectProperties = (restoredError, error) => {
757
760
  }
758
761
  };
759
762
  const restoreMessageError = (error, _currentStack) => {
760
- const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
763
+ const restoredError = constructError(error.message, error.type || error.data?.type, error.name || error.data?.name);
761
764
  if (typeof error.code === 'string' || typeof error.code === 'number') {
762
765
  Object.defineProperty(restoredError, 'code', {
763
766
  configurable: true,
@@ -772,6 +775,23 @@ const restoreMessageError = (error, _currentStack) => {
772
775
  }
773
776
  return restoredError;
774
777
  };
778
+ const getFallbackMessage = error => {
779
+ if (error && typeof error.message === 'string' && error.message) {
780
+ return error.message;
781
+ }
782
+ if (error && error.data) {
783
+ return getFallbackMessage(error.data);
784
+ }
785
+ const stringified = String(error);
786
+ if (stringified !== '[object Object]') {
787
+ return stringified;
788
+ }
789
+ try {
790
+ return JSON.stringify(error);
791
+ } catch {
792
+ return stringified;
793
+ }
794
+ };
775
795
  const restoreJsonRpcError = error => {
776
796
  const currentStack = getCurrentStack();
777
797
  if (error && error instanceof Error) {
@@ -780,13 +800,13 @@ const restoreJsonRpcError = error => {
780
800
  if (error && error.code && error.code === MethodNotFound) {
781
801
  return restoreMethodNotFoundError(error, currentStack);
782
802
  }
803
+ if (error && error.error) {
804
+ return restoreJsonRpcError(error.error);
805
+ }
783
806
  if (error && error.message) {
784
807
  return restoreMessageError(error);
785
808
  }
786
- if (typeof error === 'string') {
787
- return new Error(`JsonRpc Error: ${error}`);
788
- }
789
- return new Error(`JsonRpc Error: ${error}`);
809
+ return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
790
810
  };
791
811
  const unwrapJsonRpcResult = responseMessage => {
792
812
  if ('error' in responseMessage) {
@@ -950,6 +970,12 @@ const handleJsonRpcMessage = async (...args) => {
950
970
  requiresSocket,
951
971
  resolve
952
972
  } = options;
973
+ if (message === 'ready') {
974
+ return;
975
+ }
976
+ if (!message || typeof message !== 'object') {
977
+ throw new JsonRpcError('unexpected message');
978
+ }
953
979
  if ('id' in message) {
954
980
  if ('method' in message) {
955
981
  const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
@@ -1067,6 +1093,9 @@ const logError = () => {
1067
1093
  // handled by renderer worker
1068
1094
  };
1069
1095
  const handleMessage = event => {
1096
+ if (event.data === 'ready') {
1097
+ return Promise.resolve();
1098
+ }
1070
1099
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
1071
1100
  const actualExecute = event?.target?.execute || execute;
1072
1101
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
@@ -1366,6 +1395,12 @@ const {
1366
1395
  invokeAndTransfer,
1367
1396
  set: set$3
1368
1397
  } = create(RendererWorker);
1398
+ const initializeRendererWorkerForWorker = async commandMap => {
1399
+ const rpc = await create$1({
1400
+ commandMap
1401
+ });
1402
+ set$3(rpc);
1403
+ };
1369
1404
  const sendMessagePortToSearchProcess = async port => {
1370
1405
  await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1371
1406
  };
@@ -1505,12 +1540,11 @@ const getContextArgs = contextLines => {
1505
1540
  }
1506
1541
  return [];
1507
1542
  };
1508
- const trimPart = part => {
1509
- return part.trim();
1510
- };
1543
+
1511
1544
  const hasGlob = pattern => {
1512
1545
  return pattern.includes('*') || pattern.includes('?') || pattern.includes('[') || pattern.includes('{');
1513
1546
  };
1547
+
1514
1548
  const toGlob = pattern => {
1515
1549
  const args = ['--glob', pattern];
1516
1550
  if (!hasGlob(pattern)) {
@@ -1521,9 +1555,15 @@ const toGlob = pattern => {
1521
1555
  }
1522
1556
  return args;
1523
1557
  };
1558
+
1559
+ const trimPart = part => {
1560
+ return part.trim();
1561
+ };
1562
+
1524
1563
  const getIncludeArgs = include => {
1525
1564
  return (include || '').split(',').map(trimPart).filter(Boolean).flatMap(toGlob);
1526
1565
  };
1566
+
1527
1567
  const getRipGrepArgs = ({
1528
1568
  contextLines,
1529
1569
  defaultExcludes,
@@ -1635,23 +1675,6 @@ const textSearch$3 = async (scheme, root, query) => {
1635
1675
  };
1636
1676
  };
1637
1677
 
1638
- const textSearch$2 = async (scheme, root, query, options, assetDir) => {
1639
- try {
1640
- // @ts-ignore
1641
- const result = await invoke$3('ExtensionHostTextSearch.textSearchMemory2', scheme, root, query, options, assetDir);
1642
- if (!result || !result.results) {
1643
- throw new Error(`new api not supported`);
1644
- }
1645
- return result;
1646
- } catch {
1647
- const results = await invoke$3('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
1648
- return {
1649
- limitHit: false,
1650
- results
1651
- };
1652
- }
1653
- };
1654
-
1655
1678
  const windowsDrivePathRegex = /^\/[A-Za-z]:\//;
1656
1679
  const windowsDriveRegex = /^[A-Za-z]:[\\/]/;
1657
1680
  const uriSchemeRegex = /^[A-Za-z][A-Za-z\d+.-]*:/;
@@ -1659,25 +1682,69 @@ const trailingSlashRegex = /\/$/;
1659
1682
  const normalizeWindowsDrive = path => {
1660
1683
  return windowsDrivePathRegex.test(path) ? path.slice(1) : path;
1661
1684
  };
1662
- const toPath = uri => {
1663
- if (uri.startsWith('file://')) {
1664
- return normalizeWindowsDrive(decodeURIComponent(new URL(uri).pathname)).replaceAll('\\', '/');
1665
- }
1685
+ const toPath = (uri, expectedUrl) => {
1666
1686
  if (windowsDriveRegex.test(uri)) {
1667
1687
  return uri.replaceAll('\\', '/');
1668
1688
  }
1689
+ if (URL.canParse(uri)) {
1690
+ const url = new URL(uri);
1691
+ if (expectedUrl && (url.protocol !== expectedUrl.protocol || url.host !== expectedUrl.host)) {
1692
+ return '';
1693
+ }
1694
+ if (url.protocol === 'file:' || expectedUrl) {
1695
+ return normalizeWindowsDrive(decodeURIComponent(url.pathname)).replaceAll('\\', '/');
1696
+ }
1697
+ return '';
1698
+ }
1669
1699
  if (uriSchemeRegex.test(uri)) {
1670
1700
  return '';
1671
1701
  }
1672
1702
  return uri.replaceAll('\\', '/');
1673
1703
  };
1674
1704
  const getOpenEditorPaths = (root, openEditorUris) => {
1675
- const rootPath = toPath(root).replace(trailingSlashRegex, '');
1705
+ const rootUrl = URL.canParse(root) ? new URL(root) : undefined;
1706
+ const rootPath = toPath(root, rootUrl).replace(trailingSlashRegex, '');
1676
1707
  const rootPrefix = `${rootPath}/`;
1677
- const paths = openEditorUris.map(toPath).filter(path => path.startsWith(rootPrefix)).map(path => path.slice(rootPrefix.length));
1708
+ const paths = openEditorUris.map(uri => toPath(uri, rootUrl)).filter(path => path.startsWith(rootPrefix)).map(path => path.slice(rootPrefix.length));
1678
1709
  return [...new Set(paths)];
1679
1710
  };
1680
1711
 
1712
+ const File = 1;
1713
+
1714
+ const filterOpenEditorResults = (root, results, openEditorUris) => {
1715
+ const openEditorPaths = new Set(getOpenEditorPaths(root, openEditorUris));
1716
+ let isOpenEditor = false;
1717
+ return results.filter(result => {
1718
+ if (result.type === File) {
1719
+ isOpenEditor = openEditorPaths.has(result.text);
1720
+ }
1721
+ return isOpenEditor;
1722
+ });
1723
+ };
1724
+ const textSearch$2 = async (scheme, root, query, options, assetDir) => {
1725
+ try {
1726
+ // @ts-ignore
1727
+ const result = await invoke$3('ExtensionHostTextSearch.textSearchMemory2', scheme, root, query, options, assetDir);
1728
+ if (!result || !result.results) {
1729
+ throw new Error(`new api not supported`);
1730
+ }
1731
+ if (options.openEditorUris) {
1732
+ return {
1733
+ ...result,
1734
+ results: filterOpenEditorResults(root, result.results, options.openEditorUris)
1735
+ };
1736
+ }
1737
+ return result;
1738
+ } catch {
1739
+ const results = await invoke$3('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
1740
+ const filteredResults = options.openEditorUris ? filterOpenEditorResults(root, results, options.openEditorUris) : results;
1741
+ return {
1742
+ limitHit: false,
1743
+ results: filteredResults
1744
+ };
1745
+ }
1746
+ };
1747
+
1681
1748
  const textSearch$1 = async (scheme, root, query, options, assetDir, _platform, searchId, uid) => {
1682
1749
  const openEditorPaths = options.openEditorUris ? getOpenEditorPaths(root, options.openEditorUris) : undefined;
1683
1750
  if (openEditorPaths && openEditorPaths.length === 0) {
@@ -1736,16 +1803,10 @@ const textSearchProviderMap = {
1736
1803
  web: textSearch
1737
1804
  };
1738
1805
 
1739
- const initializeRendererWorker = async () => {
1740
- const rpc = await create$1({
1741
- commandMap: commandMapRef
1742
- });
1743
- set$3(rpc);
1744
- };
1745
1806
  const listen = async () => {
1746
1807
  Object.assign(commandMapRef, commandMap);
1747
1808
  add(textSearchProviderMap);
1748
- await initializeRendererWorker();
1809
+ await initializeRendererWorkerForWorker(commandMapRef);
1749
1810
  };
1750
1811
 
1751
1812
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "7.22.0",
3
+ "version": "7.23.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"