From 3cafcf30738fe8fb5a36bdfc3d9e9abef52c5dc9 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 19 Mar 2018 02:52:48 -0400 Subject: [PATCH] Fixes #314 - Toggle line annotation doesn't work --- CHANGELOG.md | 3 + src/annotations/annotationController.ts | 2 +- src/annotations/annotationProvider.ts | 2 +- src/annotations/blameAnnotationProvider.ts | 2 +- src/annotations/recentChangesAnnotationProvider.ts | 2 +- src/codeLensController.ts | 2 +- src/container.ts | 13 +- src/currentLineController.ts | 30 +-- src/gitCodeLensProvider.ts | 2 +- src/gitService.ts | 2 +- src/trackers/documentTracker.ts | 1 - src/trackers/gitDocumentState.ts | 37 ---- src/trackers/gitDocumentTracker.ts | 33 ++++ src/trackers/gitLineTracker.ts | 42 ++++ src/trackers/lineTracker.ts | 6 +- src/ui/settings/index.html | 211 +++++++++++---------- 16 files changed, 219 insertions(+), 171 deletions(-) delete mode 100644 src/trackers/gitDocumentState.ts create mode 100644 src/trackers/gitDocumentTracker.ts create mode 100644 src/trackers/gitLineTracker.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f9f38f..e4c1b97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Added - Adds `${agoOrDate}` and `${authorAgoOrDate}` tokens to `gitlens.blame.format`, `gitlens.currentLine.format`, `gitlens.explorers.commitFormat`, `gitlens.explorers.stashFormat`, and `gitlens.statusBar.format` settings which will honor the `gitlens.defaultDateStyle` setting — closes [#312](https://github.com/eamodio/vscode-gitlens/issues/312) +### Fixed +- Fixes [#314](https://github.com/eamodio/vscode-gitlens/issues/314) - Toggle line annotation doesn't work properly + ## [8.1.1] - 2018-03-12 ### Fixed - Fixes [#276](https://github.com/eamodio/vscode-gitlens/issues/276) - Lookup for branches without upstreams fails diff --git a/src/annotations/annotationController.ts b/src/annotations/annotationController.ts index 5c17c8d..3911298 100644 --- a/src/annotations/annotationController.ts +++ b/src/annotations/annotationController.ts @@ -5,7 +5,7 @@ import { AnnotationProviderBase, AnnotationStatus, TextEditorCorrelationKey } fr import { AnnotationsToggleMode, configuration, FileAnnotationType, HighlightLocations } from '../configuration'; import { CommandContext, isTextEditor, setCommandContext } from '../constants'; import { Container } from '../container'; -import { DocumentBlameStateChangeEvent, DocumentDirtyStateChangeEvent, GitDocumentState } from '../trackers/documentTracker'; +import { DocumentBlameStateChangeEvent, DocumentDirtyStateChangeEvent, GitDocumentState } from '../trackers/gitDocumentTracker'; import { GutterBlameAnnotationProvider } from './gutterBlameAnnotationProvider'; import { HeatmapBlameAnnotationProvider } from './heatmapBlameAnnotationProvider'; import { KeyboardScope, KeyCommand, Keys } from '../keyboard'; diff --git a/src/annotations/annotationProvider.ts b/src/annotations/annotationProvider.ts index cb6d58a..6fd929c 100644 --- a/src/annotations/annotationProvider.ts +++ b/src/annotations/annotationProvider.ts @@ -4,7 +4,7 @@ import { DecorationOptions, Disposable, Range, TextDocument, TextEditor, TextEdi import { FileAnnotationType } from '../configuration'; import { TextDocumentComparer } from '../comparers'; import { CommandContext, setCommandContext } from '../constants'; -import { GitDocumentState, TrackedDocument } from '../trackers/documentTracker'; +import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; export enum AnnotationStatus { Computing = 'computing', diff --git a/src/annotations/blameAnnotationProvider.ts b/src/annotations/blameAnnotationProvider.ts index f5ed56b..c27a655 100644 --- a/src/annotations/blameAnnotationProvider.ts +++ b/src/annotations/blameAnnotationProvider.ts @@ -5,7 +5,7 @@ import { AnnotationProviderBase } from './annotationProvider'; import { Annotations } from './annotations'; import { RangeEndOfLineIndex } from '../constants'; import { Container } from '../container'; -import { GitDocumentState, TrackedDocument } from '../trackers/documentTracker'; +import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; import { GitBlame, GitCommit, GitUri } from '../gitService'; export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase { diff --git a/src/annotations/recentChangesAnnotationProvider.ts b/src/annotations/recentChangesAnnotationProvider.ts index 38d1739..64a1b77 100644 --- a/src/annotations/recentChangesAnnotationProvider.ts +++ b/src/annotations/recentChangesAnnotationProvider.ts @@ -5,7 +5,7 @@ import { Annotations } from './annotations'; import { FileAnnotationType } from './../configuration'; import { RangeEndOfLineIndex } from '../constants'; import { Container } from '../container'; -import { GitDocumentState, TrackedDocument } from '../trackers/documentTracker'; +import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; import { GitUri } from '../gitService'; import { Logger } from '../logger'; diff --git a/src/codeLensController.ts b/src/codeLensController.ts index 088c212..934b53a 100644 --- a/src/codeLensController.ts +++ b/src/codeLensController.ts @@ -3,7 +3,7 @@ import { ConfigurationChangeEvent, Disposable, languages } from 'vscode'; import { configuration, ICodeLensConfig } from './configuration'; import { CommandContext, setCommandContext } from './constants'; import { Container } from './container'; -import { DocumentBlameStateChangeEvent, DocumentDirtyIdleTriggerEvent, GitDocumentState } from './trackers/documentTracker'; +import { DocumentBlameStateChangeEvent, DocumentDirtyIdleTriggerEvent, GitDocumentState } from './trackers/gitDocumentTracker'; import { GitCodeLensProvider } from './gitCodeLensProvider'; import { Logger } from './logger'; diff --git a/src/container.ts b/src/container.ts index 7433ee5..07abb43 100644 --- a/src/container.ts +++ b/src/container.ts @@ -4,10 +4,11 @@ import { AnnotationController } from './annotations/annotationController'; import { CodeLensController } from './codeLensController'; import { configuration, IConfig } from './configuration'; import { CurrentLineController } from './currentLineController'; -import { DocumentTracker, GitDocumentState } from './trackers/documentTracker'; import { ExplorerCommands } from './views/explorerCommands'; import { GitContentProvider } from './gitContentProvider'; +import { GitDocumentTracker } from './trackers/gitDocumentTracker'; import { GitExplorer } from './views/gitExplorer'; +import { GitLineTracker } from './trackers/gitLineTracker'; import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider'; import { GitService } from './gitService'; import { Keyboard } from './keyboard'; @@ -20,7 +21,8 @@ export class Container { this._context = context; this._config = config; - context.subscriptions.push(this._tracker = new DocumentTracker()); + context.subscriptions.push(this._lineTracker = new GitLineTracker()); + context.subscriptions.push(this._tracker = new GitDocumentTracker()); context.subscriptions.push(this._git = new GitService()); // Since there is a bit of a chicken & egg problem with the DocumentTracker and the GitService, initialize the tracker once the GitService is loaded @@ -100,6 +102,11 @@ export class Container { return this._currentLineController; } + private static _lineTracker: GitLineTracker; + static get lineTracker() { + return this._lineTracker; + } + private static _pageProvider: PageProvider; static get pages() { return this._pageProvider; @@ -114,7 +121,7 @@ export class Container { return this._resultsExplorer; } - private static _tracker: DocumentTracker; + private static _tracker: GitDocumentTracker; static get tracker() { return this._tracker; } diff --git a/src/currentLineController.ts b/src/currentLineController.ts index d43973f..c116ed4 100644 --- a/src/currentLineController.ts +++ b/src/currentLineController.ts @@ -6,9 +6,9 @@ import { Commands } from './commands'; import { configuration, IConfig, StatusBarCommand } from './configuration'; import { isTextEditor, RangeEndOfLineIndex } from './constants'; import { Container } from './container'; -import { DocumentBlameStateChangeEvent, DocumentDirtyIdleTriggerEvent, DocumentDirtyStateChangeEvent, GitDocumentState, TrackedDocument } from './trackers/documentTracker'; +import { DocumentBlameStateChangeEvent, DocumentDirtyIdleTriggerEvent, DocumentDirtyStateChangeEvent, GitDocumentState, TrackedDocument } from './trackers/gitDocumentTracker'; +import { GitLineState, GitLineTracker, LinesChangeEvent } from './trackers/gitLineTracker'; import { CommitFormatter, GitBlameLine, GitCommit, ICommitFormatOptions } from './gitService'; -import { GitLineState, LinesChangeEvent, LineTracker } from './trackers/lineTracker'; const annotationDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({ after: { @@ -63,7 +63,7 @@ export class CurrentLineController extends Disposable { private _blameAnnotationState: AnnotationState | undefined; private _editor: TextEditor | undefined; - private _lineTracker: LineTracker; + private _lineTracker: GitLineTracker; private _statusBarItem: StatusBarItem | undefined; private _disposable: Disposable; @@ -74,7 +74,7 @@ export class CurrentLineController extends Disposable { constructor() { super(() => this.dispose()); - this._lineTracker = new LineTracker(); + this._lineTracker = Container.lineTracker; this._disposable = Disposable.from( this._lineTracker, @@ -87,7 +87,6 @@ export class CurrentLineController extends Disposable { dispose() { this.clearAnnotations(this._editor); - this.unregisterHoverProviders(); this._debugSessionEndDisposable && this._debugSessionEndDisposable.dispose(); @@ -220,9 +219,9 @@ export class CurrentLineController extends Disposable { this.clearAnnotations(this._editor); } this.clearAnnotations(editor); + this.unregisterHoverProviders(); this._lineTracker.reset(); - this.unregisterHoverProviders(); if (this._statusBarItem !== undefined && reason !== 'lines') { this._statusBarItem.hide(); @@ -348,8 +347,7 @@ export class CurrentLineController extends Disposable { } private clearAnnotations(editor: TextEditor | undefined) { - if (editor === undefined) return; - if ((editor as any)._disposed === true) return; + if (editor === undefined || (editor as any)._disposed === true) return; editor.setDecorations(annotationDecoration, []); } @@ -358,9 +356,7 @@ export class CurrentLineController extends Disposable { if (this._blameAnnotationState !== undefined) return this._blameAnnotationState; const cfg = Container.config; - return { - enabled: cfg.currentLine.enabled || cfg.statusBar.enabled || (cfg.hovers.enabled && cfg.hovers.currentLine.enabled) - }; + return { enabled: cfg.currentLine.enabled }; } private _updateBlameDebounced: (((lines: number[], editor: TextEditor, trackedDocument: TrackedDocument) => void) & IDeferrable) | undefined; @@ -381,13 +377,13 @@ export class CurrentLineController extends Disposable { } const state = this.getBlameAnnotationState(); - if (state.enabled) { + if (state.enabled || Container.config.statusBar.enabled || (Container.config.hovers.enabled && Container.config.hovers.currentLine.enabled)) { if (options.trackedDocument === undefined) { options.trackedDocument = await Container.tracker.getOrAdd(editor.document); } if (options.trackedDocument.isBlameable) { - if (state.enabled && Container.config.hovers.enabled && Container.config.hovers.currentLine.enabled && + if (Container.config.hovers.enabled && Container.config.hovers.currentLine.enabled && (options.full || this._hoverProviderDisposable === undefined)) { this.registerHoverProviders(editor, Container.config.hovers.currentLine); } @@ -460,7 +456,11 @@ export class CurrentLineController extends Disposable { // Make sure we are still on the same line, blameable, and not pending, after the await if (this._lineTracker.includesAll(lines) && trackedDocument.isBlameable && !(this._updateBlameDebounced && this._updateBlameDebounced.pending!())) { - if (!this.getBlameAnnotationState().enabled) return this.clear(editor); + if (!this.getBlameAnnotationState().enabled) { + if (!Container.config.statusBar.enabled) return this.clear(editor); + + this.clearAnnotations(editor); + } } const activeLine = blameLines[0]; @@ -523,7 +523,7 @@ export class CurrentLineController extends Disposable { private async updateTrailingAnnotations(lines: GitBlameLine[], editor: TextEditor) { const cfg = Container.config.currentLine; - if (!cfg.enabled || !isTextEditor(editor)) return; + if (!this.getBlameAnnotationState().enabled || !isTextEditor(editor)) return this.clearAnnotations(editor); const decorations = []; for (const l of lines) { diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index 094a7fb..4fc7db4 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -5,7 +5,7 @@ import { Commands, DiffWithPreviousCommandArgs, ShowQuickCommitDetailsCommandArg import { CodeLensCommand, CodeLensLanguageScope, CodeLensScopes, configuration, ICodeLensConfig } from './configuration'; import { BuiltInCommands, DocumentSchemes } from './constants'; import { Container } from './container'; -import { DocumentTracker, GitDocumentState } from './trackers/documentTracker'; +import { DocumentTracker, GitDocumentState } from './trackers/gitDocumentTracker'; import { GitBlame, GitBlameCommit, GitBlameLines, GitService, GitUri } from './gitService'; import { Logger } from './logger'; diff --git a/src/gitService.ts b/src/gitService.ts index d644068..1f6b0d9 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -4,9 +4,9 @@ import { ConfigurationChangeEvent, Disposable, Event, EventEmitter, Range, TextE import { configuration, IRemotesConfig } from './configuration'; import { CommandContext, DocumentSchemes, setCommandContext } from './constants'; import { Container } from './container'; -import { CachedBlame, CachedDiff, CachedLog, GitDocumentState, TrackedDocument } from './trackers/documentTracker'; import { RemoteProviderFactory, RemoteProviderMap } from './git/remotes/factory'; import { CommitFormatting, Git, GitAuthor, GitBlame, GitBlameCommit, GitBlameLine, GitBlameLines, GitBlameParser, GitBranch, GitBranchParser, GitCommit, GitCommitType, GitDiff, GitDiffChunkLine, GitDiffParser, GitDiffShortStat, GitLog, GitLogCommit, GitLogParser, GitRemote, GitRemoteParser, GitStash, GitStashParser, GitStatus, GitStatusFile, GitStatusParser, GitTag, GitTagParser, IGit, Repository } from './git/git'; +import { CachedBlame, CachedDiff, CachedLog, GitDocumentState, TrackedDocument } from './trackers/gitDocumentTracker'; import { GitUri, IGitCommitInfo } from './git/gitUri'; import { Logger } from './logger'; import * as fs from 'fs'; diff --git a/src/trackers/documentTracker.ts b/src/trackers/documentTracker.ts index c37041f..abe15b6 100644 --- a/src/trackers/documentTracker.ts +++ b/src/trackers/documentTracker.ts @@ -6,7 +6,6 @@ import { CommandContext, DocumentSchemes, isActiveDocument, isTextEditor, setCom import { GitUri } from '../gitService'; import { DocumentBlameStateChangeEvent, TrackedDocument } from './trackedDocument'; -export { CachedBlame, CachedDiff, CachedLog, GitDocumentState } from './gitDocumentState'; export * from './trackedDocument'; export interface DocumentDirtyStateChangeEvent { diff --git a/src/trackers/gitDocumentState.ts b/src/trackers/gitDocumentState.ts deleted file mode 100644 index 7eac022..0000000 --- a/src/trackers/gitDocumentState.ts +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; -import { GitBlame, GitDiff, GitLog } from './../git/git'; -import { GitBlameCommit, GitLogCommit } from '../gitService'; - -interface CachedItem { - item: Promise; - errorMessage?: string; -} - -export type CachedBlame = CachedItem; -export type CachedDiff = CachedItem; -export type CachedLog = CachedItem; - -export class GitDocumentState { - - private cache: Map = new Map(); - - constructor( - public readonly key: string - ) { } - - get(key: string): T | undefined { - return this.cache.get(key) as T; - } - - set(key: string, value: T) { - this.cache.set(key, value); - } -} - -export class GitLineState { - - constructor( - public readonly commit: GitBlameCommit | undefined, - public logCommit?: GitLogCommit - ) { } -} \ No newline at end of file diff --git a/src/trackers/gitDocumentTracker.ts b/src/trackers/gitDocumentTracker.ts new file mode 100644 index 0000000..6566879 --- /dev/null +++ b/src/trackers/gitDocumentTracker.ts @@ -0,0 +1,33 @@ +'use strict'; +import { DocumentTracker } from './documentTracker'; +import { GitBlame, GitDiff, GitLog } from './../git/git'; + +export * from './documentTracker'; + +interface CachedItem { + item: Promise; + errorMessage?: string; +} + +export type CachedBlame = CachedItem; +export type CachedDiff = CachedItem; +export type CachedLog = CachedItem; + +export class GitDocumentState { + + private cache: Map = new Map(); + + constructor( + public readonly key: string + ) { } + + get(key: string): T | undefined { + return this.cache.get(key) as T; + } + + set(key: string, value: T) { + this.cache.set(key, value); + } +} + +export class GitDocumentTracker extends DocumentTracker { } \ No newline at end of file diff --git a/src/trackers/gitLineTracker.ts b/src/trackers/gitLineTracker.ts new file mode 100644 index 0000000..8a3303b --- /dev/null +++ b/src/trackers/gitLineTracker.ts @@ -0,0 +1,42 @@ +'use strict'; +import { GitBlameCommit, GitLogCommit } from '../gitService'; +import { LineTracker } from './lineTracker'; + +export * from './lineTracker'; + +export class GitLineState { + + constructor( + public readonly commit: GitBlameCommit | undefined, + public logCommit?: GitLogCommit + ) { } +} + +export class GitLineTracker extends LineTracker { + + private _count = 0; + + start() { + if (this._disposable !== undefined) { + this._count = 0; + return; + } + + this._count++; + if (this._count === 1) { + super.start(); + } + } + + stop() { + if (this._disposable !== undefined) { + this._count = 0; + return; + } + + this._count--; + if (this._count === 0) { + super.stop(); + } + } +} diff --git a/src/trackers/lineTracker.ts b/src/trackers/lineTracker.ts index d18aeff..a679ba1 100644 --- a/src/trackers/lineTracker.ts +++ b/src/trackers/lineTracker.ts @@ -3,8 +3,6 @@ import { Functions, IDeferrable } from './../system'; import { Disposable, Event, EventEmitter, TextEditor, TextEditorSelectionChangeEvent, window } from 'vscode'; import { isTextEditor } from './../constants'; -export { GitLineState } from './gitDocumentState'; - export interface LinesChangeEvent { readonly editor: TextEditor | undefined; @@ -15,12 +13,14 @@ export interface LinesChangeEvent { } export class LineTracker extends Disposable { + private _onDidChangeActiveLines = new EventEmitter(); get onDidChangeActiveLines(): Event { + this._onDidChangeActiveLines.event.length; return this._onDidChangeActiveLines.event; } - private _disposable: Disposable | undefined; + protected _disposable: Disposable | undefined; private _editor: TextEditor | undefined; private readonly _state: Map = new Map(); diff --git a/src/ui/settings/index.html b/src/ui/settings/index.html index 2f94ba5..8debfdb 100644 --- a/src/ui/settings/index.html +++ b/src/ui/settings/index.html @@ -2,8 +2,8 @@ - - + + @@ -12,7 +12,7 @@
- +

@@ -424,63 +422,66 @@

- +
-
- +
- +
- +
- - - - + + + +

@@ -577,7 +578,7 @@

- +
@@ -602,9 +603,9 @@
- - - + + +