Skip to content

Commit

Permalink
controller should wait on pending cell additions per notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
amunger committed Aug 17, 2022
1 parent 252f16a commit 6e670d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/interactive-window/interactiveWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
if (this.kernelConnectionMetadata) {
this.pendingCellAdd = cellAddedPromise;
const controller = this.controllerRegistration.get(this.kernelConnectionMetadata, 'interactive');
controller?.setPendingCellAddition(cellAddedPromise);
controller?.setPendingCellAddition(this.notebookDocument, cellAddedPromise);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/notebooks/controllers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface IVSCodeNotebookController extends IDisposable {
asWebviewUri(localResource: vscode.Uri): vscode.Uri;
isAssociatedWithDocument(notebook: vscode.NotebookDocument): boolean;
updateConnection(connection: KernelConnectionMetadata): void;
setPendingCellAddition(promise: Promise<void>): void;
setPendingCellAddition(notebook: vscode.NotebookDocument, promise: Promise<void>): void;
}
export const IControllerRegistration = Symbol('IControllerRegistration');

Expand Down
15 changes: 10 additions & 5 deletions src/notebooks/controllers/vscodeNotebookController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
selected: boolean;
notebook: NotebookDocument;
}>();
private pendingCellAddition: Promise<void> | undefined;
private pendingCellAdditions = new Map<NotebookDocument, Promise<void>>();
private readonly _onDidDispose = new EventEmitter<void>();
private readonly disposables: IDisposable[] = [];
private notebookKernels = new WeakMap<NotebookDocument, IKernel>();
Expand Down Expand Up @@ -217,10 +217,12 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
* This only applies to the Interactive Window since cells are added from both the extension and core.
* @param promise A promise that resolves when the notebook is ready to handle more executions.
*/
public setPendingCellAddition(promise: Promise<void>): void {
if (this.viewType === InteractiveWindowView) {
this.pendingCellAddition = promise;
public setPendingCellAddition(notebook: NotebookDocument, promise: Promise<void>): void {
if (this.viewType !== InteractiveWindowView) {
throw new Error('setPendingCellAddition only applies to the Interactive Window');
}

this.pendingCellAdditions.set(notebook, promise);
}

public dispose() {
Expand All @@ -246,7 +248,10 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
if (cells.length < 1) {
return;
}
await this.pendingCellAddition;
if (this.pendingCellAdditions.has(notebook)) {
await this.pendingCellAdditions.get(notebook);
}

// Found on CI that sometimes VS Code calls this with old deleted cells.
// See here https://github.com/microsoft/vscode-jupyter/runs/5581627878?check_suite_focus=true
cells = cells.filter((cell) => {
Expand Down

0 comments on commit 6e670d8

Please sign in to comment.