Fix removal of trailing lines in ipynb

pull/234874/head
Don Jayamanne 2024-11-29 16:00:20 +11:00
parent 3e046cfd66
commit bcb7c86ad4
No known key found for this signature in database
GPG Key ID: 6E3F5E00E1354B5F
2 changed files with 13 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import { editorSelectionBackground } from '../../../../../platform/theme/common/
import { IUndoRedoService } from '../../../../../platform/undoRedo/common/undoRedo.js';
import { SaveReason } from '../../../../common/editor.js';
import { IResolvedTextFileEditorModel, stringToSnapshot } from '../../../../services/textfile/common/textfiles.js';
import { INotebookService } from '../../../notebook/common/notebookService.js';
import { IChatAgentResult } from '../../common/chatAgents.js';
import { ChatEditKind, IModifiedFileEntry, WorkingSetEntryState } from '../../common/chatEditingService.js';
import { IChatService } from '../../common/chatService.js';
@ -129,6 +130,7 @@ export class ChatEditingModifiedFileEntry extends Disposable implements IModifie
@IEditorWorkerService private readonly _editorWorkerService: IEditorWorkerService,
@IUndoRedoService private readonly _undoRedoService: IUndoRedoService,
@IFileService private readonly _fileService: IFileService,
@INotebookService private readonly _notebookService: INotebookService,
) {
super();
if (kind === ChatEditKind.Created) {
@ -392,7 +394,14 @@ export class ChatEditingModifiedFileEntry extends Disposable implements IModifie
if (this._allEditsAreFromUs) {
// save the file after discarding so that the dirty indicator goes away
// and so that an intermediate saved state gets reverted
await this.docFileEditorModel.save({ reason: SaveReason.EXPLICIT });
if (this._notebookService.hasSupportedNotebooks(this.modifiedURI)) {
// For notebooks ignore the save participant,
// For Jupyter notebooks, the JSON must always have an ending newline
// However save participants will remove that trailing new line.
await this.docFileEditorModel.save({ reason: SaveReason.EXPLICIT, skipSaveParticipants: true });
} else {
await this.docFileEditorModel.save({ reason: SaveReason.EXPLICIT });
}
}
await this.collapse(transaction);
}

View File

@ -12,6 +12,7 @@ import { IResolvedTextEditorModel, ITextModelService } from '../../../../../edit
import { IFileService } from '../../../../../platform/files/common/files.js';
import { IUndoRedoService } from '../../../../../platform/undoRedo/common/undoRedo.js';
import { IResolvedTextFileEditorModel } from '../../../../services/textfile/common/textfiles.js';
import { INotebookService } from '../../../notebook/common/notebookService.js';
import { ChatEditKind } from '../../common/chatEditingService.js';
import { IChatService } from '../../common/chatService.js';
import { ChatEditingModifiedFileEntry, IModifiedEntryTelemetryInfo } from './chatEditingModifiedFileEntry.js';
@ -31,8 +32,9 @@ export class ChatEditingModifiedNotebookEntry extends ChatEditingModifiedFileEnt
@IEditorWorkerService _editorWorkerService: IEditorWorkerService,
@IUndoRedoService _undoRedoService: IUndoRedoService,
@IFileService _fileService: IFileService,
@INotebookService _notebookService: INotebookService,
) {
super(resourceRef, _multiDiffEntryDelegate, _telemetryInfo, kind, initialContent, modelService, textModelService, languageService, _chatService, _editorWorkerService, _undoRedoService, _fileService);
super(resourceRef, _multiDiffEntryDelegate, _telemetryInfo, kind, initialContent, modelService, textModelService, languageService, _chatService, _editorWorkerService, _undoRedoService, _fileService, _notebookService);
this.resolveTextFileEditorModel = resourceRef.object as IResolvedTextFileEditorModel;
}