Skip to content

Commit 03fefaa

Browse files
committed
Disables current line blame annotations when debugging
1 parent f11c00c commit 03fefaa

File tree

2 files changed

+72
-48
lines changed

2 files changed

+72
-48
lines changed

CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [4.x] - 2017-08-16
7+
## [4.4.0] - 2017-08-17
88
## Added
9-
- Adds progress indicator to the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) icon
10-
- Icon pulses while annotations are computed
11-
- Adds active state to the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) icon
12-
- Icon turns orange while the annotations are visible
9+
- Adds progress indicator to the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) icon -- pulses while annotations are computed
10+
- Adds active state to the `Toggle File Blame Annotations` command (`gitlens.toggleFileBlame`) icon -- turns orange while the annotations are visible
11+
- Adds automatic disabling of the current line blame annotations when starting a debug session and will restore them when the debug session ends -- can still be manually toggled via the `Toggle Line Blame Annotations` command (`gitlens.toggleLineBlame`)
1312

1413
## Changed
1514
- Changes chat links from Gitter to [Slack](https://join.slack.com/t/vscode-gitlens/shared_invite/MjIxOTgxNDE3NzM0LTE1MDE2Nzk1MTgtMjkwMmZjMzcxNQ)
1615
- Changes the look of the line separators on the gutter blame annotations
16+
- Changes gitlens.advanced.toggleWhitespace.enabled
1717

1818
## Removed
1919
- Removes unneeded `gitlens.stashExplorer.enabled` configuration setting since users can add or remove custom views natively now
@@ -35,7 +35,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
3535

3636
## [4.3.2] - 2017-07-20
3737
## Fixed
38-
- Fixes [#118](https://github.com/eamodio/vscode-gitlens/issues/118) - GitLens stopped working on latest insiders build-- thanks to [PR #121](https://github.com/eamodio/vscode-gitlens/pull/121) by Johannes Rieken ([@jrieken](https://github.com/jrieken))
38+
- Fixes [#118](https://github.com/eamodio/vscode-gitlens/issues/118) - GitLens stopped working on latest insiders build -- thanks to [PR #121](https://github.com/eamodio/vscode-gitlens/pull/121) by Johannes Rieken ([@jrieken](https://github.com/jrieken))
3939

4040
## [4.3.1] - 2017-07-03
4141
## Added

src/currentLineController.ts

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
import { Functions, Objects } from './system';
3-
import { DecorationOptions, DecorationRenderOptions, Disposable, ExtensionContext, Range, StatusBarAlignment, StatusBarItem, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
3+
import { debug, DecorationOptions, DecorationRenderOptions, Disposable, ExtensionContext, Range, StatusBarAlignment, StatusBarItem, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
44
import { AnnotationController, FileAnnotationType } from './annotations/annotationController';
55
import { Annotations, endOfLineIndex } from './annotations/annotations';
66
import { Commands } from './commands';
@@ -26,9 +26,10 @@ export const LineAnnotationType = {
2626
export class CurrentLineController extends Disposable {
2727

2828
private _blameable: boolean;
29-
private _blameLineAnnotationState: { enabled: boolean, annotationType: LineAnnotationType } | undefined = undefined;
29+
private _blameLineAnnotationState: { enabled: boolean, annotationType: LineAnnotationType, reason: 'user' | 'debugging' } | undefined = undefined;
3030
private _config: IConfig;
3131
private _currentLine: number = -1;
32+
private _debugSessionEndDisposable: Disposable | undefined;
3233
private _disposable: Disposable;
3334
private _editor: TextEditor | undefined;
3435
private _isAnnotating: boolean = false;
@@ -48,7 +49,8 @@ export class CurrentLineController extends Disposable {
4849

4950
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigurationChanged, this));
5051
subscriptions.push(git.onDidChangeGitCache(this._onGitCacheChanged, this));
51-
subscriptions.push(annotationController.onDidToggleAnnotations(this._onAnnotationsToggled, this));
52+
subscriptions.push(annotationController.onDidToggleAnnotations(this._onFileAnnotationsToggled, this));
53+
subscriptions.push(debug.onDidStartDebugSession(this._onDebugSessionStarted, this));
5254

5355
this._disposable = Disposable.from(...subscriptions);
5456
}
@@ -58,6 +60,7 @@ export class CurrentLineController extends Disposable {
5860

5961
this._trackCurrentLineDisposable && this._trackCurrentLineDisposable.dispose();
6062
this._statusBarItem && this._statusBarItem.dispose();
63+
this._debugSessionEndDisposable && this._debugSessionEndDisposable.dispose();
6164
this._disposable && this._disposable.dispose();
6265
}
6366

@@ -117,40 +120,11 @@ export class CurrentLineController extends Disposable {
117120
this._trackCurrentLineDisposable = undefined;
118121
}
119122

120-
this._onActiveTextEditorChanged(window.activeTextEditor);
123+
this.refresh(window.activeTextEditor);
121124
}
122125

123-
private isEditorBlameable(editor: TextEditor | undefined): boolean {
124-
if (editor === undefined || editor.document === undefined) return false;
125-
126-
if (!this.git.isTrackable(editor.document.uri)) return false;
127-
if (editor.document.isUntitled && editor.document.uri.scheme === DocumentSchemes.File) return false;
128-
129-
return this.git.isEditorBlameable(editor);
130-
}
131-
132-
private async _onActiveTextEditorChanged(editor: TextEditor | undefined) {
133-
this._currentLine = -1;
134-
this._clearAnnotations(this._editor);
135-
136-
if (editor === undefined || !this.isEditorBlameable(editor)) {
137-
this.clear(editor);
138-
this._editor = undefined;
139-
140-
return;
141-
}
142-
143-
this._blameable = editor !== undefined && editor.document !== undefined && !editor.document.isDirty;
144-
this._editor = editor;
145-
this._uri = await GitUri.fromUri(editor.document.uri, this.git);
146-
147-
const maxLines = this._config.advanced.caching.maxLines;
148-
// If caching is on and the file is small enough -- kick off a blame for the whole file
149-
if (this._config.advanced.caching.enabled && (maxLines <= 0 || editor.document.lineCount <= maxLines)) {
150-
this.git.getBlameForFile(this._uri);
151-
}
152-
153-
this._updateBlameDebounced(editor.selection.active.line, editor);
126+
private _onActiveTextEditorChanged(editor?: TextEditor) {
127+
this.refresh(editor);
154128
}
155129

156130
private _onBlameabilityChanged(e: BlameabilityChangeEvent) {
@@ -166,13 +140,30 @@ export class CurrentLineController extends Disposable {
166140
this._updateBlameDebounced(this._editor.selection.active.line, this._editor);
167141
}
168142

169-
private _onAnnotationsToggled() {
170-
this._onActiveTextEditorChanged(window.activeTextEditor);
143+
private _onDebugSessionStarted() {
144+
const state = this._blameLineAnnotationState !== undefined ? this._blameLineAnnotationState : this._config.blame.line;
145+
if (!state.enabled) return;
146+
147+
this._debugSessionEndDisposable = debug.onDidTerminateDebugSession(this._onDebugSessionEnded, this);
148+
this.toggleAnnotations(window.activeTextEditor, state.annotationType, 'debugging');
149+
}
150+
151+
private _onDebugSessionEnded() {
152+
this._debugSessionEndDisposable && this._debugSessionEndDisposable.dispose();
153+
this._debugSessionEndDisposable = undefined;
154+
155+
if (this._blameLineAnnotationState === undefined || this._blameLineAnnotationState.enabled || this._blameLineAnnotationState.reason !== 'debugging') return;
156+
157+
this.toggleAnnotations(window.activeTextEditor, this._blameLineAnnotationState.annotationType);
158+
}
159+
160+
private _onFileAnnotationsToggled() {
161+
this.refresh(window.activeTextEditor);
171162
}
172163

173164
private _onGitCacheChanged() {
174165
Logger.log('Git cache changed; resetting current line annotations');
175-
this._onActiveTextEditorChanged(window.activeTextEditor);
166+
this.refresh(window.activeTextEditor);
176167
}
177168

178169
private async _onTextEditorSelectionChanged(e: TextEditorSelectionChangeEvent): Promise<void> {
@@ -192,6 +183,15 @@ export class CurrentLineController extends Disposable {
192183
this._updateBlameDebounced(line, e.textEditor);
193184
}
194185

186+
private _isEditorBlameable(editor: TextEditor | undefined): boolean {
187+
if (editor === undefined || editor.document === undefined) return false;
188+
189+
if (!this.git.isTrackable(editor.document.uri)) return false;
190+
if (editor.document.isUntitled && editor.document.uri.scheme === DocumentSchemes.File) return false;
191+
192+
return this.git.isEditorBlameable(editor);
193+
}
194+
195195
private async _updateBlame(line: number, editor: TextEditor) {
196196
line = line - this._uri.offset;
197197

@@ -230,6 +230,30 @@ export class CurrentLineController extends Disposable {
230230
editor.setDecorations(annotationDecoration, []);
231231
}
232232

233+
async refresh(editor?: TextEditor) {
234+
this._currentLine = -1;
235+
this._clearAnnotations(this._editor);
236+
237+
if (editor === undefined || !this._isEditorBlameable(editor)) {
238+
this.clear(editor);
239+
this._editor = undefined;
240+
241+
return;
242+
}
243+
244+
this._blameable = editor !== undefined && editor.document !== undefined && !editor.document.isDirty;
245+
this._editor = editor;
246+
this._uri = await GitUri.fromUri(editor.document.uri, this.git);
247+
248+
const maxLines = this._config.advanced.caching.maxLines;
249+
// If caching is on and the file is small enough -- kick off a blame for the whole file
250+
if (this._config.advanced.caching.enabled && (maxLines <= 0 || editor.document.lineCount <= maxLines)) {
251+
this.git.getBlameForFile(this._uri);
252+
}
253+
254+
this._updateBlameDebounced(editor.selection.active.line, editor);
255+
}
256+
233257
async show(commit: GitCommit, blameLine: GitCommitLine, editor: TextEditor, line: number) {
234258
// I have no idea why I need this protection -- but it happens
235259
if (editor.document === undefined) return;
@@ -238,23 +262,23 @@ export class CurrentLineController extends Disposable {
238262
await this._updateAnnotations(commit, blameLine, editor, line);
239263
}
240264

241-
async showAnnotations(editor: TextEditor, type: LineAnnotationType) {
265+
async showAnnotations(editor: TextEditor | undefined, type: LineAnnotationType, reason: 'user' | 'debugging' = 'user') {
242266
if (editor === undefined) return;
243267

244268
const state = this._blameLineAnnotationState !== undefined ? this._blameLineAnnotationState : this._config.blame.line;
245269
if (!state.enabled || state.annotationType !== type) {
246-
this._blameLineAnnotationState = { enabled: true, annotationType: type };
270+
this._blameLineAnnotationState = { enabled: true, annotationType: type, reason: reason };
247271

248272
await this._clearAnnotations(editor);
249273
await this._updateBlame(editor.selection.active.line, editor);
250274
}
251275
}
252276

253-
async toggleAnnotations(editor: TextEditor, type: LineAnnotationType) {
277+
async toggleAnnotations(editor: TextEditor | undefined, type: LineAnnotationType, reason: 'user' | 'debugging' = 'user') {
254278
if (editor === undefined) return;
255279

256280
const state = this._blameLineAnnotationState !== undefined ? this._blameLineAnnotationState : this._config.blame.line;
257-
this._blameLineAnnotationState = { enabled: !state.enabled, annotationType: type };
281+
this._blameLineAnnotationState = { enabled: !state.enabled, annotationType: type, reason: reason };
258282

259283
await this._clearAnnotations(editor);
260284
await this._updateBlame(editor.selection.active.line, editor);

0 commit comments

Comments
 (0)