@lvce-editor/editor-worker 19.69.10 → 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.
- package/dist/editorWorkerMain.js +64 -6
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -6438,7 +6438,11 @@ const saveProviderResults = (editor, providers) => {
|
|
|
6438
6438
|
uri: editor.uri
|
|
6439
6439
|
});
|
|
6440
6440
|
};
|
|
6441
|
-
const updateDiagnostics = async editor => {
|
|
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
|
+
}
|
|
6442
6446
|
if (!editor.diagnosticsEnabled || editor.loadError) {
|
|
6443
6447
|
return editor;
|
|
6444
6448
|
}
|
|
@@ -6459,13 +6463,22 @@ const updateDiagnostics = async editor => {
|
|
|
6459
6463
|
const completed = Promise.withResolvers();
|
|
6460
6464
|
let commitQueue = Promise.resolve();
|
|
6461
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;
|
|
6462
6469
|
port1.onmessage = event => {
|
|
6463
6470
|
const previousCommit = commitQueue;
|
|
6464
6471
|
commitQueue = (async () => {
|
|
6465
6472
|
await previousCommit;
|
|
6466
6473
|
try {
|
|
6474
|
+
if (finished) {
|
|
6475
|
+
return;
|
|
6476
|
+
}
|
|
6467
6477
|
const message = event.data;
|
|
6468
6478
|
if (requestGenerations.get(editor.id) !== generation) {
|
|
6479
|
+
if (strict) {
|
|
6480
|
+
throw new Error('Diagnostics request was superseded');
|
|
6481
|
+
}
|
|
6469
6482
|
if (message.type === 'done') {
|
|
6470
6483
|
port1.close();
|
|
6471
6484
|
completed.resolve();
|
|
@@ -6492,6 +6505,10 @@ const updateDiagnostics = async editor => {
|
|
|
6492
6505
|
return;
|
|
6493
6506
|
}
|
|
6494
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);
|
|
6495
6512
|
providers.set(message.providerId, {
|
|
6496
6513
|
diagnostics: message.diagnostics ?? [],
|
|
6497
6514
|
providerIndex: message.providerIndex ?? providers.size
|
|
@@ -6500,6 +6517,9 @@ const updateDiagnostics = async editor => {
|
|
|
6500
6517
|
return;
|
|
6501
6518
|
}
|
|
6502
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
|
+
}
|
|
6503
6523
|
if (providerCount === 0) {
|
|
6504
6524
|
providers.clear();
|
|
6505
6525
|
await commitDiagnostics(editor, generation, [], () => saveProviderResults(editor, providers));
|
|
@@ -6512,15 +6532,25 @@ const updateDiagnostics = async editor => {
|
|
|
6512
6532
|
}
|
|
6513
6533
|
} catch (error) {
|
|
6514
6534
|
port1.close();
|
|
6515
|
-
|
|
6516
|
-
|
|
6535
|
+
if (strict) {
|
|
6536
|
+
completed.reject(error);
|
|
6537
|
+
} else {
|
|
6538
|
+
completed.resolve();
|
|
6539
|
+
await handleError(error, editor);
|
|
6540
|
+
}
|
|
6517
6541
|
}
|
|
6518
6542
|
})();
|
|
6519
6543
|
};
|
|
6520
6544
|
port1.start();
|
|
6521
|
-
|
|
6545
|
+
const request = async () => {
|
|
6522
6546
|
const response = await getDiagnostics$1(editor, port2);
|
|
6547
|
+
if (finished) {
|
|
6548
|
+
return;
|
|
6549
|
+
}
|
|
6523
6550
|
if (Array.isArray(response) && providerCount === -1) {
|
|
6551
|
+
if (strict) {
|
|
6552
|
+
throw new Error('Diagnostic provider does not support completion and error reporting');
|
|
6553
|
+
}
|
|
6524
6554
|
providers.set('legacy', {
|
|
6525
6555
|
diagnostics: response,
|
|
6526
6556
|
providerIndex: 0
|
|
@@ -6529,12 +6559,27 @@ const updateDiagnostics = async editor => {
|
|
|
6529
6559
|
port1.close();
|
|
6530
6560
|
completed.resolve();
|
|
6531
6561
|
}
|
|
6532
|
-
|
|
6562
|
+
};
|
|
6563
|
+
try {
|
|
6564
|
+
await Promise.all([request(), completed.promise]);
|
|
6533
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
|
+
}
|
|
6534
6569
|
return isApplicable(latest, editor, generation) ? latest.newState : editor;
|
|
6535
6570
|
} catch (error) {
|
|
6536
|
-
|
|
6571
|
+
if (strict) {
|
|
6572
|
+
if (requestGenerations.get(editor.id) === generation) {
|
|
6573
|
+
requestGenerations.set(editor.id, generation + 1);
|
|
6574
|
+
}
|
|
6575
|
+
throw error;
|
|
6576
|
+
}
|
|
6537
6577
|
return handleError(error, editor);
|
|
6578
|
+
} finally {
|
|
6579
|
+
finished = true;
|
|
6580
|
+
clearTimeout(timeout);
|
|
6581
|
+
port1.close();
|
|
6582
|
+
port2.close();
|
|
6538
6583
|
}
|
|
6539
6584
|
};
|
|
6540
6585
|
const requestDiagnostics = editor => {
|
|
@@ -6555,6 +6600,18 @@ const updateDiagnosticsAll = async () => {
|
|
|
6555
6600
|
}
|
|
6556
6601
|
};
|
|
6557
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
|
+
|
|
6558
6615
|
const disposeEditor = async editorUid => {
|
|
6559
6616
|
const editor = get$8(editorUid)?.newState;
|
|
6560
6617
|
if (!editor) {
|
|
@@ -18264,6 +18321,7 @@ const commandMap = {
|
|
|
18264
18321
|
'Editor.updateDebugInfo': updateDebugInfo,
|
|
18265
18322
|
'Editor.updateDiagnostics': wrapCommand(requestDiagnostics),
|
|
18266
18323
|
'Editor.updateDiagnosticsAll': updateDiagnosticsAll,
|
|
18324
|
+
'Editor.waitForDiagnostics': waitForDiagnostics,
|
|
18267
18325
|
'EditorCompletion.close': close$3,
|
|
18268
18326
|
'EditorCompletion.closeDetails': closeDetails$1,
|
|
18269
18327
|
'EditorCompletion.focusFirst': focusFirst$1,
|