Skip to content

Commit

Permalink
comments, restrict to IW, handle controller change
Browse files Browse the repository at this point in the history
  • Loading branch information
amunger committed Aug 16, 2022
1 parent 86decfd commit f928944
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/interactive-window/interactiveWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
private _submitters: Uri[] = [];
private fileInKernel: Uri | undefined;
private cellMatcher: CellMatcher;
private pendingCellAdd: Promise<void> | undefined;

private internalDisposables: Disposable[] = [];
private kernelDisposables: Disposable[] = [];
Expand Down Expand Up @@ -228,12 +229,15 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
this.start();
}

private setPendingCellAdd() {
/**
* Inform the controller that a cell is being added and it should wait before adding any others to the execution queue.
* @param cellAddedPromise - Promise that resolves when the cell execution has been queued
*/
private setPendingCellAdd(cellAddedPromise: Promise<void>) {
if (this.kernelConnectionMetadata) {
this.pendingCellAdd = cellAddedPromise;
const controller = this.controllerRegistration.get(this.kernelConnectionMetadata, 'interactive');
const deferred = createDeferred<void>();
controller?.setPendingCellAddition(deferred.promise);
return deferred;
controller?.setPendingCellAddition(cellAddedPromise);
}
}

Expand Down Expand Up @@ -264,6 +268,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
// Id may be different if the user switched controllers
this.currentKernelInfo.controller = k.controller;
this.currentKernelInfo.metadata = k.kernelConnectionMetadata;
!!this.pendingCellAdd && this.setPendingCellAdd(this.pendingCellAdd);
this.updateSysInfoMessage(
this.getSysInfoMessage(k.kernelConnectionMetadata, SysInfoReason.Start),
false,
Expand Down Expand Up @@ -573,7 +578,8 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {

// Multiple cells that have split our code.
const promises = cells.map((c) => {
const deferred = this.setPendingCellAdd();
const deferred = createDeferred<void>();
this.setPendingCellAdd(deferred.promise);
// Add the cell first. We don't need to wait for this part as we want to add them
// as quickly as possible
const notebookCellPromise = this.addNotebookCell(c, fileUri, line);
Expand Down
9 changes: 8 additions & 1 deletion src/notebooks/controllers/vscodeNotebookController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,15 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
traceInfoIfCI(`${ConsoleForegroundColors.Green}Posting message to Notebook UI ${messageType}`);
return this.controller.postMessage(message, editor);
}
/**
* A cell has been added to the notebook, so wait for the execution to be queued before handling any more execution requests.
* 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 {
this.pendingCellAddition = promise;
if (this.viewType === InteractiveWindowView) {
this.pendingCellAddition = promise;
}
}

public dispose() {
Expand Down

0 comments on commit f928944

Please sign in to comment.