@lvce-editor/editor-worker 19.69.9 → 19.70.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.
@@ -6393,13 +6393,14 @@ const mergeDiagnostics = (editor, editorWithDiagnostics) => ({
6393
6393
  lightBulbRowIndex: editorWithDiagnostics.lightBulbRowIndex,
6394
6394
  visualDecorations: editorWithDiagnostics.visualDecorations
6395
6395
  });
6396
- const commitDiagnostics = async (editor, generation, diagnostics) => {
6396
+ const commitDiagnostics = async (editor, generation, diagnostics, onAccepted) => {
6397
6397
  return (await enqueue(editor.id, async () => {
6398
6398
  let latest = get$8(editor.id);
6399
6399
  if (!isApplicable(latest, editor, generation)) {
6400
6400
  return editor;
6401
6401
  }
6402
6402
  if (diagnosticsEqual(latest.newState.diagnostics, diagnostics)) {
6403
+ onAccepted?.();
6403
6404
  return latest.newState;
6404
6405
  }
6405
6406
  let calculationState = latest.newState;
@@ -6419,6 +6420,7 @@ const commitDiagnostics = async (editor, generation, diagnostics) => {
6419
6420
  const newEditor = mergeDiagnostics(latest.newState, editorWithDiagnostics);
6420
6421
  set$9(editor.id, latest.oldState, newEditor);
6421
6422
  requestDiagnosticSnapshots.set(editor.id, diagnostics);
6423
+ onAccepted?.();
6422
6424
  await invoke$5('Editor.renderPending', newEditor.id);
6423
6425
  await notifyDiagnosticsChange(newEditor.uri, newEditor.applicationId);
6424
6426
  return newEditor;
@@ -6429,7 +6431,18 @@ const flattenProviderDiagnostics = providers => {
6429
6431
  diagnostics
6430
6432
  }) => diagnostics);
6431
6433
  };
6432
- const updateDiagnostics = async editor => {
6434
+ const saveProviderResults = (editor, providers) => {
6435
+ previousProviderResults.set(editor.id, {
6436
+ languageId: editor.languageId,
6437
+ providers: new Map(providers),
6438
+ uri: editor.uri
6439
+ });
6440
+ };
6441
+ const updateDiagnostics = async (editor, timeoutMs = 0) => {
6442
+ const strict = timeoutMs > 0;
6443
+ if (strict && editor.loadError) {
6444
+ throw new Error(`Cannot await diagnostics: ${editor.loadError}`);
6445
+ }
6433
6446
  if (!editor.diagnosticsEnabled || editor.loadError) {
6434
6447
  return editor;
6435
6448
  }
@@ -6438,7 +6451,7 @@ const updateDiagnostics = async editor => {
6438
6451
  requestDiagnosticSnapshots.set(editor.id, get$8(editor.id)?.newState.diagnostics ?? editor.diagnostics);
6439
6452
  const providers = new Map();
6440
6453
  const previous = previousProviderResults.get(editor.id);
6441
- if (previous && previous.languageId === editor.languageId && previous.lines === editor.lines && previous.uri === editor.uri) {
6454
+ if (previous && previous.languageId === editor.languageId && previous.uri === editor.uri) {
6442
6455
  for (const [providerId, result] of previous.providers) {
6443
6456
  providers.set(providerId, result);
6444
6457
  }
@@ -6450,13 +6463,22 @@ const updateDiagnostics = async editor => {
6450
6463
  const completed = Promise.withResolvers();
6451
6464
  let commitQueue = Promise.resolve();
6452
6465
  let providerCount = -1;
6466
+ let finished = false;
6467
+ const receivedProviders = new Set();
6468
+ const timeout = strict ? setTimeout(() => completed.reject(new Error(`Diagnostics timed out after ${timeoutMs}ms for ${editor.uri}`)), timeoutMs) : undefined;
6453
6469
  port1.onmessage = event => {
6454
6470
  const previousCommit = commitQueue;
6455
6471
  commitQueue = (async () => {
6456
6472
  await previousCommit;
6457
6473
  try {
6474
+ if (finished) {
6475
+ return;
6476
+ }
6458
6477
  const message = event.data;
6459
6478
  if (requestGenerations.get(editor.id) !== generation) {
6479
+ if (strict) {
6480
+ throw new Error('Diagnostics request was superseded');
6481
+ }
6460
6482
  if (message.type === 'done') {
6461
6483
  port1.close();
6462
6484
  completed.resolve();
@@ -6477,61 +6499,87 @@ const updateDiagnostics = async editor => {
6477
6499
  providers.delete(providerId);
6478
6500
  }
6479
6501
  }
6502
+ if (requestGenerations.get(editor.id) === generation) {
6503
+ saveProviderResults(editor, providers);
6504
+ }
6480
6505
  return;
6481
6506
  }
6482
6507
  if (message.type === 'result' && message.providerId !== undefined) {
6508
+ if (strict && message.error !== undefined) {
6509
+ throw new Error(`Diagnostic provider ${message.providerId} failed: ${message.error}`);
6510
+ }
6511
+ receivedProviders.add(message.providerId);
6483
6512
  providers.set(message.providerId, {
6484
6513
  diagnostics: message.diagnostics ?? [],
6485
6514
  providerIndex: message.providerIndex ?? providers.size
6486
6515
  });
6487
- await commitDiagnostics(editor, generation, flattenProviderDiagnostics(providers));
6516
+ await commitDiagnostics(editor, generation, flattenProviderDiagnostics(providers), () => saveProviderResults(editor, providers));
6488
6517
  return;
6489
6518
  }
6490
6519
  if (message.type === 'done') {
6520
+ if (strict && (providerCount < 0 || receivedProviders.size !== providerCount)) {
6521
+ throw new Error('Diagnostics stream ended without all provider results');
6522
+ }
6491
6523
  if (providerCount === 0) {
6492
6524
  providers.clear();
6493
- await commitDiagnostics(editor, generation, []);
6525
+ await commitDiagnostics(editor, generation, [], () => saveProviderResults(editor, providers));
6526
+ }
6527
+ if (requestGenerations.get(editor.id) === generation) {
6528
+ saveProviderResults(editor, providers);
6494
6529
  }
6495
- previousProviderResults.set(editor.id, {
6496
- languageId: editor.languageId,
6497
- lines: editor.lines,
6498
- providers: new Map(providers),
6499
- uri: editor.uri
6500
- });
6501
6530
  port1.close();
6502
6531
  completed.resolve();
6503
6532
  }
6504
6533
  } catch (error) {
6505
6534
  port1.close();
6506
- completed.resolve();
6507
- await handleError(error, editor);
6535
+ if (strict) {
6536
+ completed.reject(error);
6537
+ } else {
6538
+ completed.resolve();
6539
+ await handleError(error, editor);
6540
+ }
6508
6541
  }
6509
6542
  })();
6510
6543
  };
6511
6544
  port1.start();
6512
- try {
6545
+ const request = async () => {
6513
6546
  const response = await getDiagnostics$1(editor, port2);
6547
+ if (finished) {
6548
+ return;
6549
+ }
6514
6550
  if (Array.isArray(response) && providerCount === -1) {
6551
+ if (strict) {
6552
+ throw new Error('Diagnostic provider does not support completion and error reporting');
6553
+ }
6515
6554
  providers.set('legacy', {
6516
6555
  diagnostics: response,
6517
6556
  providerIndex: 0
6518
6557
  });
6519
- await commitDiagnostics(editor, generation, response);
6520
- previousProviderResults.set(editor.id, {
6521
- languageId: editor.languageId,
6522
- lines: editor.lines,
6523
- providers: new Map(providers),
6524
- uri: editor.uri
6525
- });
6558
+ await commitDiagnostics(editor, generation, response, () => saveProviderResults(editor, providers));
6526
6559
  port1.close();
6527
6560
  completed.resolve();
6528
6561
  }
6529
- await completed.promise;
6562
+ };
6563
+ try {
6564
+ await Promise.all([request(), completed.promise]);
6530
6565
  const latest = get$8(editor.id);
6566
+ if (strict && !isApplicable(latest, editor, generation)) {
6567
+ throw new Error('Editor changed or closed while waiting for diagnostics');
6568
+ }
6531
6569
  return isApplicable(latest, editor, generation) ? latest.newState : editor;
6532
6570
  } catch (error) {
6533
- port1.close();
6571
+ if (strict) {
6572
+ if (requestGenerations.get(editor.id) === generation) {
6573
+ requestGenerations.set(editor.id, generation + 1);
6574
+ }
6575
+ throw error;
6576
+ }
6534
6577
  return handleError(error, editor);
6578
+ } finally {
6579
+ finished = true;
6580
+ clearTimeout(timeout);
6581
+ port1.close();
6582
+ port2.close();
6535
6583
  }
6536
6584
  };
6537
6585
  const requestDiagnostics = editor => {
@@ -6552,6 +6600,18 @@ const updateDiagnosticsAll = async () => {
6552
6600
  }
6553
6601
  };
6554
6602
 
6603
+ // Do not wrap this command in EditorCommandQueue: streamed results need that queue to commit.
6604
+ const waitForDiagnostics = async (editorId, timeoutMs = 30_000) => {
6605
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 300_000) {
6606
+ throw new Error('Diagnostics timeout must be between 1 and 300000ms');
6607
+ }
6608
+ const editor = get$8(editorId)?.newState;
6609
+ if (!editor || editor.initial) {
6610
+ throw new Error(`Editor is not ready: ${editorId}`);
6611
+ }
6612
+ await updateDiagnostics(editor, timeoutMs);
6613
+ };
6614
+
6555
6615
  const disposeEditor = async editorUid => {
6556
6616
  const editor = get$8(editorUid)?.newState;
6557
6617
  if (!editor) {
@@ -10384,12 +10444,14 @@ const getEditorHoverInfo = async (editorUid, position) => {
10384
10444
  const wordPart = getWordBefore(editor, rowIndex, columnIndex);
10385
10445
  const wordStart = columnIndex - wordPart.length;
10386
10446
  const documentationHeight = documentation ? await measureTextBlockHeight(documentation, hoverDocumentationFontFamily, hoverDocumentationFontSize, hoverDocumentationLineHeight, hoverDocumentationWidth) : 0;
10447
+ const measuredDisplayStringHeight = displayString ? await measureTextBlockHeight(displayString, editor.fontFamily, editor.fontSize, `${editor.rowHeight}px`, hoverDocumentationWidth) : 0;
10448
+ const displayStringHeight = displayString ? measuredDisplayStringHeight + (measuredDisplayStringHeight > editor.rowHeight ? editor.rowHeight : 0) + 12 : 0;
10387
10449
  let diagnosticText = '';
10388
10450
  for (const diagnostic of matchingDiagnostics) {
10389
10451
  diagnosticText += `${diagnosticText ? '\n' : ''}${diagnostic.message} ${diagnostic.source} (${diagnostic.code})`;
10390
10452
  }
10391
10453
  const diagnosticsHeight = diagnosticText ? (await measureTextBlockHeight(diagnosticText, editor.fontFamily, editor.fontSize, `${editor.rowHeight}px`, hoverDocumentationWidth)) + 10 : 0;
10392
- const height = Math.min(diagnosticsHeight + (lineInfos.length > 0 ? lineInfos.length * editor.rowHeight + 12 : 0) + (documentation ? documentationHeight + 11 : 0) || 20, editor.height);
10454
+ const height = Math.min(diagnosticsHeight + displayStringHeight + (documentation ? documentationHeight + 11 : 0) || 20, editor.height);
10393
10455
  const x$1 = Math.max(editor.x, Math.min(x(editor, rowIndex, wordStart), editor.x + editor.width - hoverWidth));
10394
10456
  const rowBottom = y(editor, rowIndex);
10395
10457
  const y$1 = rowBottom + height <= editor.y + editor.height ? rowBottom : Math.max(editor.y, rowBottom - editor.rowHeight - height);
@@ -18259,6 +18321,7 @@ const commandMap = {
18259
18321
  'Editor.updateDebugInfo': updateDebugInfo,
18260
18322
  'Editor.updateDiagnostics': wrapCommand(requestDiagnostics),
18261
18323
  'Editor.updateDiagnosticsAll': updateDiagnosticsAll,
18324
+ 'Editor.waitForDiagnostics': waitForDiagnostics,
18262
18325
  'EditorCompletion.close': close$3,
18263
18326
  'EditorCompletion.closeDetails': closeDetails$1,
18264
18327
  'EditorCompletion.focusFirst': focusFirst$1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.69.9",
3
+ "version": "19.70.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"