@lvce-editor/problems-view 1.25.0 → 1.25.1

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.
@@ -1284,6 +1284,10 @@ const {
1284
1284
  invoke: invoke$1,
1285
1285
  set: set$3
1286
1286
  } = create$1(EditorWorker$1);
1287
+ const getUri$1 = async editorUid => {
1288
+ // @ts-ignore
1289
+ return invoke$1('Editor.getUri', editorUid);
1290
+ };
1287
1291
  const getProblems$2 = async () => {
1288
1292
  // @ts-ignore
1289
1293
  return invoke$1('Editor.getProblems');
@@ -1292,6 +1296,7 @@ const getProblems$2 = async () => {
1292
1296
  const EditorWorker = {
1293
1297
  __proto__: null,
1294
1298
  getProblems: getProblems$2,
1299
+ getUri: getUri$1,
1295
1300
  invoke: invoke$1,
1296
1301
  set: set$3
1297
1302
  };
@@ -1315,9 +1320,13 @@ const sendMessagePortToEditorWorker$1 = async (port, rpcId) => {
1315
1320
  const writeClipBoardText$1 = async text => {
1316
1321
  await invoke('ClipBoard.writeText', /* text */text);
1317
1322
  };
1323
+ const getActiveEditorId$1 = () => {
1324
+ return invoke('GetActiveEditor.getActiveEditorId');
1325
+ };
1318
1326
 
1319
1327
  const RendererWorker = {
1320
1328
  __proto__: null,
1329
+ getActiveEditorId: getActiveEditorId$1,
1321
1330
  invoke,
1322
1331
  invokeAndTransfer,
1323
1332
  sendMessagePortToEditorWorker: sendMessagePortToEditorWorker$1,
@@ -1327,6 +1336,7 @@ const RendererWorker = {
1327
1336
  };
1328
1337
 
1329
1338
  const {
1339
+ getActiveEditorId,
1330
1340
  sendMessagePortToEditorWorker,
1331
1341
  set: set$1,
1332
1342
  writeClipBoardText
@@ -1364,6 +1374,7 @@ const List = 2;
1364
1374
 
1365
1375
  const create = (id, uri, x, y, width, height, workspaceUri) => {
1366
1376
  const state = {
1377
+ activeUri: '',
1367
1378
  collapsedUris: [],
1368
1379
  filteredProblems: [],
1369
1380
  filterValue: '',
@@ -1395,7 +1406,7 @@ const isEqual$1 = (oldState, newState) => {
1395
1406
  };
1396
1407
 
1397
1408
  const isEqual = (oldState, newState) => {
1398
- return oldState.problems === newState.problems && oldState.filterValue === newState.filterValue && oldState.message === newState.message && oldState.viewMode === newState.viewMode;
1409
+ return oldState.activeUri === newState.activeUri && oldState.problems === newState.problems && oldState.filterValue === newState.filterValue && oldState.message === newState.message && oldState.viewMode === newState.viewMode;
1399
1410
  };
1400
1411
 
1401
1412
  const RenderItems = 1;
@@ -1584,22 +1595,29 @@ const showInfos = () => {
1584
1595
  return i18nString(ShowInfos);
1585
1596
  };
1586
1597
 
1587
- const getMenuEntriesFilter = state => [{
1588
- command: '-1',
1589
- flags: state.showErrors ? Checked : Unchecked,
1590
- id: 'show-errors',
1591
- label: showErrors()
1592
- }, {
1593
- command: '-1',
1594
- flags: state.showWarnings ? Checked : Unchecked,
1595
- id: 'show-warnings',
1596
- label: showWarnings()
1597
- }, {
1598
- command: '-1',
1599
- flags: state.showInfos ? Checked : Unchecked,
1600
- id: 'show-infos',
1601
- label: showInfos()
1602
- }];
1598
+ const getMenuEntriesFilter = state => {
1599
+ const {
1600
+ showErrors: showErrors$1,
1601
+ showInfos: showInfos$1,
1602
+ showWarnings: showWarnings$1
1603
+ } = state;
1604
+ return [{
1605
+ command: '-1',
1606
+ flags: showErrors$1 ? Checked : Unchecked,
1607
+ id: 'show-errors',
1608
+ label: showErrors()
1609
+ }, {
1610
+ command: '-1',
1611
+ flags: showWarnings$1 ? Checked : Unchecked,
1612
+ id: 'show-warnings',
1613
+ label: showWarnings()
1614
+ }, {
1615
+ command: '-1',
1616
+ flags: showInfos$1 ? Checked : Unchecked,
1617
+ id: 'show-infos',
1618
+ label: showInfos()
1619
+ }];
1620
+ };
1603
1621
 
1604
1622
  const getMenuEntries2 = (state, props) => {
1605
1623
  const {
@@ -1617,10 +1635,152 @@ const getMenuIds = () => {
1617
1635
  return [ProblemsFilter$1];
1618
1636
  };
1619
1637
 
1638
+ const {
1639
+ getProblems: getProblems$1,
1640
+ getUri} = EditorWorker;
1641
+
1620
1642
  const Item = 0;
1621
1643
  const Expanded = 1;
1622
1644
  const Collapsed = 2;
1623
1645
 
1646
+ const toProblem = (diagnostic, index) => {
1647
+ const {
1648
+ code,
1649
+ columnIndex,
1650
+ message,
1651
+ rowIndex,
1652
+ source,
1653
+ type,
1654
+ uri
1655
+ } = diagnostic;
1656
+ return {
1657
+ code: code || '',
1658
+ columnIndex: columnIndex || 0,
1659
+ count: 0,
1660
+ fileName: '',
1661
+ level: 2,
1662
+ listItemType: Item,
1663
+ message: message || '',
1664
+ posInSet: index,
1665
+ relativePath: '',
1666
+ rowIndex: rowIndex || 0,
1667
+ setSize: 1,
1668
+ source: source || '',
1669
+ type: type || 'error',
1670
+ uri
1671
+ };
1672
+ };
1673
+ const getRelativeParentUri = (uri, workspaceUri) => {
1674
+ const slashIndex = uri.lastIndexOf('/');
1675
+ return uri.slice(0, slashIndex).slice(workspaceUri.length);
1676
+ };
1677
+ const getFileName = uri => {
1678
+ const slashIndex = uri.lastIndexOf('/');
1679
+ return uri.slice(slashIndex + 1);
1680
+ };
1681
+ const toProblems = (diagnostics, workspaceUri = '') => {
1682
+ const problems = [];
1683
+ let problem = {
1684
+ code: '',
1685
+ columnIndex: 0,
1686
+ count: 0,
1687
+ fileName: '',
1688
+ level: 0,
1689
+ listItemType: 0,
1690
+ message: '',
1691
+ posInSet: 0,
1692
+ relativePath: '',
1693
+ rowIndex: 0,
1694
+ setSize: 0,
1695
+ source: '',
1696
+ type: '',
1697
+ uri: ''
1698
+ };
1699
+ let relativeIndex = 0;
1700
+ for (const diagnostic of diagnostics) {
1701
+ if (diagnostic.uri === problem.uri) {
1702
+ relativeIndex++;
1703
+ problem.count++;
1704
+ } else {
1705
+ relativeIndex = 1;
1706
+ problem = {
1707
+ code: '',
1708
+ columnIndex: 0,
1709
+ count: 1,
1710
+ fileName: '',
1711
+ level: 1,
1712
+ listItemType: Expanded,
1713
+ message: '',
1714
+ posInSet: relativeIndex,
1715
+ relativePath: '',
1716
+ rowIndex: 0,
1717
+ setSize: 123,
1718
+ source: '',
1719
+ type: '',
1720
+ uri: diagnostic.uri
1721
+ };
1722
+ problems.push(problem);
1723
+ }
1724
+ problems.push(toProblem(diagnostic, relativeIndex));
1725
+ }
1726
+ for (const problem of problems) {
1727
+ // TODO maybe rename property, this should be the relative path of the parent folder of the file
1728
+ // @ts-ignore
1729
+ problem.relativePath = getRelativeParentUri(problem.uri, workspaceUri);
1730
+ // @ts-ignore
1731
+ problem.fileName = getFileName(problem.uri);
1732
+ // problem.uri = problem.uri // TODO
1733
+ }
1734
+ return problems;
1735
+ };
1736
+
1737
+ const getProblems = async (workspaceUri, activeUri) => {
1738
+ if (!activeUri) {
1739
+ return {
1740
+ error: '',
1741
+ problems: []
1742
+ };
1743
+ }
1744
+ try {
1745
+ const diagnostics = await getProblems$1();
1746
+ const activeDiagnostics = diagnostics.filter(diagnostic => diagnostic.uri === activeUri);
1747
+ // @ts-ignore
1748
+ const problems = toProblems(activeDiagnostics, workspaceUri);
1749
+ return {
1750
+ error: '',
1751
+ problems
1752
+ };
1753
+ } catch (error) {
1754
+ return {
1755
+ error: `${error}`,
1756
+ problems: []
1757
+ };
1758
+ }
1759
+ };
1760
+
1761
+ const handleActiveEditorChange = async (state, activeUri) => {
1762
+ const {
1763
+ activeUri: oldActiveUri,
1764
+ workspaceUri
1765
+ } = state;
1766
+ if (activeUri === oldActiveUri) {
1767
+ return state;
1768
+ }
1769
+ const {
1770
+ error,
1771
+ problems
1772
+ } = await getProblems(workspaceUri, activeUri);
1773
+ return {
1774
+ ...state,
1775
+ activeUri,
1776
+ filteredProblems: problems,
1777
+ inputSource: Script,
1778
+ listItems: [],
1779
+ message: error || getMessage(problems.length),
1780
+ problems
1781
+ };
1782
+ };
1783
+
1624
1784
  const getArrowLeftNewFocusedIndex = (problems, collapsedUris, focusedIndex) => {
1625
1785
  for (let i = focusedIndex; i >= 0; i--) {
1626
1786
  const problem = problems[i];
@@ -1759,9 +1919,12 @@ const handleFilterInput = (state, value, inputSource = Script) => {
1759
1919
  };
1760
1920
 
1761
1921
  const handleIconThemeChange = state => {
1922
+ const {
1923
+ problems
1924
+ } = state;
1762
1925
  return {
1763
1926
  ...state,
1764
- problems: [...state.problems]
1927
+ problems: [...problems]
1765
1928
  };
1766
1929
  };
1767
1930
 
@@ -1769,117 +1932,12 @@ const initialize = async () => {
1769
1932
  // function is not needed anymore
1770
1933
  };
1771
1934
 
1772
- const {
1773
- getProblems: getProblems$1} = EditorWorker;
1774
-
1775
- const toProblem = (diagnostic, index) => {
1776
- const {
1777
- code,
1778
- columnIndex,
1779
- message,
1780
- rowIndex,
1781
- source,
1782
- type,
1783
- uri
1784
- } = diagnostic;
1785
- return {
1786
- code: code || '',
1787
- columnIndex: columnIndex || 0,
1788
- count: 0,
1789
- fileName: '',
1790
- level: 2,
1791
- listItemType: Item,
1792
- message: message || '',
1793
- posInSet: index,
1794
- relativePath: '',
1795
- rowIndex: rowIndex || 0,
1796
- setSize: 1,
1797
- source: source || '',
1798
- type: type || 'error',
1799
- uri
1800
- };
1801
- };
1802
- const getRelativeParentUri = (uri, workspaceUri) => {
1803
- const slashIndex = uri.lastIndexOf('/');
1804
- return uri.slice(0, slashIndex).slice(workspaceUri.length);
1805
- };
1806
- const getFileName = uri => {
1807
- const slashIndex = uri.lastIndexOf('/');
1808
- return uri.slice(slashIndex + 1);
1809
- };
1810
- const toProblems = (diagnostics, workspaceUri = '') => {
1811
- const problems = [];
1812
- let problem = {
1813
- code: '',
1814
- columnIndex: 0,
1815
- count: 0,
1816
- fileName: '',
1817
- level: 0,
1818
- listItemType: 0,
1819
- message: '',
1820
- posInSet: 0,
1821
- relativePath: '',
1822
- rowIndex: 0,
1823
- setSize: 0,
1824
- source: '',
1825
- type: '',
1826
- uri: ''
1827
- };
1828
- let relativeIndex = 0;
1829
- for (const diagnostic of diagnostics) {
1830
- if (diagnostic.uri === problem.uri) {
1831
- relativeIndex++;
1832
- problem.count++;
1833
- } else {
1834
- relativeIndex = 1;
1835
- problem = {
1836
- code: '',
1837
- columnIndex: 0,
1838
- count: 1,
1839
- fileName: '',
1840
- level: 1,
1841
- listItemType: Expanded,
1842
- message: '',
1843
- posInSet: relativeIndex,
1844
- relativePath: '',
1845
- rowIndex: 0,
1846
- setSize: 123,
1847
- source: '',
1848
- type: '',
1849
- uri: diagnostic.uri
1850
- };
1851
- problems.push(problem);
1852
- }
1853
- problems.push(toProblem(diagnostic, relativeIndex));
1854
- }
1855
- for (const problem of problems) {
1856
- // TODO maybe rename property, this should be the relative path of the parent folder of the file
1857
- // @ts-ignore
1858
- problem.relativePath = getRelativeParentUri(problem.uri, workspaceUri);
1859
- // @ts-ignore
1860
- problem.fileName = getFileName(problem.uri);
1861
- // problem.uri = problem.uri // TODO
1862
- }
1863
- return problems;
1864
- };
1865
-
1866
- // TODO send event listener to editor, asking to send problem updates to this worker
1867
-
1868
- const getProblems = async workspaceUri => {
1869
- try {
1870
- const diagnostics = await getProblems$1();
1871
- // @ts-ignore
1872
- const problems = toProblems(diagnostics, workspaceUri);
1873
- return {
1874
- error: '',
1875
- problems
1876
- };
1877
- } catch (error) {
1878
- return {
1879
- error: `${error}`,
1880
- problems: []
1881
- };
1935
+ const getActiveUri = async () => {
1936
+ const editorId = await getActiveEditorId();
1937
+ if (editorId === -1) {
1938
+ return '';
1882
1939
  }
1940
+ return getUri(editorId);
1883
1941
  };
1884
1942
 
1885
1943
  const getSavedViewMode = savedState => {
@@ -1904,14 +1962,21 @@ const getSavedCollapsedUris = savedState => {
1904
1962
  return [];
1905
1963
  };
1906
1964
  const loadContent = async (state, savedState) => {
1965
+ const {
1966
+ workspaceUri
1967
+ } = state;
1968
+ const activeUri = await getActiveUri();
1907
1969
  const {
1908
1970
  error,
1909
1971
  problems
1910
- } = await getProblems(state.workspaceUri);
1972
+ } = await getProblems(workspaceUri, activeUri);
1911
1973
  if (error) {
1912
1974
  return {
1913
1975
  ...state,
1914
- message: error
1976
+ activeUri,
1977
+ filteredProblems: [],
1978
+ message: error,
1979
+ problems: []
1915
1980
  };
1916
1981
  }
1917
1982
  const message = getMessage(problems.length);
@@ -1920,6 +1985,7 @@ const loadContent = async (state, savedState) => {
1920
1985
  const collapsedUris = getSavedCollapsedUris(savedState);
1921
1986
  return {
1922
1987
  ...state,
1988
+ activeUri,
1923
1989
  collapsedUris,
1924
1990
  filteredProblems: problems,
1925
1991
  filterValue,
@@ -2363,14 +2429,17 @@ const getProblemsVirtualDom$1 = (viewMode, problems, filterValue, message) => {
2363
2429
  return getProblemsListVirtualDom(problems);
2364
2430
  };
2365
2431
 
2366
- const getProblemsVirtualDom = (viewMode, problems, filterValue, isSmall, message) => {
2432
+ const Focusable = 0;
2433
+
2434
+ const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, isSmall, message) => {
2367
2435
  const baseDom = {
2368
2436
  childCount: isSmall ? 2 : 1,
2369
2437
  className: mergeClassNames(Viewlet, Problems),
2438
+ dataActiveUri: activeUri,
2370
2439
  onBlur: HandleBlur,
2371
2440
  onContextMenu: HandleContextMenu,
2372
2441
  onPointerDown: HandlePointerDown,
2373
- tabIndex: 0,
2442
+ tabIndex: Focusable,
2374
2443
  type: Div
2375
2444
  };
2376
2445
  const filterDom = isSmall ? getProblemsFilterVirtualDom({
@@ -2457,6 +2526,7 @@ const getVisibleProblems = (problems, collapsedUris, focusedIndex, filterValue)
2457
2526
 
2458
2527
  const renderItems = (oldState, newState) => {
2459
2528
  const {
2529
+ activeUri,
2460
2530
  collapsedUris,
2461
2531
  filterValue,
2462
2532
  focusedIndex,
@@ -2468,7 +2538,7 @@ const renderItems = (oldState, newState) => {
2468
2538
  } = newState;
2469
2539
  const visible = getVisibleProblems(problems, collapsedUris, focusedIndex, filterValue);
2470
2540
  const isSmall = width <= smallWidthBreakPoint;
2471
- const dom = getProblemsVirtualDom(viewMode, visible, filterValue, isSmall, message);
2541
+ const dom = getProblemsVirtualDom(activeUri, viewMode, visible, filterValue, isSmall, message);
2472
2542
  return ['Viewlet.setDom2', dom];
2473
2543
  };
2474
2544
 
@@ -2646,6 +2716,7 @@ const commandMap = {
2646
2716
  'Problems.getKeyBindings': getKeyBindings,
2647
2717
  'Problems.getMenuEntries2': wrapGetter(getMenuEntries2),
2648
2718
  'Problems.getMenuIds': getMenuIds,
2719
+ 'Problems.handleActiveEditorChange': wrapCommand(handleActiveEditorChange),
2649
2720
  'Problems.handleArrowLeft': wrapCommand(handleArrowLeft),
2650
2721
  'Problems.handleArrowRight': wrapCommand(handleArrowRight),
2651
2722
  'Problems.handleBlur': wrapCommand(handleBlur),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/problems-view",
3
- "version": "1.25.0",
3
+ "version": "1.25.1",
4
4
  "description": "Problems View Worker",
5
5
  "repository": {
6
6
  "type": "git",