@lvce-editor/editor-worker 5.0.0 → 5.1.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.
@@ -273,6 +273,17 @@ const joinLines$2 = lines => {
273
273
  return lines.join('\n');
274
274
  };
275
275
 
276
+ const RE_WHITESPACE = /^\s+/;
277
+
278
+ // TODO this doesn't belong here
279
+ const getIndent = line => {
280
+ const whitespaceMatch = line.match(RE_WHITESPACE);
281
+ if (!whitespaceMatch) {
282
+ return '';
283
+ }
284
+ return whitespaceMatch[0];
285
+ };
286
+
276
287
  // TODO have function for single edit (most common, avoid one array)
277
288
  const applyEdits = (textDocument, changes) => {
278
289
  object(textDocument);
@@ -330,7 +341,7 @@ const applyEdits = (textDocument, changes) => {
330
341
  // TODO only do this once after all edits, not inside loop
331
342
  textDocument.maxLineY = Math.min(textDocument.numberOfVisibleLines, textDocument.lines.length);
332
343
  }
333
- linesDelta += Math.max(inserted.length - deleted.length, 0);
344
+ linesDelta += inserted.length - deleted.length;
334
345
  }
335
346
  return newLines;
336
347
  };
@@ -340,16 +351,6 @@ const getLine = (textDocument, index) => {
340
351
  const getText$1 = state => {
341
352
  return joinLines$2(state.lines);
342
353
  };
343
- const RE_WHITESPACE = /^\s+/;
344
-
345
- // TODO this doesn't belong here
346
- const getIndent = line => {
347
- const whitespaceMatch = line.match(RE_WHITESPACE);
348
- if (!whitespaceMatch) {
349
- return '';
350
- }
351
- return whitespaceMatch[0];
352
- };
353
354
 
354
355
  // TDOO this doesn;t belong here
355
356
  const getSelectionText = (textDocument, range) => {
@@ -416,11 +417,6 @@ const positionAt = (textDocument, offset) => {
416
417
  } else {
417
418
  columnIndex = currentOffset - offset;
418
419
  }
419
- console.log({
420
- rowIndex,
421
- columnIndex
422
- });
423
- // TODO
424
420
  return {
425
421
  rowIndex,
426
422
  columnIndex
@@ -3190,28 +3186,41 @@ const findAllReferences = async editor => {
3190
3186
  return editor;
3191
3187
  };
3192
3188
 
3193
- // TODO format should be executed in parallel with saving
3194
- // -> fast save, no need to wait for formatting
3195
- // -> fast formatting, no need to wait for save
3196
-
3197
- // TODO should format on save when closing/switching editor?
3189
+ // TODO add tests for this
3190
+ const activateByEvent = async event => {
3191
+ await invoke$3('ExtensionHostManagement.activateByEvent', event);
3192
+ };
3198
3193
 
3199
- // TODO format with cursor
3200
- // TODO should be in editor folder
3194
+ const execute = async ({
3195
+ editor,
3196
+ args,
3197
+ event,
3198
+ method,
3199
+ noProviderFoundMessage,
3200
+ noProviderFoundResult = undefined
3201
+ }) => {
3202
+ const fullEvent = `${event}:${editor.languageId}`;
3203
+ await activateByEvent(fullEvent);
3204
+ const result = await invoke$2(method, editor.uid, ...args);
3205
+ return result;
3206
+ };
3201
3207
 
3202
- const format$1 = async editor => {
3203
- const edits = await invoke$3('Format.format', editor);
3208
+ const getFormattingEdits = async editor => {
3209
+ const edits = await execute({
3210
+ editor,
3211
+ event: 'onFormatting',
3212
+ method: 'ExtensionHostFormatting.executeFormattingProvider',
3213
+ args: []
3214
+ });
3204
3215
  return edits;
3205
3216
  };
3206
3217
 
3207
- const warn = (...args) => {
3208
- console.warn(...args);
3209
- };
3210
- const error = (...args) => {
3211
- console.error(...args);
3218
+ const expectedErrorMessage$1 = 'Failed to execute formatting provider: FormattingError:';
3219
+ const isFormattingError = error => {
3220
+ // @ts-ignore
3221
+ return error && error instanceof Error && error.message.startsWith(expectedErrorMessage$1);
3212
3222
  };
3213
3223
 
3214
- // @ts-ignore
3215
3224
  const getDocumentEdits = (editor, edits) => {
3216
3225
  const documentEdits = [];
3217
3226
  for (const edit of edits) {
@@ -3236,7 +3245,13 @@ const getDocumentEdits = (editor, edits) => {
3236
3245
  return documentEdits;
3237
3246
  };
3238
3247
 
3239
- // @ts-ignore
3248
+ const warn = (...args) => {
3249
+ console.warn(...args);
3250
+ };
3251
+ const error = (...args) => {
3252
+ console.error(...args);
3253
+ };
3254
+
3240
3255
  const applyDocumentEdits = (editor, edits) => {
3241
3256
  if (!Array.isArray(edits)) {
3242
3257
  warn('something is wrong with format on save', edits);
@@ -3250,14 +3265,11 @@ const applyDocumentEdits = (editor, edits) => {
3250
3265
  };
3251
3266
 
3252
3267
  const expectedErrorMessage = 'Failed to execute formatting provider: FormattingError:';
3253
- const isFormattingError = error => {
3254
- return error && error instanceof Error && error.message.startsWith(expectedErrorMessage);
3255
- };
3256
3268
 
3257
3269
  // TODO also format with cursor
3258
3270
  const format = async editor => {
3259
3271
  try {
3260
- const edits = await format$1(editor);
3272
+ const edits = await getFormattingEdits(editor);
3261
3273
  return applyDocumentEdits(editor, edits);
3262
3274
  } catch (error) {
3263
3275
  if (isFormattingError(error)) {
@@ -3267,6 +3279,8 @@ const format = async editor => {
3267
3279
  return editor;
3268
3280
  }
3269
3281
  console.error(error);
3282
+
3283
+ // TODO configure editor message as widget
3270
3284
  const displayErrorMessage = `${error}`;
3271
3285
  await editorShowMessage(editor, 0, 0, displayErrorMessage, true);
3272
3286
  return editor;
@@ -4554,25 +4568,6 @@ const OnCompletion = 'onCompletion';
4554
4568
  const OnHover = 'onHover';
4555
4569
  const OnTabCompletion = 'onTabCompletion';
4556
4570
 
4557
- // TODO add tests for this
4558
- const activateByEvent = async event => {
4559
- await invoke$3('ExtensionHostManagement.activateByEvent', event);
4560
- };
4561
-
4562
- const execute = async ({
4563
- editor,
4564
- args,
4565
- event,
4566
- method,
4567
- noProviderFoundMessage,
4568
- noProviderFoundResult = undefined
4569
- }) => {
4570
- const fullEvent = `${event}:${editor.languageId}`;
4571
- await activateByEvent(fullEvent);
4572
- const result = await invoke$2(method, editor.uid, ...args);
4573
- return result;
4574
- };
4575
-
4576
4571
  const combineResults$2 = results => {
4577
4572
  return results[0] ?? [];
4578
4573
  };
@@ -5544,9 +5539,18 @@ const openRename = async editor => {
5544
5539
  return addWidgetToEditor(Rename, FocusEditorRename, editor, create$4, newStateGenerator, fullFocus);
5545
5540
  };
5546
5541
 
5542
+ const getOrganizeImportEdits = async editor => {
5543
+ const edits = await execute({
5544
+ editor,
5545
+ event: 'onLanguage',
5546
+ method: 'ExtensionHostOrganizeImports.execute',
5547
+ args: []
5548
+ });
5549
+ return edits;
5550
+ };
5551
+
5547
5552
  const organizeImports = async editor => {
5548
- // TODO ask extension host worker directly
5549
- const edits = await invoke$3('ExtensionHostOrganizeImports.organizeImports', editor);
5553
+ const edits = await getOrganizeImportEdits(editor);
5550
5554
  return applyDocumentEdits(editor, edits);
5551
5555
  };
5552
5556
 
@@ -7889,6 +7893,8 @@ const MaskIcon = 'MaskIcon';
7889
7893
  const MaskIconSymbolFile = 'MaskIconSymbolFile';
7890
7894
  const MultilineInputBox = 'MultilineInputBox';
7891
7895
  const SearchField = 'SearchField';
7896
+ const SearchFieldButton = 'SearchFieldButton';
7897
+ const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
7892
7898
  const SearchFieldButtons = 'SearchFieldButtons';
7893
7899
  const SourceActionHeading = 'SourceActionHeading';
7894
7900
  const SourceActionIcon = 'SourceActionIcon';
@@ -10892,7 +10898,7 @@ const getSearchFieldButtonVirtualDom = button => {
10892
10898
  } = button;
10893
10899
  return [{
10894
10900
  type: Div,
10895
- className: `SearchFieldButton ${checked ? 'SearchFieldButtonChecked' : ''}`,
10901
+ className: mergeClassNames(SearchFieldButton, checked ? SearchFieldButtonChecked : ''),
10896
10902
  title,
10897
10903
  role: CheckBox,
10898
10904
  ariaChecked: checked,
@@ -10900,7 +10906,7 @@ const getSearchFieldButtonVirtualDom = button => {
10900
10906
  childCount: 1
10901
10907
  }, {
10902
10908
  type: Div,
10903
- className: `MaskIcon ${icon}`,
10909
+ className: mergeClassNames(MaskIcon, icon),
10904
10910
  childCount: 0
10905
10911
  }];
10906
10912
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",