diff --git a/src/vs/workbench/contrib/notebook/browser/diff/cellComponents.ts b/src/vs/workbench/contrib/notebook/browser/diff/cellComponents.ts index f65fa0e43ceb964b08e91ec40af5f401a0785042..65fbd162cec07678046b08f4f98ce2ebe6473895 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/cellComponents.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/cellComponents.ts @@ -220,8 +220,12 @@ abstract class AbstractCellRenderer extends Disposable { this._updateFoldingIcon(); } - private _getFormatedJSON(metadata: NotebookCellMetadata) { - const content = JSON.stringify(metadata); + private _getFormatedJSON(metadata: NotebookCellMetadata, language?: string) { + const content = JSON.stringify({ + language, + ...metadata + }); + const edits = format(content, undefined, {}); const metadataSource = applyEdits(content, edits); @@ -230,8 +234,8 @@ abstract class AbstractCellRenderer extends Disposable { private _buildMetadataEditor() { if (this.cell.type === 'modified') { - const originalMetadataSource = this._getFormatedJSON(this.cell.original?.metadata || {}); - const modifiedMetadataSource = this._getFormatedJSON(this.cell.modified?.metadata || {}); + const originalMetadataSource = this._getFormatedJSON(this.cell.original?.metadata || {}, this.cell.original?.language); + const modifiedMetadataSource = this._getFormatedJSON(this.cell.modified?.metadata || {}, this.cell.modified?.language); if (originalMetadataSource !== modifiedMetadataSource) { this._metadataEditor = this.instantiationService.createInstance(DiffEditorWidget, this._metadataEditorContainer!, { ...fixedDiffEditorOptions