Skip to content

Commit 855f38c

Browse files
committed
Refactor self write mark handling
1 parent 7815f42 commit 855f38c

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

src/notebooks/deepnote/deepnoteFileChangeWatcher.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,14 @@ export class DeepnoteFileChangeWatcher implements IExtensionSyncActivationServic
387387

388388
// Save to clear dirty state. VS Code serializes (same bytes) and sees the
389389
// mtime from our recent write, so no "content is newer" conflict.
390-
this.markSelfWrite(fileUri);
390+
// NOTE: onDidSaveNotebookDocument handles the self-write mark for this save.
391391
try {
392392
const saved = await workspace.save(notebook.uri);
393393
if (!saved) {
394-
this.consumeSelfWrite(fileUri);
395394
logger.warn(`[FileChangeWatcher] Save after sync write returned undefined: ${notebook.uri.path}`);
396395
return;
397396
}
398397
} catch (saveError) {
399-
this.consumeSelfWrite(fileUri);
400398
logger.warn(`[FileChangeWatcher] Save after sync write failed: ${notebook.uri.path}`, saveError);
401399
}
402400
} catch (serializeError) {
@@ -566,14 +564,9 @@ export class DeepnoteFileChangeWatcher implements IExtensionSyncActivationServic
566564
return;
567565
}
568566

569-
// Save to sync mtime — mark as self-write first
570-
this.markSelfWrite(notebook.uri);
571-
try {
572-
await workspace.save(notebook.uri);
573-
} catch (error) {
574-
this.consumeSelfWrite(notebook.uri);
575-
throw error;
576-
}
567+
// Save to sync mtime.
568+
// NOTE: onDidSaveNotebookDocument handles the self-write mark for this save.
569+
await workspace.save(notebook.uri);
577570

578571
logger.info(`[FileChangeWatcher] Updated notebook outputs from external snapshot: ${notebook.uri.path}`);
579572
}
@@ -645,8 +638,9 @@ export class DeepnoteFileChangeWatcher implements IExtensionSyncActivationServic
645638
}
646639

647640
/**
648-
* Marks a URI as about to be written by us (workspace.save).
649-
* Call before workspace.save() to prevent the resulting fs event from triggering a reload.
641+
* Marks a URI as about to be written by us.
642+
* For workspace.fs.writeFile(): call this before the write.
643+
* For workspace.save(): do NOT call this — onDidSaveNotebookDocument handles it.
650644
*/
651645
private markSelfWrite(uri: Uri): void {
652646
const key = this.normalizeFileUri(uri);

0 commit comments

Comments
 (0)