mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-08 07:44:33 +01:00
Move notebook diff class into its own file (#242380)
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
|
||||
import { computeDiff } from '../../../notebook/browser/diff/notebookDiffViewModel.js';
|
||||
import { INotebookEditorModelResolverService } from '../../../notebook/common/notebookEditorModelResolverService.js';
|
||||
import { INotebookLoggingService } from '../../../notebook/common/notebookLoggingService.js';
|
||||
import { INotebookEditorWorkerService } from '../../../notebook/common/services/notebookWorkerService.js';
|
||||
import { IEditSessionEntryDiff } from '../../common/chatEditingService.js';
|
||||
import { ISnapshotEntry } from './chatEditingModifiedFileEntry.js';
|
||||
|
||||
export class ChatEditingModifiedNotebookDiff {
|
||||
static NewModelCounter: number = 0;
|
||||
constructor(
|
||||
private readonly original: ISnapshotEntry,
|
||||
private readonly modified: ISnapshotEntry,
|
||||
@INotebookEditorWorkerService private readonly notebookEditorWorkerService: INotebookEditorWorkerService,
|
||||
@INotebookLoggingService private readonly notebookLoggingService: INotebookLoggingService,
|
||||
@INotebookEditorModelResolverService private readonly notebookEditorModelService: INotebookEditorModelResolverService,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
async computeDiff(): Promise<IEditSessionEntryDiff> {
|
||||
|
||||
let added = 0;
|
||||
let removed = 0;
|
||||
|
||||
const disposables = new DisposableStore();
|
||||
try {
|
||||
const [modifiedRef, originalRef] = await Promise.all([
|
||||
this.notebookEditorModelService.resolve(this.modified.snapshotUri),
|
||||
this.notebookEditorModelService.resolve(this.original.snapshotUri)
|
||||
]);
|
||||
disposables.add(modifiedRef);
|
||||
disposables.add(originalRef);
|
||||
const notebookDiff = await this.notebookEditorWorkerService.computeDiff(this.original.snapshotUri, this.modified.snapshotUri);
|
||||
const result = computeDiff(originalRef.object.notebook, modifiedRef.object.notebook, notebookDiff);
|
||||
result.cellDiffInfo.forEach(diff => {
|
||||
switch (diff.type) {
|
||||
case 'modified':
|
||||
case 'insert':
|
||||
added++;
|
||||
break;
|
||||
case 'delete':
|
||||
removed++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
this.notebookLoggingService.error('Notebook Chat', 'Error computing diff:\n' + e);
|
||||
} finally {
|
||||
disposables.dispose();
|
||||
}
|
||||
|
||||
return {
|
||||
added,
|
||||
removed,
|
||||
identical: added === 0 && removed === 0,
|
||||
quitEarly: false,
|
||||
modifiedURI: this.modified.snapshotUri,
|
||||
originalURI: this.original.snapshotUri,
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
-58
@@ -53,7 +53,7 @@ import { INotebookEditorModelResolverService } from '../../../notebook/common/no
|
||||
import { INotebookLoggingService } from '../../../notebook/common/notebookLoggingService.js';
|
||||
import { INotebookService } from '../../../notebook/common/notebookService.js';
|
||||
import { INotebookEditorWorkerService } from '../../../notebook/common/services/notebookWorkerService.js';
|
||||
import { ChatEditKind, IEditSessionEntryDiff, IModifiedFileEntryEditorIntegration, WorkingSetEntryState } from '../../common/chatEditingService.js';
|
||||
import { ChatEditKind, IModifiedFileEntryEditorIntegration, WorkingSetEntryState } from '../../common/chatEditingService.js';
|
||||
import { IChatResponseModel } from '../../common/chatModel.js';
|
||||
import { IChatService } from '../../common/chatService.js';
|
||||
import { IDocumentDiff2 } from './chatEditingCodeEditorIntegration.js';
|
||||
@@ -67,63 +67,6 @@ const noopKeep = () => Promise.resolve(true);
|
||||
const noopUndo = () => Promise.resolve(true);
|
||||
const SnapshotLanguageId = 'VSCodeChatNotebookSnapshotLanguage';
|
||||
|
||||
export class ChatEditingModifiedNotebookDiff {
|
||||
static NewModelCounter: number = 0;
|
||||
constructor(
|
||||
private readonly original: ISnapshotEntry,
|
||||
private readonly modified: ISnapshotEntry,
|
||||
@INotebookEditorWorkerService private readonly notebookEditorWorkerService: INotebookEditorWorkerService,
|
||||
@INotebookLoggingService private readonly notebookLoggingService: INotebookLoggingService,
|
||||
@INotebookEditorModelResolverService private readonly notebookEditorModelService: INotebookEditorModelResolverService,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
async computeDiff(): Promise<IEditSessionEntryDiff> {
|
||||
|
||||
let added = 0;
|
||||
let removed = 0;
|
||||
|
||||
const disposables = new DisposableStore();
|
||||
try {
|
||||
const [modifiedRef, originalRef] = await Promise.all([
|
||||
this.notebookEditorModelService.resolve(this.modified.snapshotUri),
|
||||
this.notebookEditorModelService.resolve(this.original.snapshotUri)
|
||||
]);
|
||||
disposables.add(modifiedRef);
|
||||
disposables.add(originalRef);
|
||||
const notebookDiff = await this.notebookEditorWorkerService.computeDiff(this.original.snapshotUri, this.modified.snapshotUri);
|
||||
const result = computeDiff(originalRef.object.notebook, modifiedRef.object.notebook, notebookDiff);
|
||||
result.cellDiffInfo.forEach(diff => {
|
||||
switch (diff.type) {
|
||||
case 'modified':
|
||||
case 'insert':
|
||||
added++;
|
||||
break;
|
||||
case 'delete':
|
||||
removed++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
this.notebookLoggingService.error('Notebook Chat', 'Error computing diff:\n' + e);
|
||||
} finally {
|
||||
disposables.dispose();
|
||||
}
|
||||
|
||||
return {
|
||||
added,
|
||||
removed,
|
||||
identical: added === 0 && removed === 0,
|
||||
quitEarly: false,
|
||||
modifiedURI: this.modified.snapshotUri,
|
||||
originalURI: this.original.snapshotUri,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class ChatEditingModifiedNotebookEntry extends AbstractChatEditingModifiedFileEntry {
|
||||
static NewModelCounter: number = 0;
|
||||
private readonly modifiedModel: NotebookTextModel;
|
||||
|
||||
@@ -49,8 +49,9 @@ import { AbstractChatEditingModifiedFileEntry, IModifiedEntryTelemetryInfo, ISna
|
||||
import { ChatEditingModifiedDocumentEntry } from './chatEditingModifiedDocumentEntry.js';
|
||||
import { ChatEditingTextModelContentProvider } from './chatEditingTextModelContentProviders.js';
|
||||
import { CellUri, ICellEditOperation } from '../../../notebook/common/notebookCommon.js';
|
||||
import { ChatEditingModifiedNotebookDiff, ChatEditingModifiedNotebookEntry } from './chatEditingModifiedNotebookEntry.js';
|
||||
import { ChatEditingModifiedNotebookEntry } from './chatEditingModifiedNotebookEntry.js';
|
||||
import { CancellationToken } from '../../../../../base/common/cancellation.js';
|
||||
import { ChatEditingModifiedNotebookDiff } from './chatEditingModifiedNotebookDiff.js';
|
||||
|
||||
const STORAGE_CONTENTS_FOLDER = 'contents';
|
||||
const STORAGE_STATE_FILE = 'state.json';
|
||||
|
||||
Reference in New Issue
Block a user