diff --git a/src/vs/workbench/contrib/scm/browser/quickDiffModel.ts b/src/vs/workbench/contrib/scm/browser/quickDiffModel.ts index 9907a627c27e7..3d1ec39c3f61b 100644 --- a/src/vs/workbench/contrib/scm/browser/quickDiffModel.ts +++ b/src/vs/workbench/contrib/scm/browser/quickDiffModel.ts @@ -33,8 +33,14 @@ export const IQuickDiffModelService = createDecorator('I export interface QuickDiffModelOptions { readonly algorithm: DiffAlgorithmName; + readonly maxComputationTimeMs?: number; } +const decoratorQuickDiffModelOptions: QuickDiffModelOptions = { + algorithm: 'legacy', + maxComputationTimeMs: 1000 +}; + export interface IQuickDiffModelService { _serviceBrand: undefined; @@ -52,7 +58,7 @@ class QuickDiffModelReferenceCollection extends ReferenceCollection | undefined { + createQuickDiffModelReference(resource: URI, options: QuickDiffModelOptions = decoratorQuickDiffModelOptions): IReference | undefined { const textFileModel = this.textFileService.files.get(resource); if (!textFileModel?.isResolved()) { return undefined; } - resource = options === undefined - ? this.uriIdentityService.asCanonicalUri(resource) - : this.uriIdentityService.asCanonicalUri(resource).with({ query: JSON.stringify(options) }); - + resource = this.uriIdentityService.asCanonicalUri(resource).with({ query: JSON.stringify(options) }); return this._references.acquire(resource.toString(), textFileModel, options); } } @@ -119,7 +122,7 @@ export class QuickDiffModel extends Disposable { constructor( textFileModel: IResolvedTextFileEditorModel, - private readonly options: QuickDiffModelOptions | undefined, + private readonly options: QuickDiffModelOptions, @ISCMService private readonly scmService: ISCMService, @IQuickDiffService private readonly quickDiffService: IQuickDiffService, @IEditorWorkerService private readonly editorWorkerService: IEditorWorkerService, @@ -273,14 +276,11 @@ export class QuickDiffModel extends Disposable { } private async _diff(original: URI, modified: URI, ignoreTrimWhitespace: boolean): Promise<{ changes: readonly IChange[] | null; changes2: readonly LineRangeMapping[] | null }> { - // When no algorithm is specified, we use the legacy diff algorithm along with a 1000ms - // timeout as the diff information is being used for the quick diff editor decorations - const algorithm = this.options?.algorithm ?? 'legacy'; - const maxComputationTimeMs = this.options?.algorithm ? Number.MAX_SAFE_INTEGER : 1000; + const maxComputationTimeMs = this.options.maxComputationTimeMs ?? Number.MAX_SAFE_INTEGER; const result = await this.editorWorkerService.computeDiff(original, modified, { computeMoves: false, ignoreTrimWhitespace, maxComputationTimeMs - }, algorithm); + }, this.options.algorithm); return { changes: result ? toLineChanges(DiffState.fromDiffResult(result)) : null, changes2: result?.changes ?? null }; } @@ -361,7 +361,7 @@ export class QuickDiffModel extends Disposable { // When the QuickDiffModel is created for a diff editor, there is no // need to compute the diff information for the `isSCM` quick diff // provider as that information will be provided by the diff editor - return this.options?.algorithm !== undefined + return this.options.maxComputationTimeMs === undefined ? quickDiffs.filter(quickDiff => !quickDiff.isSCM) : quickDiffs; }