Ensure cells do not have an internalId initially (#244000)

This commit is contained in:
Don Jayamanne
2025-03-20 10:33:14 +11:00
committed by GitHub
parent e016a289d8
commit c17c56473f
2 changed files with 11 additions and 11 deletions
@@ -5,6 +5,7 @@
import { streamToBuffer } from '../../../../../base/common/buffer.js';
import { CancellationToken } from '../../../../../base/common/cancellation.js';
import { StringSHA1 } from '../../../../../base/common/hash.js';
import { DisposableStore, IReference } from '../../../../../base/common/lifecycle.js';
import { ResourceMap, ResourceSet } from '../../../../../base/common/map.js';
import { Schemas } from '../../../../../base/common/network.js';
@@ -125,11 +126,10 @@ export class ChatEditingModifiedNotebookEntry extends AbstractChatEditingModifie
restoreSnapshot(originalRef.object.notebook, initialContent);
const edits: ICellEditOperation[] = [];
notebook.cells.forEach((cell, index) => {
const internalId = cell.internalMetadata?.internalId;
if (internalId) {
edits.push({ editType: CellEditType.PartialInternalMetadata, index, internalMetadata: { internalId } });
}
const internalId = generateCellHash(cell.uri);
edits.push({ editType: CellEditType.PartialInternalMetadata, index, internalMetadata: { internalId } });
});
resourceRef.object.notebook.applyEdits(edits, true, undefined, () => undefined, undefined, true);
originalRef.object.notebook.applyEdits(edits, true, undefined, () => undefined, undefined, true);
}
const instance = instantiationService.createInstance(ChatEditingModifiedNotebookEntry, resourceRef, originalRef, _multiDiffEntryDelegate, options.serializer.options, telemetryInfo, chatKind, initialContent);
@@ -944,3 +944,10 @@ export class ChatEditingModifiedNotebookEntry extends AbstractChatEditingModifie
return cellEntry;
}
}
function generateCellHash(cellUri: URI) {
const hash = new StringSHA1();
hash.update(cellUri.toString());
return hash.digest().substring(0, 8);
}
@@ -209,7 +209,6 @@ export class NotebookCellTextModel extends Disposable implements ICell {
this._outputs = outputs.map(op => new NotebookCellOutputTextModel(op));
this._metadata = metadata ?? {};
this._internalMetadata = internalMetadata ?? {};
this._internalMetadata.internalId ??= generateCellHash(uri);
}
enableAutoLanguageDetection() {
@@ -570,9 +569,3 @@ export function sortObjectPropertiesRecursively(obj: any): any {
}
return obj;
}
function generateCellHash(cellUri: URI) {
const hash = new StringSHA1();
hash.update(cellUri.toString());
return hash.digest().substring(0, 8);
}