Ensure notebook execution count is cleared only when necessary

pull/234627/head
Don Jayamanne 2024-11-26 03:17:39 +01:00 committed by GitHub
parent 9324d6c826
commit 2a3b61a82c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -123,6 +123,7 @@ function trackAndUpdateCellMetadata(notebook: NotebookDocument, updates: { cell:
promise.then(clean, clean);
}
const pendingCellUpdates = new WeakSet<NotebookCell>();
function onDidChangeNotebookCells(e: NotebookDocumentChangeEventEx) {
if (!isSupportedNotebook(e.notebook)) {
return;
@ -155,11 +156,15 @@ function onDidChangeNotebookCells(e: NotebookDocumentChangeEventEx) {
// Thus this is a change in metadata, which we will need to update in the model.
metadata.execution_count = null;
metadataUpdated = true;
// Note: We will get another event for this, see below for the check.
// track the fact that we're expecting an update for this cell.
pendingCellUpdates.add(e.cell);
} else if ((!e.executionSummary || (!e.executionSummary?.executionOrder && !e.executionSummary?.success && !e.executionSummary?.timing))
&& !e.metadata && !e.outputs && currentMetadata.execution_count) {
// This is a result of the previous cell being cleared.
&& !e.metadata && !e.outputs && currentMetadata.execution_count && pendingCellUpdates.has(e.cell)) {
// This is a result of the cell being cleared (i.e. we perfomed an update request and this is now the update event).
metadata.execution_count = null;
metadataUpdated = true;
pendingCellUpdates.delete(e.cell);
}
if (e.document?.languageId && e.document?.languageId !== preferredCellLanguage && e.document?.languageId !== languageIdInMetadata) {