Skip to content

Commit 878c389

Browse files
committed
Fixes #176 & #205 - better blameability eventing
1 parent c47d6b5 commit 878c389

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
77
## [Unreleased]
88
### Fixed
99
- Fixes [#207](https://github.com/eamodio/vscode-gitlens/issues/207) - Applying and deleting stashes suddenly stopped working
10+
- Fixes [#205](https://github.com/eamodio/vscode-gitlens/issues/205) - Toggle Line Blame Annotations disappeared after last update
1011
- Fixes [#203](https://github.com/eamodio/vscode-gitlens/issues/203) - Open Changed Files is broken
12+
- Fixes [#176](https://github.com/eamodio/vscode-gitlens/issues/176) - Line annotations some times mess with white space
1113

1214
## [6.1.1] - 2017-11-17
1315
### Fixed

src/currentLineController.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { Functions } from './system';
2+
import { Functions, IDeferred } from './system';
33
import { CancellationToken, ConfigurationChangeEvent, debug, DecorationRangeBehavior, DecorationRenderOptions, Disposable, ExtensionContext, Hover, HoverProvider, languages, Position, Range, StatusBarAlignment, StatusBarItem, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window } from 'vscode';
44
import { AnnotationController, FileAnnotationType } from './annotations/annotationController';
55
import { Annotations, endOfLineIndex } from './annotations/annotations';
@@ -36,7 +36,7 @@ export class CurrentLineController extends Disposable {
3636
private _isAnnotating: boolean = false;
3737
private _statusBarItem: StatusBarItem | undefined;
3838
private _trackCurrentLineDisposable: Disposable | undefined;
39-
private _updateBlameDebounced: (line: number, editor: TextEditor) => Promise<void>;
39+
private _updateBlameDebounced: ((line: number, editor: TextEditor) => Promise<void>) & IDeferred;
4040
private _uri: GitUri;
4141

4242
constructor(
@@ -138,17 +138,23 @@ export class CurrentLineController extends Disposable {
138138
}
139139

140140
private onBlameabilityChanged(e: BlameabilityChangeEvent) {
141-
if (!this._blameable && !e.blameable) return;
141+
// Make sure this is for the editor we are tracking
142+
if (!TextEditorComparer.equals(this._editor, e.editor)) return;
143+
144+
if (!this._blameable && !e.blameable) {
145+
this._updateBlameDebounced.cancel();
146+
147+
return;
148+
}
142149

143150
this._blameable = e.blameable;
144151
if (!e.blameable || this._editor === undefined) {
145-
this.clear(e.editor);
152+
this._updateBlameDebounced.cancel();
153+
this.updateBlame(this._currentLine.line, e.editor!);
154+
146155
return;
147156
}
148157

149-
// Make sure this is for the editor we are tracking
150-
if (!TextEditorComparer.equals(this._editor, e.editor)) return;
151-
152158
this._updateBlameDebounced(this._editor.selection.active.line, this._editor);
153159
}
154160

@@ -215,8 +221,12 @@ export class CurrentLineController extends Disposable {
215221
// Since blame information isn't valid when there are unsaved changes -- don't show any status
216222
if (this._blameable && line >= 0) {
217223
const blameLine = await this.git.getBlameForLine(this._uri, line);
218-
commitLine = blameLine === undefined ? undefined : blameLine.line;
219-
commit = blameLine === undefined ? undefined : blameLine.commit;
224+
225+
// Make sure we are still blameable after the await
226+
if (this._blameable) {
227+
commitLine = blameLine === undefined ? undefined : blameLine.line;
228+
commit = blameLine === undefined ? undefined : blameLine.commit;
229+
}
220230
}
221231

222232
this._currentLine.commit = commit;
@@ -255,14 +265,14 @@ export class CurrentLineController extends Disposable {
255265

256266
this.clearAnnotations(this._editor);
257267

258-
if (editor === undefined || !this.isEditorBlameable(editor)) {
259-
this.clear(editor);
268+
this._blameable = this.isEditorBlameable(editor);
269+
if (!this._blameable || editor === undefined) {
270+
this.updateBlame(this._currentLine.line, editor!);
260271
this._editor = undefined;
261272

262273
return;
263274
}
264275

265-
this._blameable = editor !== undefined && editor.document !== undefined && !editor.document.isDirty;
266276
this._editor = editor;
267277
this._uri = await GitUri.fromUri(editor.document.uri, this.git);
268278

src/git/gitContextTracker.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { Functions } from '../system';
2+
import { Functions, IDeferred } from '../system';
33
import { ConfigurationChangeEvent, Disposable, Event, EventEmitter, TextDocumentChangeEvent, TextEditor, window, workspace } from 'vscode';
44
import { TextDocumentComparer } from '../comparers';
55
import { configuration } from '../configuration';
@@ -44,16 +44,19 @@ export class GitContextTracker extends Disposable {
4444
private readonly _context: Context = { state: { dirty: false } };
4545
private readonly _disposable: Disposable;
4646
private _listenersDisposable: Disposable | undefined;
47+
private _onDirtyStateChangedDebounced: ((dirty: boolean) => void) & IDeferred;
4748

4849
constructor(
4950
private readonly git: GitService
5051
) {
5152
super(() => this.dispose());
5253

54+
this._onDirtyStateChangedDebounced = Functions.debounce(this.onDirtyStateChanged, 250);
55+
5356
this._disposable = Disposable.from(
5457
workspace.onDidChangeConfiguration(this.onConfigurationChanged, this)
5558
);
56-
this.onConfigurationChanged(configuration.initializingChangeEvent);
59+
this.onConfigurationChanged(configuration.initializingChangeEvent);
5760
}
5861

5962
dispose() {
@@ -75,7 +78,7 @@ export class GitContextTracker extends Disposable {
7578
if (enabled) {
7679
this._listenersDisposable = Disposable.from(
7780
window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveTextEditorChanged, 50), this),
78-
workspace.onDidChangeTextDocument(Functions.debounce(this.onTextDocumentChanged, 50), this),
81+
workspace.onDidChangeTextDocument(this.onTextDocumentChanged, this),
7982
this.git.onDidBlameFail(this.onBlameFailed, this),
8083
this.git.onDidChange(this.onGitChanged, this)
8184
);
@@ -102,6 +105,11 @@ export class GitContextTracker extends Disposable {
102105
this.updateBlameability(BlameabilityChangeReason.BlameFailed, false);
103106
}
104107

108+
private onDirtyStateChanged(dirty: boolean) {
109+
this._context.state.dirty = dirty;
110+
this.updateBlameability(BlameabilityChangeReason.DocumentChanged);
111+
}
112+
105113
private onGitChanged(e: GitChangeEvent) {
106114
if (e.reason !== GitChangeReason.Repositories) return;
107115

@@ -116,13 +124,25 @@ export class GitContextTracker extends Disposable {
116124
private onTextDocumentChanged(e: TextDocumentChangeEvent) {
117125
if (this._context.editor === undefined || !TextDocumentComparer.equals(this._context.editor.document, e.document)) return;
118126

127+
const dirty = e.document.isDirty;
128+
119129
// If we haven't changed state, kick out
120-
if (this._context.state.dirty === e.document.isDirty) return;
130+
if (dirty === this._context.state.dirty) {
131+
this._onDirtyStateChangedDebounced.cancel();
121132

122-
// Logger.log('GitContextTracker.onTextDocumentChanged', 'Dirty state changed', e);
133+
return;
134+
}
123135

124-
this._context.state.dirty = e.document.isDirty;
125-
this.updateBlameability(BlameabilityChangeReason.DocumentChanged);
136+
// Logger.log('GitContextTracker.onTextDocumentChanged', `Dirty(${dirty}) state changed`);
137+
138+
if (dirty) {
139+
this._onDirtyStateChangedDebounced.cancel();
140+
this.onDirtyStateChanged(dirty);
141+
142+
return;
143+
}
144+
145+
this._onDirtyStateChangedDebounced(dirty);
126146
}
127147

128148
private async updateContext(reason: BlameabilityChangeReason, editor: TextEditor | undefined, force: boolean = false) {

0 commit comments

Comments
 (0)