From f55398014615262fc31f595a87aaf29341322ba2 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 25 Jun 2017 12:41:20 -0400 Subject: [PATCH] Attempts to fix #99 undo/redo spawns too many git processes --- src/currentLineController.ts | 2 ++ src/gitService.ts | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/currentLineController.ts b/src/currentLineController.ts index c8d880b..493ddb7 100644 --- a/src/currentLineController.ts +++ b/src/currentLineController.ts @@ -8,6 +8,7 @@ import { TextEditorComparer } from './comparers'; import { IConfig, StatusBarCommand } from './configuration'; import { DocumentSchemes, ExtensionKey } from './constants'; import { BlameabilityChangeEvent, CommitFormatter, GitCommit, GitCommitLine, GitContextTracker, GitService, GitUri } from './gitService'; +import { Logger } from './logger'; const annotationDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({ after: { @@ -163,6 +164,7 @@ export class CurrentLineController extends Disposable { } private _onGitCacheChanged() { + Logger.log('Git cache changed; resetting current line annotations'); this._onActiveTextEditorChanged(window.activeTextEditor); } diff --git a/src/gitService.ts b/src/gitService.ts index c2ca7ba..f4dce4d 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Iterables, Objects } from './system'; +import { Functions, Iterables, Objects } from './system'; import { Disposable, Event, EventEmitter, ExtensionContext, FileSystemWatcher, languages, Location, Position, Range, TextDocument, TextDocumentChangeEvent, TextEditor, Uri, workspace } from 'vscode'; import { IConfig } from './configuration'; import { CommandContext, DocumentSchemes, ExtensionKey, GlyphChars, setCommandContext } from './constants'; @@ -85,6 +85,7 @@ export class GitService extends Disposable { private _codeLensProvider: GitCodeLensProvider | undefined; private _codeLensProviderDisposable: Disposable | undefined; private _disposable: Disposable | undefined; + private _fireGitCacheChangeDebounced: () => void; private _fsWatcher: FileSystemWatcher | undefined; private _gitignore: Promise; @@ -97,6 +98,8 @@ export class GitService extends Disposable { this._remotesCache = new Map(); this._uriCache = new Map(); + this._fireGitCacheChangeDebounced = Functions.debounce(this._fireGitCacheChange, 50); + this._onConfigurationChanged(); const subscriptions: Disposable[] = []; @@ -228,8 +231,16 @@ export class GitService extends Disposable { private _onGitChanged() { this._gitCache.clear(); - this._onDidChangeGitCache.fire(); - this._codeLensProvider && this._codeLensProvider.reset(); + this._fireGitCacheChangeDebounced(); + } + + private _fireGitCacheChange() { + setTimeout(() => { + // Refresh the code lenses + this._codeLensProvider && this._codeLensProvider.reset(); + + this._onDidChangeGitCache.fire(); + }, 1); } private _removeCachedEntry(document: TextDocument, reason: RemoveCacheReason) { @@ -248,10 +259,7 @@ export class GitService extends Disposable { Logger.log(`Clear cache entry for '${cacheKey}', reason=${RemoveCacheReason[reason]}`); if (reason === RemoveCacheReason.DocumentSaved) { - this._onDidChangeGitCache.fire(); - - // Refresh the codelenses with the updated blame - this._codeLensProvider && this._codeLensProvider.reset(); + this._fireGitCacheChangeDebounced(); } } }