Skip to content

Commit e2d546f

Browse files
committed
wip
1 parent 7d9c6cf commit e2d546f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/kernels/execution/cellExecutionMessageHandlerService.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ export class CellExecutionMessageHandlerService {
7575
);
7676
// This object must be kept in memory has it monitors the kernel messages.
7777
this.messageHandlers.set(cell, handler);
78+
handler.completed.finally(() => {
79+
const info = this.workspaceStorage.get<
80+
| {
81+
index: number;
82+
msg_id: string;
83+
}
84+
| undefined
85+
>(`LAST_EXECUTED_CELL_${cell.notebook.uri.toString()}`, undefined);
86+
if (
87+
!info ||
88+
info.index !== cell.index ||
89+
cell.document.isClosed ||
90+
info?.msg_id !== options.request?.msg.header.msg_id
91+
) {
92+
return;
93+
}
94+
this.workspaceStorage
95+
.update(`LAST_EXECUTED_CELL_${cell.notebook.uri.toString()}`, undefined)
96+
.then(noop, noop);
97+
});
7898
return handler;
7999
}
80100
public registerListenerForResumingExecution(

src/notebooks/controllers/vscodeNotebookController.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
247247
);
248248
}
249249
private readonly pendingOutuptsOfNotebooks = new WeakSet<NotebookDocument>();
250+
private readonly restoredConnections = new WeakSet<NotebookDocument>();
250251
public async restoreOutput(notebook: NotebookDocument) {
251252
console.error('Done');
252253
const kernel = await this.connectToKernel(notebook, new DisplayOptions(true));
@@ -270,6 +271,10 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
270271
console.error('Done', kernel.uri, kernelExecution.pendingCells.length);
271272
}
272273
public async restoreConnection(notebook: NotebookDocument) {
274+
if (this.restoredConnections.has(notebook)) {
275+
return;
276+
}
277+
this.restoredConnections.add(notebook);
273278
console.error('Done');
274279
const kernel = await this.connectToKernel(notebook, new DisplayOptions(true));
275280
const kernelExecution = this.kernelProvider.getKernelExecution(kernel);
@@ -309,13 +314,20 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
309314
lastExecutionInfo &&
310315
typeof lastExecutionInfo.index === 'number'
311316
) {
317+
let resumed = false;
318+
kernel.session.kernel.statusChanged.connect((_, status) => {
319+
console.log(status);
320+
});
312321
kernel.session.kernel.anyMessage.connect((_, msg) => {
322+
if (msg.direction === 'send' || resumed) {
323+
return;
324+
}
313325
if (
314-
msg.direction === 'recv' &&
315326
msg.msg.parent_header &&
316327
'msg_id' in msg.msg.parent_header &&
317328
msg.msg.parent_header.msg_id === lastExecutionInfo.msg_id
318329
) {
330+
resumed = true;
319331
kernelExecution
320332
.resumeCellExecution(notebook.cellAt(lastExecutionInfo.index), lastExecutionInfo.msg_id)
321333
.catch(noop);

0 commit comments

Comments
 (0)