From c2a352fc6651ca3c97f717211fa060502edfc76d Mon Sep 17 00:00:00 2001 From: Eric Amodio <eamodio@gmail.com> Date: Wed, 11 Oct 2017 01:20:33 -0400 Subject: [PATCH] Fixes incorrectly setting isBlameable context --- CHANGELOG.md | 3 +++ src/annotations/annotationController.ts | 7 +++++-- src/git/gitContextTracker.ts | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9806c5a..f4308c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Removes `Custom` from the `gitlens.codeLens.locations` setting as it wasn't really required - Removes properties (symbol `Property`) from being included in the `Blocks` option of the `gitlens.codeLens.locations` setting -- can be easily re-added by setting `"gitlens.codeLens.customLocationSymbols": [ "Property" ]` if desired +### Fixed +- Fixes issue where `isBlameable` context could be set incorrectly leading to blame icon showing up on invalid documents + ## [5.5.0] - 2017-10-09 ### Added - Adds a **quick-access** command bar to the bottom of the `details` hover annotations diff --git a/src/annotations/annotationController.ts b/src/annotations/annotationController.ts index 2a46451..8909aaf 100644 --- a/src/annotations/annotationController.ts +++ b/src/annotations/annotationController.ts @@ -325,12 +325,15 @@ export class AnnotationController extends Disposable { } return window.withProgress({ location: ProgressLocation.Window }, async (progress: Progress<{ message: string }>) => { - await setCommandContext(CommandContext.AnnotationStatus, AnnotationStatus.Computing); + const active = editor === window.activeTextEditor; + await setCommandContext(CommandContext.AnnotationStatus, active ? AnnotationStatus.Computing : undefined); const computingAnnotations = this.showAnnotationsCore(currentProvider, editor, type, shaOrLine, progress); const result = await computingAnnotations; - await setCommandContext(CommandContext.AnnotationStatus, result ? AnnotationStatus.Computed : undefined); + if (active) { + await setCommandContext(CommandContext.AnnotationStatus, result ? AnnotationStatus.Computed : undefined); + } return computingAnnotations; }); diff --git a/src/git/gitContextTracker.ts b/src/git/gitContextTracker.ts index 67b2bbe..b06a8c3 100644 --- a/src/git/gitContextTracker.ts +++ b/src/git/gitContextTracker.ts @@ -83,15 +83,26 @@ export class GitContextTracker extends Disposable { // TODO: Rework this once https://github.com/Microsoft/vscode/issues/27231 is released in v1.13 // We have to defer because isDirty is not reliable inside this event - setTimeout(() => this._updateBlameability(!e.document.isDirty), 1); + setTimeout(async () => { + let blameable = !e.document.isDirty; + if (blameable) { + blameable = await this.git.getBlameability(new GitUri(e.document.uri)); + } + this._updateBlameability(blameable); + }, 1); } - private _onTextDocumentSaved(e: TextDocument) { + private async _onTextDocumentSaved(e: TextDocument) { if (!TextDocumentComparer.equals(this._editor && this._editor.document, e)) return; // Don't need to resubscribe as we aren't unsubscribing on document changes anymore // this._subscribeToDocumentChanges(); - this._updateBlameability(!e.isDirty); + + let blameable = !e.isDirty; + if (blameable) { + blameable = await this.git.getBlameability(new GitUri(e.uri)); + } + this._updateBlameability(blameable); } private _subscribeToDocumentChanges() {