Skip to content

Commit

Permalink
Adds setting to control blame annotation highlight
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
eamodio committed Feb 13, 2017
1 parent 6641233 commit 310a547
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 42 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Provides Git CodeLens information (most recent commit, # of authors), on-demand
|Name | Description
|-----|------------
|`gitlens.blame.annotation.style`|Specifies the style of the blame annotations. `compact` - groups annotations to limit the repetition and also adds author and date when possible. `expanded` - shows an annotation on every line
|`gitlens.blame.annotation.highlight`|Specifies whether and how to highlight blame annotations. `none` - no highlight. `gutter` - adds a gutter icon. `line` - adds a full-line highlight. `both` - adds both `gutter` and `line` highlights
|`gitlens.blame.annotation.sha`|Specifies whether the commit sha will be shown in the blame annotations. Applies only to the `expanded` & `trailing` annotation styles
|`gitlens.blame.annotation.author`|Specifies whether the committer will be shown in the blame annotations. Applies only to the `expanded` & `trailing` annotation styles
|`gitlens.blame.annotation.date`|Specifies whether the commit date will be shown in the blame annotations. Applies only to the `expanded` & `trailing` annotation styles
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
],
"description": "Specifies the style of the blame annotations. `compact` - groups annotations to limit the repetition and also adds author and date when possible. `expanded` - shows an annotation before every line. `trailing` - shows an annotation after every line"
},
"gitlens.blame.annotation.highlight": {
"type": "string",
"default": "both",
"enum": [
"none",
"gutter",
"line",
"both"
],
"description": "Specifies whether and how to highlight blame annotations. `none` - no highlight. `gutter` - adds a gutter icon. `line` - adds a full-line highlight. `both` - adds both `gutter` and `line` highlights"
},
"gitlens.blame.annotation.sha": {
"type": "boolean",
"default": true,
Expand Down
6 changes: 3 additions & 3 deletions src/blameActiveLineController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export default class BlameActiveLineController extends Disposable {

this._updateBlameDebounced = Functions.debounce(this._updateBlame, 50);

this._onConfigure();
this._onConfigurationChanged();

const subscriptions: Disposable[] = [];

subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigure, this));
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigurationChanged, this));
subscriptions.push(git.onDidRemoveCacheEntry(this._onRemoveCacheEntry, this));

this._disposable = Disposable.from(...subscriptions);
Expand All @@ -51,7 +51,7 @@ export default class BlameActiveLineController extends Disposable {
this._disposable && this._disposable.dispose();
}

private _onConfigure() {
private _onConfigurationChanged() {
const config = workspace.getConfiguration('').get<IConfig>('gitlens');

let changed: boolean = false;
Expand Down
84 changes: 79 additions & 5 deletions src/blameAnnotationController.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
'use strict';
import { Functions } from './system';
import { Disposable, ExtensionContext, TextDocument, TextEditor, TextEditorViewColumnChangeEvent, window, workspace } from 'vscode';
import { DecorationRenderOptions, Disposable, ExtensionContext, OverviewRulerLane, TextDocument, TextEditor, TextEditorDecorationType, TextEditorViewColumnChangeEvent, window, workspace } from 'vscode';
import { BlameAnnotationProvider } from './blameAnnotationProvider';
import { TextDocumentComparer, TextEditorComparer } from './comparers';
// import { IAdvancedConfig } from './configuration';
import { IBlameConfig } from './configuration';
import GitProvider from './gitProvider';
import { Logger } from './logger';
import WhitespaceController from './whitespaceController';

export const blameDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({
before: {
margin: '0 1.75em 0 0'
},
after: {
margin: '0 0 0 4em'
}
} as DecorationRenderOptions);

export let highlightDecoration: TextEditorDecorationType;

export default class BlameAnnotationController extends Disposable {

private _annotationProviders: Map<number, BlameAnnotationProvider> = new Map();
private _blameAnnotationsDisposable: Disposable;
private _config: IBlameConfig;
private _disposable: Disposable;
private _whitespaceController: WhitespaceController | undefined;

constructor(private context: ExtensionContext, private git: GitProvider) {
super(() => this.dispose());

this._onConfigure();
this._onConfigurationChanged();

const subscriptions: Disposable[] = [];

subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigure, this));
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigurationChanged, this));

this._disposable = Disposable.from(...subscriptions);
}
Expand All @@ -35,7 +47,7 @@ export default class BlameAnnotationController extends Disposable {
this._disposable && this._disposable.dispose();
}

private _onConfigure() {
private _onConfigurationChanged() {
let toggleWhitespace = workspace.getConfiguration('gitlens.advanced.toggleWhitespace').get<boolean>('enabled');
if (!toggleWhitespace) {
// Until https://github.com/Microsoft/vscode/issues/11485 is fixed we need to toggle whitespace for non-monospace fonts and ligatures
Expand All @@ -50,6 +62,68 @@ export default class BlameAnnotationController extends Disposable {
this._whitespaceController.dispose();
this._whitespaceController = undefined;
}

const config = workspace.getConfiguration('gitlens').get<IBlameConfig>('blame');

if (config.annotation.highlight !== (this._config && this._config.annotation.highlight)) {
highlightDecoration && highlightDecoration.dispose();

switch (config.annotation.highlight) {
case 'none':
highlightDecoration = undefined;
break;

case 'gutter':
highlightDecoration = window.createTextEditorDecorationType({
dark: {
gutterIconPath: this.context.asAbsolutePath('images/blame-dark.svg'),
overviewRulerColor: 'rgba(255, 255, 255, 0.75)'
},
light: {
gutterIconPath: this.context.asAbsolutePath('images/blame-light.svg'),
overviewRulerColor: 'rgba(0, 0, 0, 0.75)'
},
gutterIconSize: 'contain',
overviewRulerLane: OverviewRulerLane.Right
});
break;

case 'line':
highlightDecoration = window.createTextEditorDecorationType({
dark: {
backgroundColor: 'rgba(255, 255, 255, 0.15)',
overviewRulerColor: 'rgba(255, 255, 255, 0.75)'
},
light: {
backgroundColor: 'rgba(0, 0, 0, 0.15)',
overviewRulerColor: 'rgba(0, 0, 0, 0.75)'
},
overviewRulerLane: OverviewRulerLane.Right,
isWholeLine: true
});
break;

case 'both':
highlightDecoration = window.createTextEditorDecorationType({
dark: {
backgroundColor: 'rgba(255, 255, 255, 0.15)',
gutterIconPath: this.context.asAbsolutePath('images/blame-dark.svg'),
overviewRulerColor: 'rgba(255, 255, 255, 0.75)'
},
light: {
backgroundColor: 'rgba(0, 0, 0, 0.15)',
gutterIconPath: this.context.asAbsolutePath('images/blame-light.svg'),
overviewRulerColor: 'rgba(0, 0, 0, 0.75)'
},
gutterIconSize: 'contain',
overviewRulerLane: OverviewRulerLane.Right,
isWholeLine: true
});
break;
}
}

this._config = config;
}

async clear(column: number) {
Expand Down
36 changes: 5 additions & 31 deletions src/blameAnnotationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
'use strict';
import { Iterables } from './system';
import { DecorationInstanceRenderOptions, DecorationOptions, DecorationRenderOptions, Disposable, ExtensionContext, OverviewRulerLane, Range, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
import { DecorationInstanceRenderOptions, DecorationOptions, Disposable, ExtensionContext, Range, TextDocument, TextEditor, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
import BlameAnnotationFormatter, { BlameAnnotationFormat, cssIndent, defaultShaLength, defaultAuthorLength } from './blameAnnotationFormatter';
import { blameDecoration, highlightDecoration } from './blameAnnotationController';
import { TextDocumentComparer } from './comparers';
import { BlameAnnotationStyle, IBlameConfig } from './configuration';
import GitProvider, { GitUri, IGitBlame } from './gitProvider';
import WhitespaceController from './whitespaceController';

const blameDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({
before: {
margin: '0 1.75em 0 0'
},
after: {
margin: '0 0 0 4em'
}
} as DecorationRenderOptions);

let highlightDecoration: TextEditorDecorationType;

export class BlameAnnotationProvider extends Disposable {

public document: TextDocument;
Expand All @@ -30,24 +20,6 @@ export class BlameAnnotationProvider extends Disposable {
constructor(context: ExtensionContext, private git: GitProvider, private whitespaceController: WhitespaceController | undefined, public editor: TextEditor) {
super(() => this.dispose());

if (!highlightDecoration) {
highlightDecoration = window.createTextEditorDecorationType({
dark: {
backgroundColor: 'rgba(255, 255, 255, 0.15)',
gutterIconPath: context.asAbsolutePath('images/blame-dark.svg'),
overviewRulerColor: 'rgba(255, 255, 255, 0.75)'
},
light: {
backgroundColor: 'rgba(0, 0, 0, 0.15)',
gutterIconPath: context.asAbsolutePath('images/blame-light.svg'),
overviewRulerColor: 'rgba(0, 0, 0, 0.75)'
},
gutterIconSize: 'contain',
overviewRulerLane: OverviewRulerLane.Right,
isWholeLine: true
});
}

this.document = this.editor.document;
this._uri = GitUri.fromUri(this.document.uri, this.git);

Expand All @@ -65,7 +37,7 @@ export class BlameAnnotationProvider extends Disposable {
async dispose() {
if (this.editor) {
this.editor.setDecorations(blameDecoration, []);
this.editor.setDecorations(highlightDecoration, []);
highlightDecoration && this.editor.setDecorations(highlightDecoration, []);
}

// HACK: Until https://github.com/Microsoft/vscode/issues/11485 is fixed -- restore whitespace
Expand Down Expand Up @@ -123,6 +95,8 @@ export class BlameAnnotationProvider extends Disposable {
}

private _setSelection(blame: IGitBlame, shaOrLine?: string | number) {
if (!highlightDecoration) return;

const offset = this._uri.offset;

let sha: string;
Expand Down
1 change: 1 addition & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const BlameAnnotationStyle = {
export interface IBlameConfig {
annotation: {
style: BlameAnnotationStyle;
highlight: 'none' | 'gutter' | 'line' | 'both';
sha: boolean;
author: boolean;
date: 'off' | 'relative' | 'absolute';
Expand Down
6 changes: 3 additions & 3 deletions src/gitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export default class GitProvider extends Disposable {

this._repoPath = context.workspaceState.get(WorkspaceState.RepoPath) as string;

this._onConfigure();
this._onConfigurationChanged();

const subscriptions: Disposable[] = [];

subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigure, this));
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigurationChanged, this));

this._disposable = Disposable.from(...subscriptions);
}
Expand All @@ -99,7 +99,7 @@ export default class GitProvider extends Disposable {
return !!this._gitCache;
}

private _onConfigure() {
private _onConfigurationChanged() {
const config = workspace.getConfiguration().get<IConfig>('gitlens');

const codeLensChanged = !Objects.areEquivalent(config.codeLens, this.config && this.config.codeLens);
Expand Down

0 comments on commit 310a547

Please sign in to comment.