@lvce-editor/status-bar-worker 3.31.1 → 3.31.3

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.
@@ -2,7 +2,7 @@ const toCommandId = key => {
2
2
  const dotIndex = key.indexOf('.');
3
3
  return key.slice(dotIndex + 1);
4
4
  };
5
- const create$8 = () => {
5
+ const create$a = () => {
6
6
  const commandQueues = new Map();
7
7
  const generations = Object.create(null);
8
8
  const states = Object.create(null);
@@ -265,12 +265,12 @@ const {
265
265
  getCommandIds,
266
266
  getKeys,
267
267
  registerCommands,
268
- set: set$6,
268
+ set: set$7,
269
269
  wrapCommand,
270
270
  wrapGetter,
271
- wrapSerialAsyncCommand} = create$8();
271
+ wrapSerialAsyncCommand} = create$a();
272
272
 
273
- const create$7 = (uid, uri, x, y, width, height, platform, assetDir) => {
273
+ const create$9 = (uid, uri, x, y, width, height, platform, assetDir) => {
274
274
  const state = {
275
275
  assetDir,
276
276
  errorCount: 0,
@@ -281,7 +281,7 @@ const create$7 = (uid, uri, x, y, width, height, platform, assetDir) => {
281
281
  uid,
282
282
  warningCount: 0
283
283
  };
284
- set$6(uid, state, state);
284
+ set$7(uid, state, state);
285
285
  };
286
286
 
287
287
  const isEqual = (oldState, newState) => {
@@ -641,6 +641,53 @@ const getMatchingItem = (itemsLeft, itemsRight, name) => {
641
641
  return getMatchingItemInternal(itemsLeft, name) ?? getMatchingItemInternal(itemsRight, name);
642
642
  };
643
643
 
644
+ const EditorEncoding = 'EditorEncoding';
645
+ const EditorEndOfLine = 'EditorEndOfLine';
646
+ const EditorIndentation = 'EditorIndentation';
647
+ const EditorLanguage = 'EditorLanguage';
648
+ const EditorPosition = 'EditorPosition';
649
+ const Notifications = 'Notifications';
650
+ const Problems = 'Problems';
651
+ const isEditorStatus = name => {
652
+ return [EditorEncoding, EditorEndOfLine, EditorIndentation, EditorLanguage, EditorPosition].includes(name);
653
+ };
654
+ const isRight = name => {
655
+ return name === Notifications || isEditorStatus(name);
656
+ };
657
+
658
+ const state$1 = {
659
+ rpc: undefined
660
+ };
661
+ const set$6 = rpc => {
662
+ state$1.rpc = rpc;
663
+ };
664
+ const invoke$4 = (method, ...args) => {
665
+ const {
666
+ rpc
667
+ } = state$1;
668
+ return rpc.invoke(method, ...args);
669
+ };
670
+
671
+ const handleClickEditorStatus = async (name, status) => {
672
+ if (!status) {
673
+ return;
674
+ }
675
+ switch (name) {
676
+ case EditorEndOfLine:
677
+ await invoke$4('QuickPick.openStatusBarPicker', 'end-of-line');
678
+ return;
679
+ case EditorIndentation:
680
+ await invoke$4('QuickPick.openStatusBarPicker', 'indentation');
681
+ return;
682
+ case EditorLanguage:
683
+ await invoke$4('QuickPick.openStatusBarPicker', 'language-mode');
684
+ return;
685
+ case EditorPosition:
686
+ await invoke$4('QuickPick.openStatusBarPicker', 'go-to-line', status.line, status.column);
687
+ return;
688
+ }
689
+ };
690
+
644
691
  const normalizeLine = line => {
645
692
  if (line.startsWith('Error: ')) {
646
693
  return line.slice('Error: '.length);
@@ -1352,6 +1399,23 @@ const restoreMessageError = (error, _currentStack) => {
1352
1399
  }
1353
1400
  return restoredError;
1354
1401
  };
1402
+ const getFallbackMessage = error => {
1403
+ if (error && typeof error.message === 'string' && error.message) {
1404
+ return error.message;
1405
+ }
1406
+ if (error && error.data) {
1407
+ return getFallbackMessage(error.data);
1408
+ }
1409
+ const stringified = String(error);
1410
+ if (stringified !== '[object Object]') {
1411
+ return stringified;
1412
+ }
1413
+ try {
1414
+ return JSON.stringify(error);
1415
+ } catch {
1416
+ return stringified;
1417
+ }
1418
+ };
1355
1419
  const restoreJsonRpcError = error => {
1356
1420
  const currentStack = getCurrentStack();
1357
1421
  if (error && error instanceof Error) {
@@ -1360,13 +1424,13 @@ const restoreJsonRpcError = error => {
1360
1424
  if (error && error.code && error.code === MethodNotFound) {
1361
1425
  return restoreMethodNotFoundError(error, currentStack);
1362
1426
  }
1427
+ if (error && error.error) {
1428
+ return restoreJsonRpcError(error.error);
1429
+ }
1363
1430
  if (error && error.message) {
1364
1431
  return restoreMessageError(error);
1365
1432
  }
1366
- if (typeof error === 'string') {
1367
- return new Error(`JsonRpc Error: ${error}`);
1368
- }
1369
- return new Error(`JsonRpc Error: ${error}`);
1433
+ return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
1370
1434
  };
1371
1435
  const unwrapJsonRpcResult = responseMessage => {
1372
1436
  if ('error' in responseMessage) {
@@ -1445,7 +1509,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
1445
1509
  const errorProperty = getErrorProperty(error, prettyError);
1446
1510
  return create$1$1(id, errorProperty);
1447
1511
  };
1448
- const create$6 = (message, result) => {
1512
+ const create$8 = (message, result) => {
1449
1513
  return {
1450
1514
  id: message.id,
1451
1515
  jsonrpc: Two$1,
@@ -1454,7 +1518,7 @@ const create$6 = (message, result) => {
1454
1518
  };
1455
1519
  const getSuccessResponse = (message, result) => {
1456
1520
  const resultProperty = result ?? null;
1457
- return create$6(message, resultProperty);
1521
+ return create$8(message, resultProperty);
1458
1522
  };
1459
1523
  const getErrorResponseSimple = (id, error) => {
1460
1524
  return {
@@ -1553,7 +1617,7 @@ const handleJsonRpcMessage = async (...args) => {
1553
1617
 
1554
1618
  const Two = '2.0';
1555
1619
 
1556
- const create$5 = (method, params) => {
1620
+ const create$7 = (method, params) => {
1557
1621
  return {
1558
1622
  jsonrpc: Two,
1559
1623
  method,
@@ -1561,7 +1625,7 @@ const create$5 = (method, params) => {
1561
1625
  };
1562
1626
  };
1563
1627
 
1564
- const create$4 = (id, method, params) => {
1628
+ const create$6 = (id, method, params) => {
1565
1629
  const message = {
1566
1630
  id,
1567
1631
  jsonrpc: Two,
@@ -1572,12 +1636,12 @@ const create$4 = (id, method, params) => {
1572
1636
  };
1573
1637
 
1574
1638
  let id = 0;
1575
- const create$3 = () => {
1639
+ const create$5 = () => {
1576
1640
  return ++id;
1577
1641
  };
1578
1642
 
1579
1643
  const registerPromise = map => {
1580
- const id = create$3();
1644
+ const id = create$5();
1581
1645
  const {
1582
1646
  promise,
1583
1647
  resolve
@@ -1594,7 +1658,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
1594
1658
  id,
1595
1659
  promise
1596
1660
  } = registerPromise(callbacks);
1597
- const message = create$4(id, method, params);
1661
+ const message = create$6(id, method, params);
1598
1662
  if (useSendAndTransfer && ipc.sendAndTransfer) {
1599
1663
  ipc.sendAndTransfer(message);
1600
1664
  } else {
@@ -1630,7 +1694,7 @@ const createRpc = ipc => {
1630
1694
  * @deprecated
1631
1695
  */
1632
1696
  send(method, ...params) {
1633
- const message = create$5(method, params);
1697
+ const message = create$7(method, params);
1634
1698
  ipc.send(message);
1635
1699
  }
1636
1700
  };
@@ -1670,7 +1734,35 @@ const listen$1 = async (module, options) => {
1670
1734
  return ipc;
1671
1735
  };
1672
1736
 
1673
- const create$2 = async ({
1737
+ const createSharedLazyRpc = factory => {
1738
+ let rpcPromise;
1739
+ const getOrCreate = () => {
1740
+ if (!rpcPromise) {
1741
+ rpcPromise = factory();
1742
+ }
1743
+ return rpcPromise;
1744
+ };
1745
+ return {
1746
+ async dispose() {
1747
+ const rpc = await getOrCreate();
1748
+ await rpc.dispose();
1749
+ },
1750
+ async invoke(method, ...params) {
1751
+ const rpc = await getOrCreate();
1752
+ return rpc.invoke(method, ...params);
1753
+ },
1754
+ async invokeAndTransfer(method, ...params) {
1755
+ const rpc = await getOrCreate();
1756
+ return rpc.invokeAndTransfer(method, ...params);
1757
+ },
1758
+ async send(method, ...params) {
1759
+ const rpc = await getOrCreate();
1760
+ rpc.send(method, ...params);
1761
+ }
1762
+ };
1763
+ };
1764
+
1765
+ const create$4 = async ({
1674
1766
  commandMap,
1675
1767
  isMessagePortOpen = true,
1676
1768
  messagePort
@@ -1688,6 +1780,37 @@ const create$2 = async ({
1688
1780
  return rpc;
1689
1781
  };
1690
1782
 
1783
+ const create$3 = async ({
1784
+ commandMap,
1785
+ isMessagePortOpen,
1786
+ send
1787
+ }) => {
1788
+ const {
1789
+ port1,
1790
+ port2
1791
+ } = new MessageChannel();
1792
+ await send(port1);
1793
+ return create$4({
1794
+ commandMap,
1795
+ isMessagePortOpen,
1796
+ messagePort: port2
1797
+ });
1798
+ };
1799
+
1800
+ const create$2 = async ({
1801
+ commandMap,
1802
+ isMessagePortOpen,
1803
+ send
1804
+ }) => {
1805
+ return createSharedLazyRpc(() => {
1806
+ return create$3({
1807
+ commandMap,
1808
+ isMessagePortOpen,
1809
+ send
1810
+ });
1811
+ });
1812
+ };
1813
+
1691
1814
  const create$1 = async ({
1692
1815
  commandMap
1693
1816
  }) => {
@@ -1779,6 +1902,7 @@ const {
1779
1902
 
1780
1903
  const {
1781
1904
  invoke: invoke$1,
1905
+ invokeAndTransfer,
1782
1906
  set: set$2
1783
1907
  } = create(RendererWorker);
1784
1908
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
@@ -1792,40 +1916,6 @@ const getPreference = async key => {
1792
1916
  return await invoke$1('Preferences.get', key);
1793
1917
  };
1794
1918
 
1795
- const EditorEncoding = 'EditorEncoding';
1796
- const EditorEndOfLine = 'EditorEndOfLine';
1797
- const EditorIndentation = 'EditorIndentation';
1798
- const EditorLanguage = 'EditorLanguage';
1799
- const EditorPosition = 'EditorPosition';
1800
- const Notifications = 'Notifications';
1801
- const Problems = 'Problems';
1802
- const isEditorStatus = name => {
1803
- return [EditorEncoding, EditorEndOfLine, EditorIndentation, EditorLanguage, EditorPosition].includes(name);
1804
- };
1805
- const isRight = name => {
1806
- return name === Notifications || isEditorStatus(name);
1807
- };
1808
-
1809
- const handleClickEditorStatus = async (name, status) => {
1810
- if (!status) {
1811
- return;
1812
- }
1813
- switch (name) {
1814
- case EditorEndOfLine:
1815
- await invoke$1('Viewlet.openWidget', 'QuickPick', 'end-of-line');
1816
- return;
1817
- case EditorIndentation:
1818
- await invoke$1('Viewlet.openWidget', 'QuickPick', 'indentation');
1819
- return;
1820
- case EditorLanguage:
1821
- await invoke$1('Viewlet.openWidget', 'QuickPick', 'language-mode');
1822
- return;
1823
- case EditorPosition:
1824
- await invoke$1('Viewlet.openWidget', 'QuickPick', 'go-to-line', status.line, status.column);
1825
- return;
1826
- }
1827
- };
1828
-
1829
1919
  const handleClickExtensionStatusBarItem = async name => {
1830
1920
  try {
1831
1921
  await invoke$3('Extensions.executeCommand', name);
@@ -1840,9 +1930,7 @@ const handleClickNotification = async () => {
1840
1930
 
1841
1931
  const handleClickProblems = async () => {
1842
1932
  // @ts-ignore
1843
- await invoke$1('Layout.showPanel');
1844
- // @ts-ignore
1845
- await invoke$1('Panel.toggleView', 'Problems');
1933
+ await invoke$1('Layout.showPanel', 'Problems');
1846
1934
  };
1847
1935
 
1848
1936
  const handleClick = async (state, name) => {
@@ -2055,7 +2143,7 @@ const render2 = (uid, diffResult) => {
2055
2143
  newState,
2056
2144
  oldState
2057
2145
  } = get$5(uid);
2058
- set$6(uid, newState, newState);
2146
+ set$7(uid, newState, newState);
2059
2147
  const commands = applyRender(oldState, newState, diffResult);
2060
2148
  if (!isConnected()) {
2061
2149
  return commands;
@@ -2102,7 +2190,7 @@ const handleEditorStatusChangedAll = async update => {
2102
2190
  if (newState === newerState || oldState === newerState) {
2103
2191
  continue;
2104
2192
  }
2105
- set$6(uid, oldState, newerState);
2193
+ set$7(uid, oldState, newerState);
2106
2194
  changedUids.push(uid);
2107
2195
  }
2108
2196
  await Promise.all(changedUids.map(renderOutOfBand));
@@ -2143,7 +2231,7 @@ const handleEditorStatusVisibilityChangedAll = async visible => {
2143
2231
  if (newState === newerState || oldState === newerState) {
2144
2232
  continue;
2145
2233
  }
2146
- set$6(uid, oldState, newerState);
2234
+ set$7(uid, oldState, newerState);
2147
2235
  changedUids.push(uid);
2148
2236
  }
2149
2237
  await Promise.all(changedUids.map(renderOutOfBand));
@@ -2385,7 +2473,7 @@ const handleExtensionManagementChange = async () => {
2385
2473
  // Loading and other updates can finish while the provider query is pending.
2386
2474
  // Only replace the extension items; retain the current lifecycle and render baseline.
2387
2475
  const current = get$5(uid);
2388
- set$6(uid, current.oldState, {
2476
+ set$7(uid, current.oldState, {
2389
2477
  ...current.newState,
2390
2478
  statusBarItemsLeft: newerState.statusBarItemsLeft
2391
2479
  });
@@ -2430,7 +2518,7 @@ const handleNotificationCountChangedAll = async count => {
2430
2518
  if (newState === newerState || oldState === newerState) {
2431
2519
  continue;
2432
2520
  }
2433
- set$6(uid, oldState, newerState);
2521
+ set$7(uid, oldState, newerState);
2434
2522
  await renderOutOfBand(uid);
2435
2523
  }
2436
2524
  };
@@ -2441,7 +2529,7 @@ const commandMap$1 = {
2441
2529
  };
2442
2530
 
2443
2531
  const handleExtensionManagementMessagePort = async port => {
2444
- const rpc = await create$2({
2532
+ const rpc = await create$4({
2445
2533
  commandMap: commandMap$1,
2446
2534
  messagePort: port
2447
2535
  });
@@ -2459,7 +2547,7 @@ const handleMessagePort = async (port, viewletCommandMap, setAsRendererProcess =
2459
2547
  await fn(uid, ...args);
2460
2548
  await invoke$1('Viewlet.requestRender', uid);
2461
2549
  };
2462
- const rpc = await create$2({
2550
+ const rpc = await create$4({
2463
2551
  commandMap: {
2464
2552
  'StatusBar.handleEditorStatusChanged': handleEditorStatusChangedAll,
2465
2553
  'StatusBar.handleEditorStatusVisibilityChanged': handleEditorStatusVisibilityChangedAll,
@@ -2516,9 +2604,11 @@ const getIndex = (items, item) => {
2516
2604
 
2517
2605
  const updateArray = (items, newItem) => {
2518
2606
  const index = getIndex(items, newItem);
2519
- const before = items.slice(0, index);
2520
- const after = items.slice(index + 1);
2521
- return [...before, newItem, ...after];
2607
+ if (index < 0) {
2608
+ return [newItem, ...items];
2609
+ }
2610
+ // eslint-disable-next-line unicorn/no-confusing-array-splice -- Keep updates immutable with toSpliced.
2611
+ return items.toSpliced(index, 1, newItem);
2522
2612
  };
2523
2613
 
2524
2614
  const itemLeftUpdate = (state, newItem) => {
@@ -2687,7 +2777,7 @@ const handleWorkspaceChangeAndRefresh = async (uid, workspacePath) => {
2687
2777
  await refreshExtensionItems(uid);
2688
2778
  };
2689
2779
  const commandMap = {
2690
- 'StatusBar.create': create$7,
2780
+ 'StatusBar.create': create$9,
2691
2781
  'StatusBar.diff2': diff2,
2692
2782
  'StatusBar.getCommandIds': getCommandIds,
2693
2783
  'StatusBar.getComponentDom': getComponentDom,
@@ -2718,6 +2808,16 @@ const commandMap = {
2718
2808
  'StatusBar.terminate': terminate
2719
2809
  };
2720
2810
 
2811
+ const initializeQuickPickWorker = async () => {
2812
+ const rpc = await create$2({
2813
+ commandMap: {},
2814
+ async send(port) {
2815
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToQuickPickWorker', port, 'QuickPick.handleStatusBarMessagePort', 0);
2816
+ }
2817
+ });
2818
+ set$6(rpc);
2819
+ };
2820
+
2721
2821
  const initializeRenderWorker = async () => {
2722
2822
  const rpc = await create$1({
2723
2823
  commandMap: commandMap
@@ -2727,7 +2827,7 @@ const initializeRenderWorker = async () => {
2727
2827
 
2728
2828
  const listen = async () => {
2729
2829
  registerCommands(commandMap);
2730
- await initializeRenderWorker();
2830
+ await Promise.all([initializeRenderWorker(), initializeQuickPickWorker()]);
2731
2831
  };
2732
2832
 
2733
2833
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "3.31.1",
3
+ "version": "3.31.3",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",