@@ -37,8 +37,9 @@ import { ButtonBar } from 'vs/base/browser/ui/button/button';
37
37
import { defaultButtonStyles } from 'vs/platform/theme/browser/defaultStyles' ;
38
38
import { Mutable } from 'vs/base/common/types' ;
39
39
import { IResourceDiffEditorInput } from 'vs/workbench/common/editor' ;
40
- import { IMultiDiffEditorOptions } from 'vs/editor/browser/widget/multiDiffEditor/multiDiffEditorWidgetImpl' ;
40
+ import { IMultiDiffEditorOptions , IMultiDiffResourceId } from 'vs/editor/browser/widget/multiDiffEditor/multiDiffEditorWidgetImpl' ;
41
41
import { IRange } from 'vs/editor/common/core/range' ;
42
+ import { CachedFunction , LRUCachedFunction } from 'vs/base/common/cache' ;
42
43
43
44
const enum State {
44
45
Data = 'data' ,
@@ -70,8 +71,6 @@ export class BulkEditPane extends ViewPane {
70
71
private _currentResolve ?: ( edit ?: ResourceEdit [ ] ) => void ;
71
72
private _currentInput ?: BulkFileOperations ;
72
73
private _currentProvider ?: BulkEditPreviewProvider ;
73
- private _fileOperations ?: BulkFileOperation [ ] ;
74
- private _resources ?: IResourceDiffEditorInput [ ] ;
75
74
76
75
constructor (
77
76
options : IViewletViewOptions ,
@@ -345,12 +344,13 @@ export class BulkEditPane extends ViewPane {
345
344
return ;
346
345
}
347
346
348
- const resources = await this . _resolveResources ( fileOperations ) ;
347
+ const result = await this . _computeResourceDiffEditorInputs . get ( fileOperations ) ;
348
+ const resourceId = await result . getResourceDiffEditorInputIdOfOperation ( fileElement . edit ) ;
349
349
const options : Mutable < IMultiDiffEditorOptions > = {
350
350
...e . editorOptions ,
351
351
viewState : {
352
352
revealData : {
353
- resource : { original : fileElement . edit . uri } ,
353
+ resource : resourceId ,
354
354
range : selection ,
355
355
}
356
356
}
@@ -359,49 +359,56 @@ export class BulkEditPane extends ViewPane {
359
359
const label = 'Refactor Preview' ;
360
360
this . _editorService . openEditor ( {
361
361
multiDiffSource,
362
- resources,
363
362
label,
364
363
options,
365
364
isTransient : true ,
366
- description : label
365
+ description : label ,
366
+ resources : result . resources
367
367
} , e . sideBySide ? SIDE_GROUP : ACTIVE_GROUP ) ;
368
368
}
369
369
370
- private async _resolveResources ( fileOperations : BulkFileOperation [ ] ) : Promise < IResourceDiffEditorInput [ ] > {
371
- if ( this . _fileOperations === fileOperations && this . _resources ) {
372
- return this . _resources ;
373
- }
374
- const sortedFileOperations = fileOperations . sort ( compareBulkFileOperations ) ;
375
- const resources : IResourceDiffEditorInput [ ] = [ ] ;
376
- for ( const operation of sortedFileOperations ) {
377
- const operationUri = operation . uri ;
378
- const previewUri = this . _currentProvider ! . asPreviewUri ( operationUri ) ;
379
- // delete -> show single editor
380
- if ( operation . type & BulkFileOperationType . Delete ) {
381
- resources . push ( {
370
+ private readonly _computeResourceDiffEditorInputs = new LRUCachedFunction ( async ( fileOperations : BulkFileOperation [ ] ) => {
371
+ const computeDiffEditorInput = new CachedFunction < BulkFileOperation , Promise < IResourceDiffEditorInput > > ( async ( fileOperation ) => {
372
+ const fileOperationUri = fileOperation . uri ;
373
+ const previewUri = this . _currentProvider ! . asPreviewUri ( fileOperationUri ) ;
374
+ // delete
375
+ if ( fileOperation . type & BulkFileOperationType . Delete ) {
376
+ return {
382
377
original : { resource : undefined } ,
383
378
modified : { resource : URI . revive ( previewUri ) }
384
- } ) ;
379
+ } ;
385
380
386
- } else {
387
- // rename, create, edits -> show diff editr
381
+ }
382
+ // rename, create, edits
383
+ else {
388
384
let leftResource : URI | undefined ;
389
385
try {
390
- ( await this . _textModelService . createModelReference ( operationUri ) ) . dispose ( ) ;
391
- leftResource = operationUri ;
386
+ ( await this . _textModelService . createModelReference ( fileOperationUri ) ) . dispose ( ) ;
387
+ leftResource = fileOperationUri ;
392
388
} catch {
393
389
leftResource = BulkEditPreviewProvider . emptyPreview ;
394
390
}
395
- resources . push ( {
391
+ return {
396
392
original : { resource : URI . revive ( leftResource ) } ,
397
393
modified : { resource : URI . revive ( previewUri ) }
398
- } ) ;
394
+ } ;
399
395
}
396
+ } ) ;
397
+
398
+ const sortedFileOperations = fileOperations . slice ( ) . sort ( compareBulkFileOperations ) ;
399
+ const resources : IResourceDiffEditorInput [ ] = [ ] ;
400
+ for ( const operation of sortedFileOperations ) {
401
+ resources . push ( await computeDiffEditorInput . get ( operation ) ) ;
400
402
}
401
- this . _fileOperations = fileOperations ;
402
- this . _resources = resources ;
403
- return resources ;
404
- }
403
+ const getResourceDiffEditorInputIdOfOperation = async ( operation : BulkFileOperation ) : Promise < IMultiDiffResourceId > => {
404
+ const resource = await computeDiffEditorInput . get ( operation ) ;
405
+ return { original : resource . original . resource , modified : resource . modified . resource } ;
406
+ } ;
407
+ return {
408
+ resources,
409
+ getResourceDiffEditorInputIdOfOperation
410
+ } ;
411
+ } , key => key ) ;
405
412
406
413
private _onContextMenu ( e : ITreeContextMenuEvent < any > ) : void {
407
414
0 commit comments