Skip to content

Commit

Permalink
SCM - more quick diff cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru committed Dec 16, 2024
1 parent c82097d commit 73742b6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/vs/workbench/contrib/scm/browser/quickDiffModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ export const IQuickDiffModelService = createDecorator<IQuickDiffModelService>('I

export interface QuickDiffModelOptions {
readonly algorithm: DiffAlgorithmName;
readonly maxComputationTimeMs?: number;
}

const decoratorQuickDiffModelOptions: QuickDiffModelOptions = {
algorithm: 'legacy',
maxComputationTimeMs: 1000
};

export interface IQuickDiffModelService {
_serviceBrand: undefined;

Expand All @@ -52,7 +58,7 @@ class QuickDiffModelReferenceCollection extends ReferenceCollection<QuickDiffMod
super();
}

protected override createReferencedObject(_key: string, textFileModel: IResolvedTextFileEditorModel, options?: QuickDiffModelOptions): QuickDiffModel {
protected override createReferencedObject(_key: string, textFileModel: IResolvedTextFileEditorModel, options: QuickDiffModelOptions): QuickDiffModel {
return this._instantiationService.createInstance(QuickDiffModel, textFileModel, options);
}

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

createQuickDiffModelReference(resource: URI, options?: QuickDiffModelOptions): IReference<QuickDiffModel> | undefined {
createQuickDiffModelReference(resource: URI, options: QuickDiffModelOptions = decoratorQuickDiffModelOptions): IReference<QuickDiffModel> | 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);
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 };
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 73742b6

Please sign in to comment.