From a2171fdd4281c11c59453837915c54a177b6e5ba Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 12 Apr 2022 13:36:57 -0700 Subject: [PATCH] raw cells should not stay in a pending exec state (#9634) --- news/2 Fixes/9633.md | 1 + src/notebooks/execution/cellExecution.node.ts | 4 ++++ .../execution/cellExecutionCreator.ts | 6 +++++- .../notebook/executionService.vscode.test.ts | 20 +++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 news/2 Fixes/9633.md diff --git a/news/2 Fixes/9633.md b/news/2 Fixes/9633.md new file mode 100644 index 00000000000..8e8d9cdc9fd --- /dev/null +++ b/news/2 Fixes/9633.md @@ -0,0 +1 @@ +Ensure `raw` cells do not stay in a pending execution state. diff --git a/src/notebooks/execution/cellExecution.node.ts b/src/notebooks/execution/cellExecution.node.ts index fef1e769370..138371002a2 100644 --- a/src/notebooks/execution/cellExecution.node.ts +++ b/src/notebooks/execution/cellExecution.node.ts @@ -195,6 +195,7 @@ export class CellExecution implements IDisposable { this.disposables ); NotebookCellStateTracker.setCellState(cell, NotebookCellExecutionState.Idle); + const execution = CellExecutionCreator.get(cell); if (this.canExecuteCell()) { // This has been queued for execution, hence clear all the output. // (possible solution for ) https://github.com/microsoft/vscode-jupyter/issues/7123 @@ -207,6 +208,9 @@ export class CellExecution implements IDisposable { // void tempTask.end(undefined); this.execution = CellExecutionCreator.getOrCreate(cell, this.controller); NotebookCellStateTracker.setCellState(cell, NotebookCellExecutionState.Pending); + } else if (execution) { + execution.start(); + execution.end(undefined); } } diff --git a/src/notebooks/execution/cellExecutionCreator.ts b/src/notebooks/execution/cellExecutionCreator.ts index 2204331e889..30679d35571 100644 --- a/src/notebooks/execution/cellExecutionCreator.ts +++ b/src/notebooks/execution/cellExecutionCreator.ts @@ -84,7 +84,7 @@ export class CellExecutionCreator { static getOrCreate(cell: NotebookCell, controller: NotebookController) { let cellExecution: NotebookCellExecutionWrapper | undefined; const key = cell.document.uri.toString(); - cellExecution = CellExecutionCreator._map.get(key); + cellExecution = this.get(cell); if (!cellExecution) { cellExecution = CellExecutionCreator.create(key, cell, controller); } else { @@ -105,6 +105,10 @@ export class CellExecutionCreator { } return cellExecution; } + static get(cell: NotebookCell) { + const key = cell.document.uri.toString(); + return CellExecutionCreator._map.get(key); + } private static create(key: string, cell: NotebookCell, controller: NotebookController) { const result = new NotebookCellExecutionWrapper( diff --git a/src/test/datascience/notebook/executionService.vscode.test.ts b/src/test/datascience/notebook/executionService.vscode.test.ts index 420a8e42282..a602e8672f0 100644 --- a/src/test/datascience/notebook/executionService.vscode.test.ts +++ b/src/test/datascience/notebook/executionService.vscode.test.ts @@ -850,6 +850,26 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () { waitForTextOutput(cell, 'after fail', 0, false) ]); }); + test('Raw cells should not get executed', async () => { + await insertCodeCell('print(1234)', { index: 0 }); + await insertCodeCell('Hello World', { index: 1, language: 'raw' }); + await insertCodeCell('print(5678)', { index: 2 }); + + const [cell1, cell2, cell3] = vscodeNotebook.activeNotebookEditor!.document.getCells(); + await Promise.all([ + runAllCellsInActiveNotebook(), + waitForCellExecutionToComplete(cell1), + waitForTextOutput(cell1, '1234', 0, false), + waitForCellExecutionToComplete(cell3), + waitForTextOutput(cell3, '5678', 0, false) + ]); + + // Second cell should not have been executed. + assert.isEmpty(cell2.outputs, 'Second cell should not have any output'); + assert.isUndefined(cell2.executionSummary?.executionOrder, 'Second cell should not have an execution order'); + assert.isUndefined(cell2.executionSummary?.timing, 'Second cell should not have execution times'); + assert.isUndefined(cell2.executionSummary?.success, 'Second cell should not have execution result'); + }); test('Run whole document and test status of cells', async () => { const cells = await insertRandomCells({ count: 4, addMarkdownCells: false });