@lvce-editor/editor-worker 19.24.0 → 19.24.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.
@@ -4473,207 +4473,6 @@ const get$2 = async key => {
4473
4473
  return value;
4474
4474
  };
4475
4475
 
4476
- const logError = async (error, prefix) => {
4477
- const prettyError = await invoke$g('Errors.prepare', error);
4478
- await invoke$g('Errors.print', prettyError, prefix);
4479
- };
4480
- const logFallback = (error, prefix) => {
4481
- if (prefix) {
4482
- console.error(prefix, error);
4483
- return;
4484
- }
4485
- console.error(error);
4486
- };
4487
- const handleError$1 = async (error, prefix = '') => {
4488
- try {
4489
- await logError(error, prefix);
4490
- } catch (otherError) {
4491
- console.warn('ErrorHandling error', otherError);
4492
- logFallback(error, prefix);
4493
- }
4494
- };
4495
-
4496
- const OnDiagnostic = 'onDiagnostic';
4497
- const OnHover = 'onHover';
4498
- const OnTabCompletion = 'onTabCompletion';
4499
-
4500
- const execute = async ({
4501
- args,
4502
- assetDir,
4503
- editor,
4504
- event,
4505
- method,
4506
- noProviderFoundMessage,
4507
- noProviderFoundResult = undefined,
4508
- platform
4509
- }) => {
4510
- const fullEvent = `${event}:${editor.languageId}`;
4511
- await activateByEvent(fullEvent, assetDir, platform);
4512
- const result = await invoke$6(method, editor.uid, ...args);
4513
- return result;
4514
- };
4515
-
4516
- const getTextDocument$1 = editor => {
4517
- return {
4518
- documentId: editor.id || editor.uid,
4519
- languageId: editor.languageId,
4520
- text: getText$1(editor),
4521
- uri: editor.uri
4522
- };
4523
- };
4524
- const executeIsolatedDiagnosticProvider = async editor => {
4525
- const textDocument = getTextDocument$1(editor);
4526
- return invoke$e('Extensions.executeDiagnosticProvider', textDocument);
4527
- };
4528
- const executeDiagnosticProvider = async editor => {
4529
- const isolatedDiagnostics = await executeIsolatedDiagnosticProvider(editor);
4530
- if (isolatedDiagnostics.length > 0) {
4531
- return isolatedDiagnostics;
4532
- }
4533
- const {
4534
- assetDir,
4535
- platform
4536
- } = editor;
4537
- return execute({
4538
- args: [],
4539
- assetDir,
4540
- editor,
4541
- event: OnDiagnostic,
4542
- method: 'ExtensionHost.executeDiagnosticProvider',
4543
- noProviderFoundMessage: 'no diagnostic provider found',
4544
- platform
4545
- });
4546
- };
4547
-
4548
- const getDiagnosticType = diagnostic => {
4549
- return diagnostic.type;
4550
- };
4551
-
4552
- const getY = (row, minLineY, rowHeight) => {
4553
- return (row - minLineY) * rowHeight;
4554
- };
4555
-
4556
- const getVisibleDiagnostics = async (editor, diagnostics) => {
4557
- const visibleDiagnostics = [];
4558
- const {
4559
- charWidth,
4560
- fontFamily,
4561
- fontSize,
4562
- fontWeight,
4563
- isMonospaceFont,
4564
- letterSpacing,
4565
- lines,
4566
- minLineY,
4567
- rowHeight,
4568
- tabSize,
4569
- width
4570
- } = editor;
4571
- for (const diagnostic of diagnostics) {
4572
- const {
4573
- columnIndex,
4574
- endColumnIndex,
4575
- rowIndex
4576
- } = diagnostic;
4577
- const columnDelta = endColumnIndex - columnIndex;
4578
- const diagnosticWidth = columnDelta * charWidth;
4579
- const endLineDifference = 0;
4580
- const halfCursorWidth = 0;
4581
- const x = await getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, charWidth, endLineDifference);
4582
- const y = getY(rowIndex, minLineY, rowHeight) - rowHeight;
4583
- visibleDiagnostics.push({
4584
- height: rowHeight,
4585
- type: getDiagnosticType(diagnostic),
4586
- width: diagnosticWidth,
4587
- x,
4588
- y
4589
- });
4590
- }
4591
- return visibleDiagnostics;
4592
- };
4593
-
4594
- /**
4595
- * Merges link decorations with diagnostic decorations
4596
- * Links should always be present, but we also need to include any diagnostic decorations
4597
- */
4598
- const mergeLinksWithDiagnosticDecorations = (editor, diagnosticDecorations) => {
4599
- // Get link decorations
4600
- const linkDecorations = detectAllLinksAsDecorations(editor);
4601
-
4602
- // Merge with diagnostic decorations
4603
- const allDecorations = [...linkDecorations, ...diagnosticDecorations];
4604
-
4605
- // Sort by offset to maintain proper order
4606
- const sortedDecorations = [];
4607
- for (let i = 0; i < allDecorations.length; i += 4) {
4608
- sortedDecorations.push({
4609
- length: allDecorations[i + 1],
4610
- modifiers: allDecorations[i + 3],
4611
- offset: allDecorations[i],
4612
- type: allDecorations[i + 2]
4613
- });
4614
- }
4615
- sortedDecorations.sort((a, b) => a.offset - b.offset);
4616
-
4617
- // Flatten back to array format
4618
- const result = [];
4619
- for (const dec of sortedDecorations) {
4620
- result.push(dec.offset, dec.length, dec.type, dec.modifiers);
4621
- }
4622
- return result;
4623
- };
4624
-
4625
- const getDiagnostics$2 = async editor => {
4626
- const content = getText$1(editor);
4627
- // @ts-ignore
4628
- await invoke$6(TextDocumentSyncFull, editor.uri, editor.id, editor.languageId, content);
4629
- return executeDiagnosticProvider(editor);
4630
- };
4631
- const addDiagnostics = async (editor, diagnostics) => {
4632
- const visualDecorations = await getVisibleDiagnostics(editor, diagnostics);
4633
- const diagnosticDecorations = visualDecorations.flatMap(decoration => [decoration.offset, decoration.length, decoration.type, decoration.modifiers || 0]);
4634
- const decorations = mergeLinksWithDiagnosticDecorations(editor, diagnosticDecorations);
4635
- return {
4636
- ...editor,
4637
- decorations,
4638
- diagnostics,
4639
- visualDecorations
4640
- };
4641
- };
4642
- const handleError = async (error, editor) => {
4643
- if (error instanceof Error && error.message.includes('No diagnostic provider found')) {
4644
- return editor;
4645
- }
4646
- await handleError$1(error, 'Failed to update diagnostics: ');
4647
- return editor;
4648
- };
4649
- const getEditorWithDiagnostics = async editor => {
4650
- try {
4651
- const diagnostics = await getDiagnostics$2(editor);
4652
- if (!get$7(editor.id)) {
4653
- return editor;
4654
- }
4655
- return addDiagnostics(editor, diagnostics);
4656
- } catch (error) {
4657
- return handleError(error, editor);
4658
- }
4659
- };
4660
- const updateDiagnostics = async editor => {
4661
- try {
4662
- const diagnostics = await getDiagnostics$2(editor);
4663
- const latest = get$7(editor.id);
4664
- if (!latest) {
4665
- return editor;
4666
- }
4667
- const newEditor = await addDiagnostics(latest.newState, diagnostics);
4668
- set$9(editor.id, latest.oldState, newEditor);
4669
- // @ts-ignore
4670
- await invoke$b('Editor.rerender', editor.id);
4671
- return newEditor;
4672
- } catch (error) {
4673
- return handleError(error, editor);
4674
- }
4675
- };
4676
-
4677
4476
  const createEditor = async ({
4678
4477
  assetDir,
4679
4478
  columnToReveal,
@@ -4832,11 +4631,10 @@ const createEditor = async ({
4832
4631
  // e.g. it might not always be necessary to send text to extension host worker
4833
4632
  // @ts-ignore
4834
4633
  await invoke$6(TextDocumentSyncFull, uri, id, languageId, content);
4835
- const editorWithDiagnostics = diagnosticsEnabled ? await updateDiagnostics(newEditor4) : newEditor4;
4836
4634
  const completionsOnTypeRaw = await get$2('editor.completionsOnType');
4837
4635
  const completionsOnType = Boolean(completionsOnTypeRaw);
4838
4636
  set$9(id, emptyEditor, {
4839
- ...editorWithDiagnostics,
4637
+ ...newEditor4,
4840
4638
  completionsOnType
4841
4639
  });
4842
4640
  };
@@ -5157,6 +4955,26 @@ const closeWidgetsMaybe = widgets => {
5157
4955
  return widgets.filter(widget => isPersistentWidget(widget.id));
5158
4956
  };
5159
4957
 
4958
+ const logError = async (error, prefix) => {
4959
+ const prettyError = await invoke$g('Errors.prepare', error);
4960
+ await invoke$g('Errors.print', prettyError, prefix);
4961
+ };
4962
+ const logFallback = (error, prefix) => {
4963
+ if (prefix) {
4964
+ console.error(prefix, error);
4965
+ return;
4966
+ }
4967
+ console.error(error);
4968
+ };
4969
+ const handleError$1 = async (error, prefix = '') => {
4970
+ try {
4971
+ await logError(error, prefix);
4972
+ } catch (otherError) {
4973
+ console.warn('ErrorHandling error', otherError);
4974
+ logFallback(error, prefix);
4975
+ }
4976
+ };
4977
+
5160
4978
  const getFormattingEdits = async editor => {
5161
4979
  const textDocument = {
5162
4980
  documentId: editor.id || editor.uid,
@@ -8914,6 +8732,22 @@ const openRename = async editor => {
8914
8732
  };
8915
8733
  };
8916
8734
 
8735
+ const execute = async ({
8736
+ args,
8737
+ assetDir,
8738
+ editor,
8739
+ event,
8740
+ method,
8741
+ noProviderFoundMessage,
8742
+ noProviderFoundResult = undefined,
8743
+ platform
8744
+ }) => {
8745
+ const fullEvent = `${event}:${editor.languageId}`;
8746
+ await activateByEvent(fullEvent, assetDir, platform);
8747
+ const result = await invoke$6(method, editor.uid, ...args);
8748
+ return result;
8749
+ };
8750
+
8917
8751
  const getOrganizeImportEdits = async editor => {
8918
8752
  const edits = await execute({
8919
8753
  args: [],
@@ -9692,6 +9526,10 @@ const sortLinesAscending = editor => {
9692
9526
  return scheduleDocumentAndCursorsSelections(editor, changes);
9693
9527
  };
9694
9528
 
9529
+ const OnDiagnostic = 'onDiagnostic';
9530
+ const OnHover = 'onHover';
9531
+ const OnTabCompletion = 'onTabCompletion';
9532
+
9695
9533
  const executeTabCompletionProvider = async (editor, offset) => {
9696
9534
  return execute({
9697
9535
  args: [offset],
@@ -10504,7 +10342,7 @@ const EditorCompletionWidget = {
10504
10342
  toggleDetails: toggleDetails$1
10505
10343
  };
10506
10344
 
10507
- const getTextDocument = editor => {
10345
+ const getTextDocument$1 = editor => {
10508
10346
  return {
10509
10347
  documentId: editor.id || editor.uid,
10510
10348
  languageId: editor.languageId,
@@ -10513,7 +10351,7 @@ const getTextDocument = editor => {
10513
10351
  };
10514
10352
  };
10515
10353
  const executeIsolatedHoverProvider = async (editor, offset) => {
10516
- const textDocument = getTextDocument(editor);
10354
+ const textDocument = getTextDocument$1(editor);
10517
10355
  return invoke$e('Extensions.executeHoverProvider', textDocument, offset);
10518
10356
  };
10519
10357
  const executeHoverProvider = async (editor, offset) => {
@@ -11186,7 +11024,7 @@ const getSourceActions = async editorUid => {
11186
11024
  const actions = await getEditorSourceActions(editorUid);
11187
11025
  return actions;
11188
11026
  };
11189
- const getDiagnostics$1 = async editorUid => {
11027
+ const getDiagnostics$2 = async editorUid => {
11190
11028
  const editor = getEditor(editorUid);
11191
11029
  const {
11192
11030
  diagnostics
@@ -11674,7 +11512,39 @@ const getMenuIds = () => {
11674
11512
  return [Editor$1];
11675
11513
  };
11676
11514
 
11677
- const getDiagnostics = editor => {
11515
+ const getTextDocument = editor => {
11516
+ return {
11517
+ documentId: editor.id || editor.uid,
11518
+ languageId: editor.languageId,
11519
+ text: getText$1(editor),
11520
+ uri: editor.uri
11521
+ };
11522
+ };
11523
+ const executeIsolatedDiagnosticProvider = async editor => {
11524
+ const textDocument = getTextDocument(editor);
11525
+ return invoke$e('Extensions.executeDiagnosticProvider', textDocument);
11526
+ };
11527
+ const executeDiagnosticProvider = async editor => {
11528
+ const isolatedDiagnostics = await executeIsolatedDiagnosticProvider(editor);
11529
+ if (isolatedDiagnostics.length > 0) {
11530
+ return isolatedDiagnostics;
11531
+ }
11532
+ const {
11533
+ assetDir,
11534
+ platform
11535
+ } = editor;
11536
+ return execute({
11537
+ args: [],
11538
+ assetDir,
11539
+ editor,
11540
+ event: OnDiagnostic,
11541
+ method: 'ExtensionHost.executeDiagnosticProvider',
11542
+ noProviderFoundMessage: 'no diagnostic provider found',
11543
+ platform
11544
+ });
11545
+ };
11546
+
11547
+ const getDiagnostics$1 = editor => {
11678
11548
  return executeDiagnosticProvider(editor);
11679
11549
  };
11680
11550
  const getProblems = async () => {
@@ -11687,7 +11557,7 @@ const getProblems = async () => {
11687
11557
  return editor;
11688
11558
  });
11689
11559
  const newEditors = editors.map(editor => editor.newState);
11690
- const diagnostics = await Promise.all(newEditors.map(getDiagnostics));
11560
+ const diagnostics = await Promise.all(newEditors.map(getDiagnostics$1));
11691
11561
  const flatDiagnostics = diagnostics.flat();
11692
11562
  return flatDiagnostics;
11693
11563
  };
@@ -12231,11 +12101,10 @@ const loadContent = async (state, savedState) => {
12231
12101
  // e.g. it might not always be necessary to send text to extension host worker
12232
12102
  // @ts-ignore
12233
12103
  await invoke$6(TextDocumentSyncFull, uri, id, computedLanguageId, content);
12234
- const editorWithDiagnostics = diagnosticsEnabled ? await getEditorWithDiagnostics(newEditor4) : newEditor4;
12235
12104
  const completionsOnTypeRaw = await get$2('editor.completionsOnType');
12236
12105
  const completionsOnType = Boolean(completionsOnTypeRaw);
12237
12106
  const newEditor5 = {
12238
- ...editorWithDiagnostics,
12107
+ ...newEditor4,
12239
12108
  completionsOnType,
12240
12109
  initial: false
12241
12110
  };
@@ -13305,6 +13174,125 @@ const updateDebugInfo = async debugId => {
13305
13174
  await invoke$b('Editor.rerender', key);
13306
13175
  };
13307
13176
 
13177
+ const getDiagnosticType = diagnostic => {
13178
+ return diagnostic.type;
13179
+ };
13180
+
13181
+ const getY = (row, minLineY, rowHeight) => {
13182
+ return (row - minLineY) * rowHeight;
13183
+ };
13184
+
13185
+ const getVisibleDiagnostics = async (editor, diagnostics) => {
13186
+ const visibleDiagnostics = [];
13187
+ const {
13188
+ charWidth,
13189
+ fontFamily,
13190
+ fontSize,
13191
+ fontWeight,
13192
+ isMonospaceFont,
13193
+ letterSpacing,
13194
+ lines,
13195
+ minLineY,
13196
+ rowHeight,
13197
+ tabSize,
13198
+ width
13199
+ } = editor;
13200
+ for (const diagnostic of diagnostics) {
13201
+ const {
13202
+ columnIndex,
13203
+ endColumnIndex,
13204
+ rowIndex
13205
+ } = diagnostic;
13206
+ const columnDelta = endColumnIndex - columnIndex;
13207
+ const diagnosticWidth = columnDelta * charWidth;
13208
+ const endLineDifference = 0;
13209
+ const halfCursorWidth = 0;
13210
+ const x = await getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, charWidth, endLineDifference);
13211
+ const y = getY(rowIndex, minLineY, rowHeight);
13212
+ visibleDiagnostics.push({
13213
+ height: rowHeight,
13214
+ type: getDiagnosticType(diagnostic),
13215
+ width: diagnosticWidth,
13216
+ x,
13217
+ y
13218
+ });
13219
+ }
13220
+ return visibleDiagnostics;
13221
+ };
13222
+
13223
+ /**
13224
+ * Merges link decorations with diagnostic decorations
13225
+ * Links should always be present, but we also need to include any diagnostic decorations
13226
+ */
13227
+ const mergeLinksWithDiagnosticDecorations = (editor, diagnosticDecorations) => {
13228
+ // Get link decorations
13229
+ const linkDecorations = detectAllLinksAsDecorations(editor);
13230
+
13231
+ // Merge with diagnostic decorations
13232
+ const allDecorations = [...linkDecorations, ...diagnosticDecorations];
13233
+
13234
+ // Sort by offset to maintain proper order
13235
+ const sortedDecorations = [];
13236
+ for (let i = 0; i < allDecorations.length; i += 4) {
13237
+ sortedDecorations.push({
13238
+ length: allDecorations[i + 1],
13239
+ modifiers: allDecorations[i + 3],
13240
+ offset: allDecorations[i],
13241
+ type: allDecorations[i + 2]
13242
+ });
13243
+ }
13244
+ sortedDecorations.sort((a, b) => a.offset - b.offset);
13245
+
13246
+ // Flatten back to array format
13247
+ const result = [];
13248
+ for (const dec of sortedDecorations) {
13249
+ result.push(dec.offset, dec.length, dec.type, dec.modifiers);
13250
+ }
13251
+ return result;
13252
+ };
13253
+
13254
+ const getDiagnostics = async editor => {
13255
+ const content = getText$1(editor);
13256
+ // @ts-ignore
13257
+ await invoke$6(TextDocumentSyncFull, editor.uri, editor.id, editor.languageId, content);
13258
+ return executeDiagnosticProvider(editor);
13259
+ };
13260
+ const addDiagnostics = async (editor, diagnostics) => {
13261
+ const visualDecorations = await getVisibleDiagnostics(editor, diagnostics);
13262
+ const diagnosticDecorations = visualDecorations.flatMap(decoration => [decoration.offset, decoration.length, decoration.type, decoration.modifiers || 0]);
13263
+ const decorations = mergeLinksWithDiagnosticDecorations(editor, diagnosticDecorations);
13264
+ return {
13265
+ ...editor,
13266
+ decorations,
13267
+ diagnostics,
13268
+ visualDecorations
13269
+ };
13270
+ };
13271
+ const handleError = async (error, editor) => {
13272
+ if (error instanceof Error && error.message.includes('No diagnostic provider found')) {
13273
+ return editor;
13274
+ }
13275
+ await handleError$1(error, 'Failed to update diagnostics: ');
13276
+ return editor;
13277
+ };
13278
+ const updateDiagnostics = async editor => {
13279
+ if (!editor.diagnosticsEnabled) {
13280
+ return editor;
13281
+ }
13282
+ try {
13283
+ const diagnostics = await getDiagnostics(editor);
13284
+ const latest = get$7(editor.id);
13285
+ if (!latest) {
13286
+ return editor;
13287
+ }
13288
+ const newEditor = await addDiagnostics(latest.newState, diagnostics);
13289
+ set$9(editor.id, latest.oldState, newEditor);
13290
+ return newEditor;
13291
+ } catch (error) {
13292
+ return handleError(error, editor);
13293
+ }
13294
+ };
13295
+
13308
13296
  const queues = [];
13309
13297
 
13310
13298
  // TODO wrap commands globally, not per editor
@@ -13404,7 +13392,7 @@ const commandMap = {
13404
13392
  'Editor.fold': wrapCommand(fold$1),
13405
13393
  'Editor.format': wrapCommand(format),
13406
13394
  'Editor.getCommandIds': getCommandIds,
13407
- 'Editor.getDiagnostics': getDiagnostics$1,
13395
+ 'Editor.getDiagnostics': getDiagnostics$2,
13408
13396
  'Editor.getKeyBindings': getKeyBindings,
13409
13397
  'Editor.getKeys': getKeys$1,
13410
13398
  'Editor.getLanguageId': getLanguageId,
@@ -13511,6 +13499,7 @@ const commandMap = {
13511
13499
  'Editor.setDecorations': wrapCommand(setDecorations),
13512
13500
  'Editor.setDelta': wrapCommand(setDelta),
13513
13501
  'Editor.setDeltaY': wrapCommand(setDeltaY),
13502
+ 'Editor.setDiagnostics': wrapCommand(addDiagnostics),
13514
13503
  'Editor.setLanguageId': wrapCommand(setLanguageId),
13515
13504
  'Editor.setSelections': wrapCommand(setSelections),
13516
13505
  'Editor.setSelections2': setSelections2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.24.0",
3
+ "version": "19.24.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"