Skip to content

Commit 4058211

Browse files
authored
SCM - more quick diff cleanup (microsoft#236280)
1 parent f1a2ce6 commit 4058211

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/vs/workbench/contrib/scm/browser/quickDiffModel.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ export const IQuickDiffModelService = createDecorator<IQuickDiffModelService>('I
3333

3434
export interface QuickDiffModelOptions {
3535
readonly algorithm: DiffAlgorithmName;
36+
readonly maxComputationTimeMs?: number;
3637
}
3738

39+
const decoratorQuickDiffModelOptions: QuickDiffModelOptions = {
40+
algorithm: 'legacy',
41+
maxComputationTimeMs: 1000
42+
};
43+
3844
export interface IQuickDiffModelService {
3945
_serviceBrand: undefined;
4046

@@ -52,7 +58,7 @@ class QuickDiffModelReferenceCollection extends ReferenceCollection<QuickDiffMod
5258
super();
5359
}
5460

55-
protected override createReferencedObject(_key: string, textFileModel: IResolvedTextFileEditorModel, options?: QuickDiffModelOptions): QuickDiffModel {
61+
protected override createReferencedObject(_key: string, textFileModel: IResolvedTextFileEditorModel, options: QuickDiffModelOptions): QuickDiffModel {
5662
return this._instantiationService.createInstance(QuickDiffModel, textFileModel, options);
5763
}
5864

@@ -74,16 +80,13 @@ export class QuickDiffModelService implements IQuickDiffModelService {
7480
this._references = this.instantiationService.createInstance(QuickDiffModelReferenceCollection);
7581
}
7682

77-
createQuickDiffModelReference(resource: URI, options?: QuickDiffModelOptions): IReference<QuickDiffModel> | undefined {
83+
createQuickDiffModelReference(resource: URI, options: QuickDiffModelOptions = decoratorQuickDiffModelOptions): IReference<QuickDiffModel> | undefined {
7884
const textFileModel = this.textFileService.files.get(resource);
7985
if (!textFileModel?.isResolved()) {
8086
return undefined;
8187
}
8288

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) });
8790
return this._references.acquire(resource.toString(), textFileModel, options);
8891
}
8992
}
@@ -119,7 +122,7 @@ export class QuickDiffModel extends Disposable {
119122

120123
constructor(
121124
textFileModel: IResolvedTextFileEditorModel,
122-
private readonly options: QuickDiffModelOptions | undefined,
125+
private readonly options: QuickDiffModelOptions,
123126
@ISCMService private readonly scmService: ISCMService,
124127
@IQuickDiffService private readonly quickDiffService: IQuickDiffService,
125128
@IEditorWorkerService private readonly editorWorkerService: IEditorWorkerService,
@@ -273,14 +276,11 @@ export class QuickDiffModel extends Disposable {
273276
}
274277

275278
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;
280280

281281
const result = await this.editorWorkerService.computeDiff(original, modified, {
282282
computeMoves: false, ignoreTrimWhitespace, maxComputationTimeMs
283-
}, algorithm);
283+
}, this.options.algorithm);
284284

285285
return { changes: result ? toLineChanges(DiffState.fromDiffResult(result)) : null, changes2: result?.changes ?? null };
286286
}
@@ -361,7 +361,7 @@ export class QuickDiffModel extends Disposable {
361361
// When the QuickDiffModel is created for a diff editor, there is no
362362
// need to compute the diff information for the `isSCM` quick diff
363363
// provider as that information will be provided by the diff editor
364-
return this.options?.algorithm !== undefined
364+
return this.options.maxComputationTimeMs === undefined
365365
? quickDiffs.filter(quickDiff => !quickDiff.isSCM)
366366
: quickDiffs;
367367
}

0 commit comments

Comments
 (0)