@@ -16,22 +16,21 @@ import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/note
1616import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService' ;
1717import { NotebookDiffEditorInput } from './notebookDiffEditorInput' ;
1818import { CancellationToken } from 'vs/base/common/cancellation' ;
19- import { IDiffResult , LcsDiff } from 'vs/base/common/diff/diff' ;
20- import { CellSequence , INotebookDiffEditorModel } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
19+ import { INotebookDiffEditorModel , INotebookDiffResult } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
2120import { INotebookDeltaDecoration } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
2221import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
2322import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel' ;
2423import { MarkdownCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel' ;
2524import { FileService } from 'vs/platform/files/common/fileService' ;
2625import { IFileService } from 'vs/platform/files/common/files' ;
27- import { DiffComputer } from 'vs/editor/common/diff/diffComputer' ;
2826import { createDecoration , DECORATIONS , isChangeOrDelete , isChangeOrInsert } from 'vs/editor/browser/widget/diffEditorWidget' ;
2927import * as editorCommon from 'vs/editor/common/editorCommon' ;
3028import { Color } from 'vs/base/common/color' ;
3129import { IModelDeltaDecoration , IReadonlyTextBuffer } from 'vs/editor/common/model' ;
3230import { Range } from 'vs/editor/common/core/range' ;
3331import { Constants } from 'vs/base/common/uint' ;
3432import { defaultInsertColor , defaultRemoveColor , diffInserted , diffRemoved } from 'vs/platform/theme/common/colorRegistry' ;
33+ import { INotebookEditorWorkerService } from 'vs/workbench/contrib/notebook/common/services/notebookWorkerService' ;
3534
3635export class NotebookDiffEditor extends BaseEditor {
3736 static readonly ID : string = 'workbench.editor.notebookDiffEditor' ;
@@ -52,6 +51,7 @@ export class NotebookDiffEditor extends BaseEditor {
5251 @ITelemetryService telemetryService : ITelemetryService ,
5352 @IInstantiationService private readonly instantiationService : IInstantiationService ,
5453 @IStorageService storageService : IStorageService ,
54+ @INotebookEditorWorkerService private readonly notebookEditorWorkerService : INotebookEditorWorkerService
5555 ) {
5656 super ( NotebookDiffEditor . ID , telemetryService , themeService , storageService ) ;
5757
@@ -149,10 +149,9 @@ export class NotebookDiffEditor extends BaseEditor {
149149 }
150150
151151 private _update ( model : INotebookDiffEditorModel ) {
152- const diff = new LcsDiff ( new CellSequence ( model . original . notebook ) , new CellSequence ( model . modified . notebook ) ) ;
153- const diffResult = diff . ComputeDiff ( false ) ;
154-
155- this . _adjustHeight ( diffResult ) ;
152+ this . notebookEditorWorkerService . computeDiff ( model . original . notebook . uri , model . modified . notebook . uri ) . then ( diffResult => {
153+ this . _adjustHeight ( diffResult ) ;
154+ } ) ;
156155 }
157156
158157 private _setStrategy ( newStrategy : DiffEditorWidgetSideBySide ) : void {
@@ -162,13 +161,12 @@ export class NotebookDiffEditor extends BaseEditor {
162161
163162 this . _strategy = newStrategy ;
164163 newStrategy . applyColors ( this . themeService . getColorTheme ( ) ) ;
165-
166- // if (this._diffComputationResult) {
167- // this._updateDecorations();
168- // }
169164 }
170165
171- private _adjustHeight ( diffResult : IDiffResult ) {
166+ private _adjustHeight ( notebookDiffResult : INotebookDiffResult ) {
167+ const diffResult = notebookDiffResult . cellsDiff ;
168+ const linesDiffResult = notebookDiffResult . linesDiff ;
169+
172170 if ( ! this . _widget || ! this . _originalWidget ) {
173171 return ;
174172 }
@@ -211,67 +209,37 @@ export class NotebookDiffEditor extends BaseEditor {
211209 } ;
212210
213211 viewLayoutUpdateDisposables . push ( ...[
214- ...originalCells . map ( cell => ( cell instanceof CodeCellViewModel ) ? cell . onDidChangeLayout ( e => update ( ) ) : ( cell as MarkdownCellViewModel ) . onDidChangeLayout ( e => update ( ) ) ) ,
215- ...modifiedCells . map ( cell => ( cell instanceof CodeCellViewModel ) ? cell . onDidChangeLayout ( e => update ( ) ) : ( cell as MarkdownCellViewModel ) . onDidChangeLayout ( e => update ( ) ) ) ,
212+ ...originalCells . map ( cell => ( cell instanceof CodeCellViewModel ) ? cell . onDidChangeLayout ( ( ) => update ( ) ) : ( cell as MarkdownCellViewModel ) . onDidChangeLayout ( ( ) => update ( ) ) ) ,
213+ ...modifiedCells . map ( cell => ( cell instanceof CodeCellViewModel ) ? cell . onDidChangeLayout ( ( ) => update ( ) ) : ( cell as MarkdownCellViewModel ) . onDidChangeLayout ( ( ) => update ( ) ) ) ,
216214 ] ) ;
215+
216+ update ( ) ;
217217 } ) ;
218218
219- // console.log(diffResult);
220219
221- diffResult . changes . forEach ( change => {
222- if ( change . modifiedLength === 0 ) {
223- // deletion ...
224- return ;
225- }
220+ linesDiffResult . forEach ( diff => {
221+ const originalCell = this . _originalWidget ! . viewModel ! . viewCells . find ( cell => cell . handle === diff . originalCellhandle ) ;
222+ const modifiedCell = this . _widget ! . viewModel ! . viewCells . find ( cell => cell . handle === diff . modifiedCellhandle ) ;
226223
227- if ( change . originalLength === 0 ) {
228- // insertion
224+ if ( ! originalCell || ! modifiedCell ) {
229225 return ;
230226 }
231227
232- for ( let i = 0 , len = Math . min ( change . modifiedLength , change . originalLength ) ; i < len ; i ++ ) {
233- let originalIndex = change . originalStart + i ;
234- let modifiedIndex = change . modifiedStart + i ;
235-
236- const originalCell = this . _originalWidget ! . viewModel ! . viewCells [ originalIndex ] ;
237- const modifiedCell = this . _widget ! . viewModel ! . viewCells [ modifiedIndex ] ;
238-
239- if ( originalCell . getText ( ) !== modifiedCell . getText ( ) ) {
240- // console.log(`original cell ${originalIndex} content change`);
241- const originalLines = originalCell . textBuffer . getLinesContent ( ) ;
242- const modifiedLines = modifiedCell . textBuffer . getLinesContent ( ) ;
243- const diffComputer = new DiffComputer ( originalLines , modifiedLines , {
244- shouldComputeCharChanges : true ,
245- shouldPostProcessCharChanges : true ,
246- shouldIgnoreTrimWhitespace : false ,
247- shouldMakePrettyDiff : true ,
248- maxComputationTime : 5000
249- } ) ;
250-
251- const lineChanges = diffComputer . computeDiff ( ) . changes ;
252- const lineDecorations = this . _strategy . getEditorsDiffDecorations ( lineChanges , false , false , originalCell . textBuffer , modifiedCell . textBuffer ) ;
253-
254- this . _originalWidget ?. changeModelDecorations ( accessor => {
255- accessor . deltaDecorations ( [ ] , [ {
256- ownerId : originalCell . handle ,
257- decorations : lineDecorations . original . decorations
258- } ] ) ;
259- } ) ;
260-
261- this . _widget ?. changeModelDecorations ( accessor => {
262- accessor . deltaDecorations ( [ ] , [ {
263- ownerId : modifiedCell . handle ,
264- decorations : lineDecorations . modified . decorations
265- } ] ) ;
266- } ) ;
267-
268- // console.log(lineDecorations);
269-
270- } else {
271- // console.log(`original cell ${originalIndex} metadata change`);
272- }
273-
274- }
228+ const lineDecorations = this . _strategy . getEditorsDiffDecorations ( diff . lineChanges , false , false , originalCell . textBuffer , modifiedCell . textBuffer ) ;
229+
230+ this . _originalWidget ?. changeModelDecorations ( accessor => {
231+ accessor . deltaDecorations ( [ ] , [ {
232+ ownerId : diff . originalCellhandle ,
233+ decorations : lineDecorations . original . decorations
234+ } ] ) ;
235+ } ) ;
236+
237+ this . _widget ?. changeModelDecorations ( accessor => {
238+ accessor . deltaDecorations ( [ ] , [ {
239+ ownerId : diff . modifiedCellhandle ,
240+ decorations : lineDecorations . modified . decorations
241+ } ] ) ;
242+ } ) ;
275243 } ) ;
276244
277245 this . _originalCellDecorations = this . _originalWidget . deltaCellDecorations ( this . _originalCellDecorations , originalDecorations ) ;
@@ -362,29 +330,16 @@ export class DiffEditorWidgetSideBySide extends Disposable {
362330 }
363331
364332 public getEditorsDiffDecorations ( lineChanges : editorCommon . ILineChange [ ] , ignoreTrimWhitespace : boolean , renderIndicators : boolean , originalModel : IReadonlyTextBuffer , modifiedModel : IReadonlyTextBuffer ) : IEditorsDiffDecorationsWithZones {
365- // Get view zones
366- // modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => {
367- // return a.afterLineNumber - b.afterLineNumber;
368- // });
369- // originalWhitespaces = originalWhitespaces.sort((a, b) => {
370- // return a.afterLineNumber - b.afterLineNumber;
371- // });
372- // let zones = this._getViewZones(lineChanges, originalWhitespaces, modifiedWhitespaces, originalEditor, modifiedEditor, renderIndicators);
373-
374333 // Get decorations & overview ruler zones
375334 let originalDecorations = this . _getOriginalEditorDecorations ( lineChanges , ignoreTrimWhitespace , renderIndicators , originalModel ) ;
376335 let modifiedDecorations = this . _getModifiedEditorDecorations ( lineChanges , ignoreTrimWhitespace , renderIndicators , modifiedModel ) ;
377336
378337 return {
379338 original : {
380339 decorations : originalDecorations . decorations ,
381- // overviewZones: originalDecorations.overviewZones,
382- // zones: zones.original
383340 } ,
384341 modified : {
385342 decorations : modifiedDecorations . decorations ,
386- // overviewZones: modifiedDecorations.overviewZones,
387- // zones: zones.modified
388343 }
389344 } ;
390345 }
0 commit comments