Skip to content

Commit

Permalink
DirtyDiff - handle the diff in trigger instead of then (#233914)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Nov 15, 2024
1 parent 434e2d6 commit 2fc0143
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ export class DirtyDiffModel extends Disposable {
private _model: ITextFileEditorModel;
get original(): ITextModel[] { return this._originalTextModels; }

private diffDelayer = new ThrottledDelayer<{ changes: LabeledChange[]; mapChanges: Map<string, number[]> } | null>(200);
private diffDelayer = new ThrottledDelayer<void>(200);
private _quickDiffsPromise?: Promise<QuickDiff[]>;
private repositoryDisposables = new Set<IDisposable>();
private readonly originalModelDisposables = this._register(new DisposableStore());
Expand Down Expand Up @@ -1295,14 +1295,15 @@ export class DirtyDiffModel extends Disposable {
this.triggerDiff();
}

private triggerDiff(): Promise<void> {
private triggerDiff(): void {
if (!this.diffDelayer) {
return Promise.resolve();
return;
}

return this.diffDelayer
.trigger(() => this.diff())
.then((result: { changes: LabeledChange[]; mapChanges: Map<string, number[]> } | null) => {
this.diffDelayer
.trigger(async () => {
const result: { changes: LabeledChange[]; mapChanges: Map<string, number[]> } | null = await this.diff();

const originalModels = Array.from(this._originalModels.values());
if (!result || this._disposed || this._model.isDisposed() || originalModels.some(originalModel => originalModel.isDisposed())) {
return; // disposed
Expand All @@ -1317,7 +1318,8 @@ export class DirtyDiffModel extends Disposable {
}

this.setChanges(result.changes, result.mapChanges);
}, (err) => onUnexpectedError(err));
})
.catch(err => onUnexpectedError(err));
}

private setChanges(changes: LabeledChange[], mapChanges: Map<string, number[]>): void {
Expand Down

0 comments on commit 2fc0143

Please sign in to comment.