@@ -33,8 +33,14 @@ export const IQuickDiffModelService = createDecorator<IQuickDiffModelService>('I
33
33
34
34
export interface QuickDiffModelOptions {
35
35
readonly algorithm : DiffAlgorithmName ;
36
+ readonly maxComputationTimeMs ?: number ;
36
37
}
37
38
39
+ const decoratorQuickDiffModelOptions : QuickDiffModelOptions = {
40
+ algorithm : 'legacy' ,
41
+ maxComputationTimeMs : 1000
42
+ } ;
43
+
38
44
export interface IQuickDiffModelService {
39
45
_serviceBrand : undefined ;
40
46
@@ -52,7 +58,7 @@ class QuickDiffModelReferenceCollection extends ReferenceCollection<QuickDiffMod
52
58
super ( ) ;
53
59
}
54
60
55
- protected override createReferencedObject ( _key : string , textFileModel : IResolvedTextFileEditorModel , options ? : QuickDiffModelOptions ) : QuickDiffModel {
61
+ protected override createReferencedObject ( _key : string , textFileModel : IResolvedTextFileEditorModel , options : QuickDiffModelOptions ) : QuickDiffModel {
56
62
return this . _instantiationService . createInstance ( QuickDiffModel , textFileModel , options ) ;
57
63
}
58
64
@@ -74,16 +80,13 @@ export class QuickDiffModelService implements IQuickDiffModelService {
74
80
this . _references = this . instantiationService . createInstance ( QuickDiffModelReferenceCollection ) ;
75
81
}
76
82
77
- createQuickDiffModelReference ( resource : URI , options ? : QuickDiffModelOptions ) : IReference < QuickDiffModel > | undefined {
83
+ createQuickDiffModelReference ( resource : URI , options : QuickDiffModelOptions = decoratorQuickDiffModelOptions ) : IReference < QuickDiffModel > | undefined {
78
84
const textFileModel = this . textFileService . files . get ( resource ) ;
79
85
if ( ! textFileModel ?. isResolved ( ) ) {
80
86
return undefined ;
81
87
}
82
88
83
- resource = options === undefined
84
- ? this . uriIdentityService . asCanonicalUri ( resource )
85
- : this . uriIdentityService . asCanonicalUri ( resource ) . with ( { query : JSON . stringify ( options ) } ) ;
86
-
89
+ resource = this . uriIdentityService . asCanonicalUri ( resource ) . with ( { query : JSON . stringify ( options ) } ) ;
87
90
return this . _references . acquire ( resource . toString ( ) , textFileModel , options ) ;
88
91
}
89
92
}
@@ -119,7 +122,7 @@ export class QuickDiffModel extends Disposable {
119
122
120
123
constructor (
121
124
textFileModel : IResolvedTextFileEditorModel ,
122
- private readonly options : QuickDiffModelOptions | undefined ,
125
+ private readonly options : QuickDiffModelOptions ,
123
126
@ISCMService private readonly scmService : ISCMService ,
124
127
@IQuickDiffService private readonly quickDiffService : IQuickDiffService ,
125
128
@IEditorWorkerService private readonly editorWorkerService : IEditorWorkerService ,
@@ -273,14 +276,11 @@ export class QuickDiffModel extends Disposable {
273
276
}
274
277
275
278
private async _diff ( original : URI , modified : URI , ignoreTrimWhitespace : boolean ) : Promise < { changes : readonly IChange [ ] | null ; changes2 : readonly LineRangeMapping [ ] | null } > {
276
- // When no algorithm is specified, we use the legacy diff algorithm along with a 1000ms
277
- // timeout as the diff information is being used for the quick diff editor decorations
278
- const algorithm = this . options ?. algorithm ?? 'legacy' ;
279
- const maxComputationTimeMs = this . options ?. algorithm ? Number . MAX_SAFE_INTEGER : 1000 ;
279
+ const maxComputationTimeMs = this . options . maxComputationTimeMs ?? Number . MAX_SAFE_INTEGER ;
280
280
281
281
const result = await this . editorWorkerService . computeDiff ( original , modified , {
282
282
computeMoves : false , ignoreTrimWhitespace, maxComputationTimeMs
283
- } , algorithm ) ;
283
+ } , this . options . algorithm ) ;
284
284
285
285
return { changes : result ? toLineChanges ( DiffState . fromDiffResult ( result ) ) : null , changes2 : result ?. changes ?? null } ;
286
286
}
@@ -361,7 +361,7 @@ export class QuickDiffModel extends Disposable {
361
361
// When the QuickDiffModel is created for a diff editor, there is no
362
362
// need to compute the diff information for the `isSCM` quick diff
363
363
// provider as that information will be provided by the diff editor
364
- return this . options ?. algorithm ! == undefined
364
+ return this . options . maxComputationTimeMs = == undefined
365
365
? quickDiffs . filter ( quickDiff => ! quickDiff . isSCM )
366
366
: quickDiffs ;
367
367
}
0 commit comments