@lvce-editor/problems-view 1.25.2 → 1.25.4

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.
@@ -712,7 +712,10 @@ const constructError = (message, type, name) => {
712
712
  if (ErrorConstructor === Error) {
713
713
  const error = new Error(message);
714
714
  if (name && name !== 'VError') {
715
- error.name = name;
715
+ Object.defineProperty(error, 'name', {
716
+ configurable: true,
717
+ value: name
718
+ });
716
719
  }
717
720
  return error;
718
721
  }
@@ -729,8 +732,10 @@ const getCurrentStack = () => {
729
732
  const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
730
733
  return currentStack;
731
734
  };
732
- const getNewLineIndex = (string, startIndex = undefined) => {
733
- return string.indexOf(NewLine, startIndex);
735
+ const getNewLineIndex = (string, startIndex) => {
736
+ {
737
+ return string.indexOf(NewLine);
738
+ }
734
739
  };
735
740
  const getParentStack = error => {
736
741
  let parentStack = error.stack || error.data || error.message || '';
@@ -741,55 +746,91 @@ const getParentStack = error => {
741
746
  };
742
747
  const MethodNotFound = -32601;
743
748
  const Custom = -32001;
749
+ const setStack = (error, stack) => {
750
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
751
+ if (descriptor) {
752
+ if (!descriptor.configurable && !descriptor.writable) {
753
+ return;
754
+ }
755
+ if (!descriptor.configurable && descriptor.writable) {
756
+ error.stack = stack;
757
+ return;
758
+ }
759
+ }
760
+ Object.defineProperty(error, 'stack', {
761
+ configurable: true,
762
+ value: stack,
763
+ writable: true
764
+ });
765
+ };
766
+ const restoreExistingError = (error, currentStack) => {
767
+ if (typeof error.stack === 'string') {
768
+ setStack(error, `${error.stack}${NewLine}${currentStack}`);
769
+ }
770
+ return error;
771
+ };
772
+ const restoreMethodNotFoundError = (error, currentStack) => {
773
+ const restoredError = new JsonRpcError(error.message);
774
+ const parentStack = getParentStack(error);
775
+ setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
776
+ return restoredError;
777
+ };
778
+ const restoreStackFromData = (restoredError, error, currentStack) => {
779
+ if (error.data.stack && error.data.type && error.message) {
780
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
781
+ return;
782
+ }
783
+ if (error.data.stack) {
784
+ setStack(restoredError, error.data.stack);
785
+ }
786
+ };
787
+ const applyDataProperties = (restoredError, error) => {
788
+ restoreStackFromData(restoredError, error, getCurrentStack());
789
+ if (error.data.codeFrame) {
790
+ // @ts-ignore
791
+ restoredError.codeFrame = error.data.codeFrame;
792
+ }
793
+ if (error.data.code) {
794
+ // @ts-ignore
795
+ restoredError.code = error.data.code;
796
+ }
797
+ if (error.data.type) {
798
+ // @ts-ignore
799
+ restoredError.name = error.data.type;
800
+ }
801
+ };
802
+ const applyDirectProperties = (restoredError, error) => {
803
+ if (error.stack) {
804
+ const lowerStack = restoredError.stack || '';
805
+ const indexNewLine = getNewLineIndex(lowerStack);
806
+ const parentStack = getParentStack(error);
807
+ // @ts-ignore
808
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
809
+ }
810
+ if (error.codeFrame) {
811
+ // @ts-ignore
812
+ restoredError.codeFrame = error.codeFrame;
813
+ }
814
+ };
815
+ const restoreMessageError = (error, _currentStack) => {
816
+ const restoredError = constructError(error.message, error.type, error.name);
817
+ if (error.data) {
818
+ applyDataProperties(restoredError, error);
819
+ } else {
820
+ applyDirectProperties(restoredError, error);
821
+ }
822
+ return restoredError;
823
+ };
744
824
  const restoreJsonRpcError = error => {
745
825
  const currentStack = getCurrentStack();
746
826
  if (error && error instanceof Error) {
747
- if (typeof error.stack === 'string') {
748
- error.stack = error.stack + NewLine + currentStack;
749
- }
750
- return error;
827
+ return restoreExistingError(error, currentStack);
751
828
  }
752
829
  if (error && error.code && error.code === MethodNotFound) {
753
- const restoredError = new JsonRpcError(error.message);
754
- const parentStack = getParentStack(error);
755
- restoredError.stack = parentStack + NewLine + currentStack;
756
- return restoredError;
830
+ return restoreMethodNotFoundError(error, currentStack);
757
831
  }
758
832
  if (error && error.message) {
759
- const restoredError = constructError(error.message, error.type, error.name);
760
- if (error.data) {
761
- if (error.data.stack && error.data.type && error.message) {
762
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
763
- } else if (error.data.stack) {
764
- restoredError.stack = error.data.stack;
765
- }
766
- if (error.data.codeFrame) {
767
- // @ts-ignore
768
- restoredError.codeFrame = error.data.codeFrame;
769
- }
770
- if (error.data.code) {
771
- // @ts-ignore
772
- restoredError.code = error.data.code;
773
- }
774
- if (error.data.type) {
775
- // @ts-ignore
776
- restoredError.name = error.data.type;
777
- }
778
- } else {
779
- if (error.stack) {
780
- const lowerStack = restoredError.stack || '';
781
- // @ts-ignore
782
- const indexNewLine = getNewLineIndex(lowerStack);
783
- const parentStack = getParentStack(error);
784
- // @ts-ignore
785
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
786
- }
787
- if (error.codeFrame) {
788
- // @ts-ignore
789
- restoredError.codeFrame = error.codeFrame;
790
- }
791
- }
792
- return restoredError;
833
+ return restoreMessageError(error);
793
834
  }
794
835
  if (typeof error === 'string') {
795
836
  return new Error(`JsonRpc Error: ${error}`);
@@ -1280,6 +1321,8 @@ const Unchecked = 3;
1280
1321
  const EditorWorker$1 = 99;
1281
1322
  const RendererWorker$1 = 1;
1282
1323
 
1324
+ const SetCss = 'Viewlet.setCss';
1325
+
1283
1326
  const {
1284
1327
  invoke: invoke$1,
1285
1328
  set: set$3
@@ -1401,6 +1444,10 @@ const create = (id, uri, x, y, width, height, workspaceUri) => {
1401
1444
  set(id, state, state);
1402
1445
  };
1403
1446
 
1447
+ const isEqual$2 = (oldState, newState) => {
1448
+ return oldState.collapsedUris === newState.collapsedUris && oldState.filterValue === newState.filterValue && oldState.problems === newState.problems;
1449
+ };
1450
+
1404
1451
  const isEqual$1 = (oldState, newState) => {
1405
1452
  return newState.inputSource === User || oldState.filterValue === newState.filterValue;
1406
1453
  };
@@ -1411,9 +1458,10 @@ const isEqual = (oldState, newState) => {
1411
1458
 
1412
1459
  const RenderItems = 1;
1413
1460
  const RenderFilterValue = 2;
1461
+ const RenderCss = 4;
1414
1462
 
1415
- const modules = [isEqual, isEqual$1];
1416
- const numbers = [RenderItems, RenderFilterValue];
1463
+ const modules = [isEqual, isEqual$1, isEqual$2];
1464
+ const numbers = [RenderItems, RenderFilterValue, RenderCss];
1417
1465
 
1418
1466
  const diff = (oldState, newState) => {
1419
1467
  const diffResult = [];
@@ -1670,9 +1718,22 @@ const toProblem = (diagnostic, index) => {
1670
1718
  uri
1671
1719
  };
1672
1720
  };
1721
+ const normalizeFileUri = uri => {
1722
+ const normalizedUri = uri.startsWith('file://') ? uri.slice('file://'.length) : uri;
1723
+ return /^\/[a-z]:\//i.test(normalizedUri) ? normalizedUri.slice(1) : normalizedUri;
1724
+ };
1673
1725
  const getRelativeParentUri = (uri, workspaceUri) => {
1674
- const slashIndex = uri.lastIndexOf('/');
1675
- return uri.slice(0, slashIndex).slice(workspaceUri.length);
1726
+ const normalizedUri = normalizeFileUri(uri);
1727
+ const normalizedWorkspaceUri = normalizeFileUri(workspaceUri).replace(/\/$/, '');
1728
+ const slashIndex = normalizedUri.lastIndexOf('/');
1729
+ const parentUri = normalizedUri.slice(0, slashIndex);
1730
+ if (parentUri === normalizedWorkspaceUri) {
1731
+ return '';
1732
+ }
1733
+ if (normalizedWorkspaceUri && parentUri.startsWith(`${normalizedWorkspaceUri}/`)) {
1734
+ return parentUri.slice(normalizedWorkspaceUri.length + 1);
1735
+ }
1736
+ return parentUri.replace(/^\/+/, '');
1676
1737
  };
1677
1738
  const getFileName = uri => {
1678
1739
  const slashIndex = uri.lastIndexOf('/');
@@ -1997,6 +2058,122 @@ const loadContent = async (state, savedState) => {
1997
2058
  };
1998
2059
  };
1999
2060
 
2061
+ const getIndentRule = indent => {
2062
+ return `.Indent-${indent} {
2063
+ padding-left: ${indent};
2064
+ }`;
2065
+ };
2066
+
2067
+ const defaultIndent = 1;
2068
+ const getTreeItemIndent = depth => {
2069
+ return `${depth * defaultIndent}rem`;
2070
+ };
2071
+
2072
+ const getProblemIndent = listItemType => {
2073
+ const isGroup = listItemType === Expanded || listItemType === Collapsed;
2074
+ const depth = isGroup ? 1 : 2;
2075
+ return getTreeItemIndent(depth);
2076
+ };
2077
+
2078
+ const getUniqueIndents = problems => {
2079
+ const uniqueIndents = [];
2080
+ for (const problem of problems) {
2081
+ const indent = getProblemIndent(problem.listItemType);
2082
+ if (!uniqueIndents.includes(indent)) {
2083
+ uniqueIndents.push(indent);
2084
+ }
2085
+ }
2086
+ return uniqueIndents;
2087
+ };
2088
+
2089
+ const matchesFilterValue = (string, filterValueLower) => {
2090
+ if (filterValueLower) {
2091
+ return string.toLowerCase().indexOf(filterValueLower);
2092
+ }
2093
+ return 0;
2094
+ };
2095
+
2096
+ const getListItemType = (listItemType, isCollapsed) => {
2097
+ if (listItemType === Item) {
2098
+ return Item;
2099
+ }
2100
+ if (isCollapsed) {
2101
+ return Collapsed;
2102
+ }
2103
+ return Expanded;
2104
+ };
2105
+ const filterProblems = (problems, collapsedUris, filterValue) => {
2106
+ const filterValueLower = filterValue.toLowerCase();
2107
+ const filtered = [];
2108
+ for (const problem of problems) {
2109
+ const uriMatchIndex = matchesFilterValue(problem.uri, filterValueLower);
2110
+ const sourceMatchIndex = matchesFilterValue(problem.source, filterValueLower);
2111
+ const messageMatchIndex = matchesFilterValue(problem.message, filterValueLower);
2112
+ if (uriMatchIndex === -1 && sourceMatchIndex === -1 && messageMatchIndex === -1) {
2113
+ continue;
2114
+ }
2115
+ const isCollapsed = collapsedUris.includes(problem.uri);
2116
+ if (isCollapsed && problem.listItemType === Item) {
2117
+ continue;
2118
+ }
2119
+ filtered.push({
2120
+ ...problem,
2121
+ isCollapsed,
2122
+ listItemType: getListItemType(problem.listItemType, isCollapsed),
2123
+ messageMatchIndex,
2124
+ sourceMatchIndex,
2125
+ uriMatchIndex
2126
+ });
2127
+ }
2128
+ return filtered;
2129
+ };
2130
+
2131
+ const getFileNameIcon = file => {
2132
+ return '';
2133
+ };
2134
+
2135
+ const getIcon = uri => {
2136
+ if (!uri) {
2137
+ return '';
2138
+ }
2139
+ return getFileNameIcon();
2140
+ };
2141
+
2142
+ const getVisibleProblems = (problems, collapsedUris, focusedIndex, filterValue) => {
2143
+ array(problems);
2144
+ array(collapsedUris);
2145
+ number(focusedIndex);
2146
+ string(filterValue);
2147
+ const visibleItems = [];
2148
+ const filterValueLength = filterValue.length;
2149
+ const filtered = filterProblems(problems, collapsedUris, filterValue);
2150
+ for (let i = 0; i < filtered.length; i++) {
2151
+ const problem = filtered[i];
2152
+ visibleItems.push({
2153
+ ...problem,
2154
+ filterValueLength,
2155
+ icon: getIcon(problem.uri),
2156
+ isActive: i === focusedIndex,
2157
+ isEven: i % 2 === 0
2158
+ });
2159
+ }
2160
+ return visibleItems;
2161
+ };
2162
+
2163
+ const renderCss = (oldState, newState) => {
2164
+ const {
2165
+ collapsedUris,
2166
+ filterValue,
2167
+ focusedIndex,
2168
+ problems,
2169
+ uid
2170
+ } = newState;
2171
+ const visibleProblems = getVisibleProblems(problems, collapsedUris, focusedIndex, filterValue);
2172
+ const uniqueIndents = getUniqueIndents(visibleProblems);
2173
+ const css = uniqueIndents.map(getIndentRule).join('\n');
2174
+ return [SetCss, uid, css];
2175
+ };
2176
+
2000
2177
  const Filter$2 = 'filter';
2001
2178
 
2002
2179
  const renderFilterValue = (oldState, newState) => {
@@ -2021,6 +2198,7 @@ const MessageAction = 'MessageAction';
2021
2198
  const Problem = 'Problem';
2022
2199
  const ProblemAt = 'ProblemAt';
2023
2200
  const ProblemBadge = 'ProblemBadge';
2201
+ const ProblemLabel = 'ProblemLabel';
2024
2202
  const Problems = 'Problems';
2025
2203
  const ProblemSelected = 'ProblemSelected';
2026
2204
  const ProblemsErrorIcon = 'ProblemsErrorIcon';
@@ -2198,11 +2376,6 @@ const getProblemSourceDetail = (source, code) => {
2198
2376
  return message;
2199
2377
  };
2200
2378
 
2201
- const defaultIndent = 1;
2202
- const getTreeItemIndent = depth => {
2203
- return `${depth * defaultIndent}rem`;
2204
- };
2205
-
2206
2379
  const labelNode = {
2207
2380
  childCount: 1,
2208
2381
  className: Label,
@@ -2244,6 +2417,8 @@ const getProblemVirtualDom = problem => {
2244
2417
  type
2245
2418
  } = problem;
2246
2419
  let className = Problem;
2420
+ const indent = getProblemIndent(listItemType);
2421
+ className = mergeClassNames(className, `Indent-${indent}`);
2247
2422
  if (isActive) {
2248
2423
  className = mergeClassNames(className, ProblemSelected);
2249
2424
  }
@@ -2256,7 +2431,6 @@ const getProblemVirtualDom = problem => {
2256
2431
  ariaSetSize: setSize,
2257
2432
  childCount: 5,
2258
2433
  className,
2259
- paddingLeft: getTreeItemIndent(1),
2260
2434
  role: TreeItem,
2261
2435
  type: Div
2262
2436
  }, listItemType === Collapsed ? getChevronRightVirtualDom() : getChevronDownVirtualDom(), getFileIconVirtualDom(icon), labelNode, text(fileName), labelDetailNode, text(relativePath), ...getBadgeVirtualDom(ProblemBadge, problem.count)];
@@ -2264,7 +2438,7 @@ const getProblemVirtualDom = problem => {
2264
2438
  const lineColumn = atLineColumn(rowIndex, columnIndex);
2265
2439
  const label = {
2266
2440
  childCount: 1,
2267
- className: Label,
2441
+ className: ProblemLabel,
2268
2442
  type: Div
2269
2443
  };
2270
2444
  /**
@@ -2277,7 +2451,6 @@ const getProblemVirtualDom = problem => {
2277
2451
  ariaSetSize: setSize,
2278
2452
  childCount: 3,
2279
2453
  className,
2280
- paddingLeft: getTreeItemIndent(2),
2281
2454
  role: TreeItem,
2282
2455
  type: Div
2283
2456
  }, getProblemsIconVirtualDom(type), label];
@@ -2438,80 +2611,6 @@ const getProblemsVirtualDom = (activeUri, viewMode, problems, filterValue, isSma
2438
2611
  return [baseDom, ...filterDom, ...itemsDom];
2439
2612
  };
2440
2613
 
2441
- const matchesFilterValue = (string, filterValueLower) => {
2442
- if (filterValueLower) {
2443
- return string.toLowerCase().indexOf(filterValueLower);
2444
- }
2445
- return 0;
2446
- };
2447
-
2448
- const getListItemType = (listItemType, isCollapsed) => {
2449
- if (listItemType === Item) {
2450
- return Item;
2451
- }
2452
- if (isCollapsed) {
2453
- return Collapsed;
2454
- }
2455
- return Expanded;
2456
- };
2457
- const filterProblems = (problems, collapsedUris, filterValue) => {
2458
- const filterValueLower = filterValue.toLowerCase();
2459
- const filtered = [];
2460
- for (const problem of problems) {
2461
- const uriMatchIndex = matchesFilterValue(problem.uri, filterValueLower);
2462
- const sourceMatchIndex = matchesFilterValue(problem.source, filterValueLower);
2463
- const messageMatchIndex = matchesFilterValue(problem.message, filterValueLower);
2464
- if (uriMatchIndex === -1 && sourceMatchIndex === -1 && messageMatchIndex === -1) {
2465
- continue;
2466
- }
2467
- const isCollapsed = collapsedUris.includes(problem.uri);
2468
- if (isCollapsed && problem.listItemType === Item) {
2469
- continue;
2470
- }
2471
- filtered.push({
2472
- ...problem,
2473
- isCollapsed,
2474
- listItemType: getListItemType(problem.listItemType, isCollapsed),
2475
- messageMatchIndex,
2476
- sourceMatchIndex,
2477
- uriMatchIndex
2478
- });
2479
- }
2480
- return filtered;
2481
- };
2482
-
2483
- const getFileNameIcon = file => {
2484
- return '';
2485
- };
2486
-
2487
- const getIcon = uri => {
2488
- if (!uri) {
2489
- return '';
2490
- }
2491
- return getFileNameIcon();
2492
- };
2493
-
2494
- const getVisibleProblems = (problems, collapsedUris, focusedIndex, filterValue) => {
2495
- array(problems);
2496
- array(collapsedUris);
2497
- number(focusedIndex);
2498
- string(filterValue);
2499
- const visibleItems = [];
2500
- const filterValueLength = filterValue.length;
2501
- const filtered = filterProblems(problems, collapsedUris, filterValue);
2502
- for (let i = 0; i < filtered.length; i++) {
2503
- const problem = filtered[i];
2504
- visibleItems.push({
2505
- ...problem,
2506
- filterValueLength,
2507
- icon: getIcon(problem.uri),
2508
- isActive: i === focusedIndex,
2509
- isEven: i % 2 === 0
2510
- });
2511
- }
2512
- return visibleItems;
2513
- };
2514
-
2515
2614
  const renderItems = (oldState, newState) => {
2516
2615
  const {
2517
2616
  activeUri,
@@ -2532,6 +2631,8 @@ const renderItems = (oldState, newState) => {
2532
2631
 
2533
2632
  const getRenderer = diffType => {
2534
2633
  switch (diffType) {
2634
+ case RenderCss:
2635
+ return renderCss;
2535
2636
  case RenderFilterValue:
2536
2637
  return renderFilterValue;
2537
2638
  case RenderItems:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/problems-view",
3
- "version": "1.25.2",
3
+ "version": "1.25.4",
4
4
  "description": "Problems View Worker",
5
5
  "repository": {
6
6
  "type": "git",