@lvce-editor/editor-worker 19.62.2 → 19.62.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.
@@ -2092,6 +2092,13 @@ const getViewportLineIndices = (lineCount, ranges, startVisualRow, numberOfVisib
2092
2092
  }
2093
2093
  return result;
2094
2094
  };
2095
+ const getLongestLineWidth = (lines, charWidth) => {
2096
+ let longest = 0;
2097
+ for (const line of lines) {
2098
+ longest = Math.max(longest, line.length);
2099
+ }
2100
+ return longest * charWidth;
2101
+ };
2095
2102
  const updateLayout = (editor, foldingRanges) => {
2096
2103
  const {
2097
2104
  height,
@@ -2124,6 +2131,9 @@ const updateLayout = (editor, foldingRanges) => {
2124
2131
  finalY,
2125
2132
  foldingRanges,
2126
2133
  maxLineY,
2134
+ ...(editor.largeFile && {
2135
+ longestLineWidth: getLongestLineWidth(lines, editor.charWidth)
2136
+ }),
2127
2137
  mergeConflicts,
2128
2138
  minLineY,
2129
2139
  scrollBarHeight,
@@ -2325,6 +2335,46 @@ const getDecorationClassName = type => {
2325
2335
  }
2326
2336
  };
2327
2337
 
2338
+ // Large files have no token cache. Only materialize the text inside the horizontal viewport.
2339
+ const getLargeFileVisible = editor => {
2340
+ const {
2341
+ deltaX,
2342
+ lines,
2343
+ tabSize,
2344
+ visibleLineIndices,
2345
+ width
2346
+ } = editor;
2347
+ const charWidth = editor.charWidth || 8;
2348
+ const firstColumn = Math.max(0, Math.floor(deltaX / charWidth));
2349
+ const lastColumn = firstColumn + Math.ceil(width / charWidth) + 2;
2350
+ const textInfos = [];
2351
+ const differences = [];
2352
+ for (const row of visibleLineIndices) {
2353
+ const line = lines[row];
2354
+ let text = '';
2355
+ if (line.includes('\t')) {
2356
+ let column = 0;
2357
+ for (let index = 0; index < line.length && column < lastColumn; index++) {
2358
+ const character = line[index];
2359
+ const length = character === '\t' ? Math.max(1, tabSize) : 1;
2360
+ const end = column + length;
2361
+ if (end > firstColumn) {
2362
+ text += character === '\t' ? ' '.repeat(Math.min(end, lastColumn) - Math.max(column, firstColumn)) : character;
2363
+ }
2364
+ column = end;
2365
+ }
2366
+ } else {
2367
+ text = line.slice(firstColumn, lastColumn);
2368
+ }
2369
+ textInfos.push([text, 'Token Text']);
2370
+ differences.push(firstColumn * charWidth - deltaX);
2371
+ }
2372
+ return {
2373
+ differences,
2374
+ textInfos
2375
+ };
2376
+ };
2377
+
2328
2378
  const deepCopy = value => {
2329
2379
  return structuredClone(value);
2330
2380
  };
@@ -3229,6 +3279,9 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
3229
3279
  };
3230
3280
  };
3231
3281
  const getVisible$1 = async (editor, syncIncremental) => {
3282
+ if (editor.largeFile) {
3283
+ return getLargeFileVisible(editor);
3284
+ }
3232
3285
  // TODO should separate rendering from business logic somehow
3233
3286
  // currently hard to test because need to mock editor height, top, left,
3234
3287
  // invalidStartIndex, lineCache, etc. just for testing editorType
@@ -3458,6 +3511,9 @@ const detectLinks = text => {
3458
3511
  */
3459
3512
  const detectAllLinksAsDecorations = editor => {
3460
3513
  const decorations = [];
3514
+ if (editor.largeFile) {
3515
+ return decorations;
3516
+ }
3461
3517
  const {
3462
3518
  lines
3463
3519
  } = editor;
@@ -4524,6 +4580,9 @@ const getProviderDecorations$1 = results => {
4524
4580
  return decorations;
4525
4581
  };
4526
4582
  const getEditorGutterDecorations = async editor => {
4583
+ if (editor.largeFile) {
4584
+ return [];
4585
+ }
4527
4586
  const textDocument = {
4528
4587
  languageId: editor.languageId,
4529
4588
  text: getText$1(editor),
@@ -6239,6 +6298,9 @@ const handleError$1 = async (error, prefix = '') => {
6239
6298
  };
6240
6299
 
6241
6300
  const getFormattingEdits = async editor => {
6301
+ if (editor.largeFile) {
6302
+ return [];
6303
+ }
6242
6304
  const textDocument = {
6243
6305
  documentId: editor.id || editor.uid,
6244
6306
  languageId: editor.languageId,
@@ -6681,6 +6743,9 @@ const execute = async ({
6681
6743
  method,
6682
6744
  noProviderFoundResult = undefined
6683
6745
  }) => {
6746
+ if (editor.largeFile) {
6747
+ return noProviderFoundResult;
6748
+ }
6684
6749
  const textDocument = getTextDocument$3(editor);
6685
6750
  const result = await invoke$8(editor.applicationId, 'Extensions.executeLanguageProvider', kind, method, textDocument, ...args);
6686
6751
  if (!result.found) {
@@ -8841,6 +8906,9 @@ const getProviderDecorations = (results, rowIndex) => {
8841
8906
  return decorations;
8842
8907
  };
8843
8908
  const getEditorLineDecorations = async (editor, rowIndex) => {
8909
+ if (editor.largeFile) {
8910
+ return [];
8911
+ }
8844
8912
  const textDocument = {
8845
8913
  languageId: editor.languageId,
8846
8914
  text: getText$1(editor),
@@ -11075,6 +11143,9 @@ const openRename = async editor => {
11075
11143
  };
11076
11144
 
11077
11145
  const getOrganizeImportEdits = async editor => {
11146
+ if (editor.largeFile) {
11147
+ return [];
11148
+ }
11078
11149
  const textDocument = {
11079
11150
  documentId: editor.id || editor.uid,
11080
11151
  languageId: editor.languageId,
@@ -11689,6 +11760,12 @@ const setIndentation = (editor, insertSpaces) => {
11689
11760
  };
11690
11761
 
11691
11762
  const setLanguageId = async (editor, languageId, tokenizePath) => {
11763
+ if (editor.largeFile) {
11764
+ return {
11765
+ ...editor,
11766
+ languageId
11767
+ };
11768
+ }
11692
11769
  const {
11693
11770
  tokenizerId
11694
11771
  } = editor;
@@ -14426,6 +14503,21 @@ const getEditorPreferences = async () => {
14426
14503
  };
14427
14504
  };
14428
14505
 
14506
+ const getLargeFilePreferences = () => ({
14507
+ breadcrumbsEnabled: false,
14508
+ completionsOnType: false,
14509
+ completionTriggerCharacters: [],
14510
+ diagnosticsEnabled: false,
14511
+ formatOnSave: false,
14512
+ hoverEnabled: false,
14513
+ isAutoClosingBracketsEnabled: false,
14514
+ isAutoClosingQuotesEnabled: false,
14515
+ isAutoClosingTagsEnabled: false,
14516
+ isQuickSuggestionsEnabled: false,
14517
+ mergeConflictActionsEnabled: false,
14518
+ minimapEnabled: false
14519
+ });
14520
+
14429
14521
  const getWorkspaceUri$1 = async applicationId => {
14430
14522
  try {
14431
14523
  return await invoke$9(applicationId, 'Workspace.getPath');
@@ -14434,7 +14526,10 @@ const getWorkspaceUri$1 = async applicationId => {
14434
14526
  }
14435
14527
  };
14436
14528
  const handleSettingsChanged = async state => {
14437
- const editorPreferences = await getEditorPreferences();
14529
+ const editorPreferences = {
14530
+ ...(await getEditorPreferences()),
14531
+ ...(state.largeFile && getLargeFilePreferences())
14532
+ };
14438
14533
  const {
14439
14534
  breadcrumbsEnabled,
14440
14535
  diagnosticsEnabled,
@@ -14451,7 +14546,7 @@ const handleSettingsChanged = async state => {
14451
14546
  ...state,
14452
14547
  ...editorPreferences,
14453
14548
  charWidth,
14454
- completionsOnType: Boolean(completionsOnTypeRaw),
14549
+ completionsOnType: !state.largeFile && Boolean(completionsOnTypeRaw),
14455
14550
  diagnostics: diagnosticsEnabled ? state.diagnostics : [],
14456
14551
  isMonospaceFont,
14457
14552
  itemHeight: rowHeight,
@@ -14733,7 +14828,7 @@ const getSavedHistory = (savedState, content) => {
14733
14828
  undoStack
14734
14829
  };
14735
14830
  };
14736
- const loadContent = async (state, savedState) => {
14831
+ const loadContent = async (state, savedState, largeFile = false) => {
14737
14832
  const {
14738
14833
  assetDir,
14739
14834
  height,
@@ -14774,11 +14869,6 @@ const loadContent = async (state, savedState) => {
14774
14869
  const languages = await getLanguages(platform, assetDir);
14775
14870
  setTokenizePaths(languages);
14776
14871
  const computedLanguageId = getLanguageId$1(uri, languages);
14777
- const tokenizePath = getTokenizePath(languages, computedLanguageId);
14778
- await loadTokenizer(computedLanguageId, tokenizePath);
14779
- const tokenizer = getTokenizer(computedLanguageId);
14780
- const newTokenizerId = state.tokenizerId + 1;
14781
- set$3(newTokenizerId, tokenizer);
14782
14872
  const newEditor0 = {
14783
14873
  ...state,
14784
14874
  breadcrumbsEnabled,
@@ -14807,7 +14897,7 @@ const loadContent = async (state, savedState) => {
14807
14897
  roundedSelection,
14808
14898
  rowHeight,
14809
14899
  tabSize,
14810
- tokenizerId: newTokenizerId
14900
+ tokenizerId: state.tokenizerId
14811
14901
  };
14812
14902
  let existingEditor;
14813
14903
  for (const key of getKeys$2()) {
@@ -14837,11 +14927,26 @@ const loadContent = async (state, savedState) => {
14837
14927
  textInfos: []
14838
14928
  };
14839
14929
  }
14930
+ const savedLargeFile = !!savedState && typeof savedState === 'object' && savedState.largeFile === true;
14931
+ largeFile ||= state.largeFile === true || existingEditor?.largeFile === true || savedLargeFile || content.length > 50 * 1024 * 1024;
14932
+ const effectiveEditor = {
14933
+ ...newEditor0,
14934
+ largeFile,
14935
+ ...(largeFile && getLargeFilePreferences())
14936
+ };
14937
+ if (!largeFile) {
14938
+ const tokenizePath = getTokenizePath(languages, computedLanguageId);
14939
+ await loadTokenizer(computedLanguageId, tokenizePath);
14940
+ const tokenizer = getTokenizer(computedLanguageId);
14941
+ const newTokenizerId = state.tokenizerId + 1;
14942
+ set$3(newTokenizerId, tokenizer);
14943
+ effectiveEditor.tokenizerId = newTokenizerId;
14944
+ }
14840
14945
  const savedHistory = existingEditor ? undefined : getSavedHistory(savedState, content);
14841
14946
 
14842
14947
  // TODO avoid creating intermediate editors here
14843
14948
  const newEditor1 = setBounds({
14844
- ...newEditor0,
14949
+ ...effectiveEditor,
14845
14950
  endOfLine
14846
14951
  }, x, y, width, height, 9);
14847
14952
  const newEditor2 = setText$1(newEditor1, content);
@@ -14855,7 +14960,7 @@ const loadContent = async (state, savedState) => {
14855
14960
  };
14856
14961
  let documentSymbols = state.documentSymbols || [];
14857
14962
  let workspaceUri = state.workspaceUri || '';
14858
- if (breadcrumbsEnabled) {
14963
+ if (effectiveEditor.breadcrumbsEnabled) {
14859
14964
  [documentSymbols, workspaceUri] = await Promise.all([getDocumentSymbols(newEditor3WithLinks), getWorkspaceUri(state.applicationId)]);
14860
14965
  }
14861
14966
  const newEditor3WithBreadcrumbs = {
@@ -14879,7 +14984,7 @@ const loadContent = async (state, savedState) => {
14879
14984
  const completionsOnType = Boolean(completionsOnTypeRaw);
14880
14985
  const newEditor5 = {
14881
14986
  ...newEditor4,
14882
- completionsOnType,
14987
+ completionsOnType: !largeFile && completionsOnType,
14883
14988
  initial: false,
14884
14989
  modified: existingEditor?.modified || false,
14885
14990
  redoStack: existingEditor?.redoStack || savedHistory?.redoStack || [],
@@ -16274,11 +16379,15 @@ const revealProblem = (editor, rowIndex, columnIndex) => {
16274
16379
 
16275
16380
  const saveState = (state, savedState) => {
16276
16381
  const {
16382
+ largeFile,
16277
16383
  lines,
16278
16384
  redoStack,
16279
16385
  undoStack
16280
16386
  } = state;
16281
16387
  return {
16388
+ ...(largeFile && {
16389
+ largeFile: true
16390
+ }),
16282
16391
  lines,
16283
16392
  redoStack,
16284
16393
  undoStack
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.62.2",
3
+ "version": "19.62.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"