@lvce-editor/text-search-worker 7.22.1 → 7.24.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
  };
@@ -1402,11 +1437,11 @@ const invoke = async (method, ...params) => {
1402
1437
  };
1403
1438
 
1404
1439
  const getIncrementalResults = async (searchId, minLineY, maxLineY) => {
1405
- return invoke('TextSearch.getIncrementalResults', searchId, minLineY, maxLineY);
1440
+ return await invoke('TextSearch.getIncrementalResults', searchId, minLineY, maxLineY);
1406
1441
  };
1407
1442
 
1408
1443
  const getPullResults = async searchId => {
1409
- return invoke('TextSearch.getPullResults', searchId);
1444
+ return await invoke('TextSearch.getPullResults', searchId);
1410
1445
  };
1411
1446
 
1412
1447
  const commandMapRef = Object.create(null);
@@ -1449,7 +1484,6 @@ const launchSearchProcessNode = async () => {
1449
1484
  }
1450
1485
  return create$2({
1451
1486
  commandMap: commandMapRef,
1452
- // @ts-ignore
1453
1487
  type: 'search-process'
1454
1488
  });
1455
1489
  };
@@ -1471,7 +1505,7 @@ const initialize = async platform => {
1471
1505
 
1472
1506
  const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
1473
1507
  const getProtocol = uri => {
1474
- const protocolMatch = uri.match(RE_PROTOCOL);
1508
+ const protocolMatch = RE_PROTOCOL.exec(uri);
1475
1509
  if (protocolMatch) {
1476
1510
  return protocolMatch[1];
1477
1511
  }
@@ -1505,12 +1539,11 @@ const getContextArgs = contextLines => {
1505
1539
  }
1506
1540
  return [];
1507
1541
  };
1508
- const trimPart = part => {
1509
- return part.trim();
1510
- };
1542
+
1511
1543
  const hasGlob = pattern => {
1512
1544
  return pattern.includes('*') || pattern.includes('?') || pattern.includes('[') || pattern.includes('{');
1513
1545
  };
1546
+
1514
1547
  const toGlob = pattern => {
1515
1548
  const args = ['--glob', pattern];
1516
1549
  if (!hasGlob(pattern)) {
@@ -1521,9 +1554,15 @@ const toGlob = pattern => {
1521
1554
  }
1522
1555
  return args;
1523
1556
  };
1557
+
1558
+ const trimPart = part => {
1559
+ return part.trim();
1560
+ };
1561
+
1524
1562
  const getIncludeArgs = include => {
1525
1563
  return (include || '').split(',').map(trimPart).filter(Boolean).flatMap(toGlob);
1526
1564
  };
1565
+
1527
1566
  const getRipGrepArgs = ({
1528
1567
  contextLines,
1529
1568
  defaultExcludes,
@@ -1651,7 +1690,7 @@ const toPath = (uri, expectedUrl) => {
1651
1690
  if (expectedUrl && (url.protocol !== expectedUrl.protocol || url.host !== expectedUrl.host)) {
1652
1691
  return '';
1653
1692
  }
1654
- if (url.protocol === 'file:' || expectedUrl) {
1693
+ if (expectedUrl || url.protocol === 'file:') {
1655
1694
  return normalizeWindowsDrive(decodeURIComponent(url.pathname)).replaceAll('\\', '/');
1656
1695
  }
1657
1696
  return '';
@@ -1683,7 +1722,6 @@ const filterOpenEditorResults = (root, results, openEditorUris) => {
1683
1722
  };
1684
1723
  const textSearch$2 = async (scheme, root, query, options, assetDir) => {
1685
1724
  try {
1686
- // @ts-ignore
1687
1725
  const result = await invoke$3('ExtensionHostTextSearch.textSearchMemory2', scheme, root, query, options, assetDir);
1688
1726
  if (!result || !result.results) {
1689
1727
  throw new Error(`new api not supported`);
@@ -1720,7 +1758,7 @@ const textSearch$1 = async (scheme, root, query, options, assetDir, _platform, s
1720
1758
  }),
1721
1759
  searchString: query
1722
1760
  });
1723
- if (options.usePullBasedSearch && searchId && (scheme === '' || scheme === 'file')) {
1761
+ if (searchId && options.usePullBasedSearch && (scheme === '' || scheme === 'file')) {
1724
1762
  const pullSearchOptions = {
1725
1763
  ripGrepArgs,
1726
1764
  searchDir: root,
@@ -1763,16 +1801,10 @@ const textSearchProviderMap = {
1763
1801
  web: textSearch
1764
1802
  };
1765
1803
 
1766
- const initializeRendererWorker = async () => {
1767
- const rpc = await create$1({
1768
- commandMap: commandMapRef
1769
- });
1770
- set$3(rpc);
1771
- };
1772
1804
  const listen = async () => {
1773
1805
  Object.assign(commandMapRef, commandMap);
1774
1806
  add(textSearchProviderMap);
1775
- await initializeRendererWorker();
1807
+ await initializeRendererWorkerForWorker(commandMapRef);
1776
1808
  };
1777
1809
 
1778
1810
  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.1",
3
+ "version": "7.24.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"