Skip to content

Commit 1d8f3ee

Browse files
committed
fix: manage reset state patch
1 parent 3998829 commit 1d8f3ee

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

src/controller.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,23 +386,40 @@ export class PlutoNotebookController {
386386
// );
387387
// }
388388
}
389-
private updateAllCellsFromState = (
389+
private updateAllCellsFromState = async (
390390
notebook: vscode.NotebookDocument,
391391
update: UpdateEvent
392392
) => {
393+
console.warn("Using nuclear reset flow");
393394
// Optimistically send data. May be ignored.
394395
// If not ignored, this makes sure logs, stdout and progress
395396
// are properly propagated to state object
396397
const fullNotebookState = update.notebook;
397-
Object.entries(fullNotebookState?.cell_results ?? {}).forEach(
398-
([cell_id, state]) => {
399-
this.sendMessageToRenderer(notebook, {
400-
type: "setState",
401-
state,
402-
cell_id,
403-
});
398+
for (const [cell_id, state] of Object.entries(
399+
fullNotebookState?.cell_results ?? {}
400+
)) {
401+
const start = Date.now();
402+
const execution = this.startExecution(cell_id, notebook);
403+
try {
404+
await execution.replaceOutput([formatCellOutput(state)]);
405+
} catch (e) {
406+
console.error(e);
407+
//
404408
}
405-
);
409+
if (!state.queued || !state.running) {
410+
// This results to many "cannot resolve twice" messages
411+
try {
412+
execution.end(!state.errored, start + (state.runtime ?? 0) / 1000);
413+
} catch (x) {
414+
console.error(x);
415+
}
416+
}
417+
this.sendMessageToRenderer(notebook, {
418+
type: "setState",
419+
state,
420+
cell_id,
421+
});
422+
}
406423
};
407424

408425
/**
@@ -424,6 +441,11 @@ export class PlutoNotebookController {
424441
for (const patch of patches) {
425442
const path = patch.path;
426443
const [action, ...rest] = path;
444+
if (path.length === 0 && patches.length === 0) {
445+
// This is a state reset; handle it accordingly
446+
anyWeird = true;
447+
break;
448+
}
427449
switch (action) {
428450
case "bonds": {
429451
// TODO here we do bound send to the renderers
@@ -568,7 +590,7 @@ export class PlutoNotebookController {
568590
// Update the cell's metadata with the Pluto cell ID
569591
const edit = new vscode.WorkspaceEdit();
570592
const cellMetadata = {
571-
...addedCell.metadata,
593+
...addedCell?.metadata,
572594
pluto_cell_id: cellId,
573595
};
574596

0 commit comments

Comments
 (0)