From 5ba18860cbfcad8a6b772410a01704c16af9abd3 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 6 Jan 2018 15:53:54 -0500 Subject: [PATCH] Defers provider reset --- src/annotations/annotationProvider.ts | 11 +++++++++++ src/annotations/blameAnnotationProvider.ts | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/annotations/annotationProvider.ts b/src/annotations/annotationProvider.ts index 5999274..91a9195 100644 --- a/src/annotations/annotationProvider.ts +++ b/src/annotations/annotationProvider.ts @@ -1,4 +1,5 @@ 'use strict'; +import { Functions } from '../system'; import { DecorationOptions, Disposable, ExtensionContext, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, Uri, window } from 'vscode'; import { FileAnnotationType } from '../annotations/annotationController'; import { TextDocumentComparer } from '../comparers'; @@ -79,7 +80,17 @@ export abstract class AnnotationProviderBase extends Disposable { } } + private _resetDebounced: ((changes?: { decoration: TextEditorDecorationType | undefined, highlightDecoration: TextEditorDecorationType | undefined }) => Promise) | undefined; + async reset(changes?: { decoration: TextEditorDecorationType | undefined, highlightDecoration: TextEditorDecorationType | undefined }) { + if (this._resetDebounced === undefined) { + this._resetDebounced = Functions.debounce(this.onReset, 250); + } + + this._resetDebounced(changes); + } + + async onReset(changes?: { decoration: TextEditorDecorationType | undefined, highlightDecoration: TextEditorDecorationType | undefined }) { if (changes !== undefined) { await this.clear(); diff --git a/src/annotations/blameAnnotationProvider.ts b/src/annotations/blameAnnotationProvider.ts index fc19533..e2d3d2e 100644 --- a/src/annotations/blameAnnotationProvider.ts +++ b/src/annotations/blameAnnotationProvider.ts @@ -33,14 +33,14 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase super.clear(); } - async reset(changes?: { decoration: TextEditorDecorationType | undefined, highlightDecoration: TextEditorDecorationType | undefined }) { + async onReset(changes?: { decoration: TextEditorDecorationType | undefined, highlightDecoration: TextEditorDecorationType | undefined }) { if (this.editor !== undefined) { this._blame = this.editor.document.isDirty ? this.git.getBlameForFileContents(this.uri, this.editor.document.getText()) : this.git.getBlameForFile(this.uri); } - super.reset(changes); + super.onReset(changes); } async selection(shaOrLine?: string | number, blame?: GitBlame) {