Skip to content

Commit

Permalink
Ensure execution_count is cleared when clearing outputs (#237301)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Jan 6, 2025
1 parent 08c8f1a commit 8cc255e
Show file tree
Hide file tree
Showing 5 changed files with 762 additions and 4 deletions.
8 changes: 6 additions & 2 deletions extensions/ipynb/src/deserializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ function getNotebookCellMetadata(cell: nbformat.IBaseCell): {
// We put this only for VSC to display in diff view.
// Else we don't use this.
const cellMetadata: CellMetadata = {};
if (cell.cell_type === 'code' && typeof cell['execution_count'] === 'number') {
cellMetadata.execution_count = cell['execution_count'];
if (cell.cell_type === 'code') {
if (typeof cell['execution_count'] === 'number') {
cellMetadata.execution_count = cell['execution_count'];
} else {
cellMetadata.execution_count = null;
}
}

if (cell['metadata']) {
Expand Down
7 changes: 7 additions & 0 deletions extensions/ipynb/src/notebookModelStoreSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ function onDidChangeNotebookCells(e: NotebookDocumentChangeEventEx) {
metadata.execution_count = null;
metadataUpdated = true;
pendingCellUpdates.delete(e.cell);
} else if (!e.executionSummary?.executionOrder && !e.executionSummary?.success && !e.executionSummary?.timing
&& !e.metadata && !e.outputs && currentMetadata.execution_count && !pendingCellUpdates.has(e.cell)) {
// This is a result of the cell without outupts but has execution count being cleared
// Create two cells, one that produces output and one that doesn't. Run both and then clear the output or all cells.
// This condition will be satisfied for first cell without outputs.
metadata.execution_count = null;
metadataUpdated = true;
}

if (e.document?.languageId && e.document?.languageId !== preferredCellLanguage && e.document?.languageId !== languageIdInMetadata) {
Expand Down
Loading

0 comments on commit 8cc255e

Please sign in to comment.