Skip to content

Commit c02ff46

Browse files
committed
Adds changes hover to file annotations
1 parent a38f163 commit c02ff46

File tree

8 files changed

+73
-36
lines changed

8 files changed

+73
-36
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
8+
### Added
9+
- Adds `changes` (diff) hover annotation support to both the `gutter` and `hover` file blame annotations
10+
- Adds `gitlens.annotations.file.gutter.hover.changes` setting to specify whether or not to provide a changes (diff) hover annotation over the gutter blame annotations
11+
- Adds `gitlens.annotations.file.hover.details` setting to specify whether or not to provide a commit details hover annotation over each line
12+
- Adds `gitlens.annotations.file.hover.changes` setting to specify whether or not to provide a changes (diff) hover annotation over each line
13+
814
### Changed
915
- Changes `gitlens.codeLens.customLocationSymbols` setting to both include and exclude (using a `!` prefix) symbols and therefore is always applied
1016

1117
### Removed
1218
- Removes `Custom` from the `gitlens.codeLens.locations` setting as it wasn't really required
1319
- 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
20+
- Removes `gitlens.annotations.file.hover.wholeLine` setting as it didn't really make sense
1421

1522
### Fixed
1623
- Fixes issue where changing `gitlens.blame.file.annotationType` wouldn't correctly update the blame annotations if they were currently active

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
4343
- Contains the commit message and date, by [default](#file-blame-annotation-settings)
4444
- Adds a `details` hover annotation to the line's annotation, which provides more commit details ([optional](#file-blame-annotation-settings), on by default)
4545

46-
![File Blame Annotations (hover)](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-file-blame-annotations.png)
46+
![File Details Blame Annotations (hover)](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-file-blame-annotations.png)
4747

4848
- Provides a **quick-access command bar** with `Open Changes`, `Blame Previous Revision`, `Open in Remote`, and `Show More Actions` command buttons
4949
- Clicking the commit id will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
50+
- Adds a `changes` (diff) hover annotation to the line's annotation, which provides **instant access** to the line's previous version ([optional](#file-blame-annotation-settings), on by default)
51+
- Clicking on `Changes` will run the `Compare File Revisions` command (`gitlens.diffWith`)
52+
- Clicking the current and previous commit ids will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
5053
- Adds a `heatmap` (age) indicator to the gutter annotations (on right edge by [default](#file-blame-annotation-settings)), which provides an easy, at-a-glance way to tell the age of a line ([optional](#file-blame-annotation-settings), on by default)
5154
- Indicator ranges from bright yellow (newer) to dark brown (older)
5255
- Press `Escape` to quickly toggle the annotations off
@@ -76,7 +79,7 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
7679

7780
- Adds on-demand, [customizable](#file-recent-changes-annotation-settings) and [themeable](#theme-settings), **recent changes annotations** of the whole file
7881
- Highlights all of lines changed in the most recent commit
79-
- Adds a `details` hover annotation to each line, which provides more commit details ([optional](#file-blame-annotation-settings), on by default)
82+
- Adds a `details` hover annotation to each line, which provides more commit details ([optional](#file-recent-changes-annotation-settings), on by default)
8083
- Clicking the commit id will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
8184
- Adds a `changes` (diff) hover annotation to each line, which provides **instant** access to the line's previous version ([optional](#file-recent-changes-annotation-settings), on by default)
8285
- Clicking on `Changes` will run the `Compare File Revisions` command (`gitlens.diffWith`)
@@ -316,9 +319,11 @@ GitLens is highly customizable and provides many configuration settings to allow
316319
|`gitlens.annotations.file.gutter.heatmap.enabled`|Specifies whether or not to provide a heatmap indicator in the gutter blame annotations
317320
|`gitlens.annotations.file.gutter.heatmap.location`|Specifies where the heatmap indicators will be shown in the gutter blame annotations<br />`left` - adds a heatmap indicator on the left edge of the gutter blame annotations<br />`right` - adds a heatmap indicator on the right edge of the gutter blame annotations
318321
|`gitlens.annotations.file.gutter.hover.details`|Specifies whether or not to provide a commit details hover annotation over the gutter blame annotations
322+
|`gitlens.annotations.file.gutter.hover.changes`|Specifies whether or not to provide a changes (diff) hover annotation over the gutter blame annotations
319323
|`gitlens.annotations.file.gutter.hover.wholeLine`|Specifies whether or not to trigger hover annotations over the whole line
324+
|`gitlens.annotations.file.hover.details`|Specifies whether or not to provide a commit details hover annotation over each line
325+
|`gitlens.annotations.file.hover.changes`|Specifies whether or not to provide a changes (diff) hover annotation over each line
320326
|`gitlens.annotations.file.hover.heatmap.enabled`|Specifies whether or not to provide heatmap indicators on the left edge of each line
321-
|`gitlens.annotations.file.hover.wholeLine`|Specifies whether or not to trigger hover annotations over the whole line
322327

323328
#### Line Blame Annotation Settings
324329

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,30 @@
107107
"default": true,
108108
"description": "Specifies whether or not to provide a commit details hover annotation over the gutter blame annotations"
109109
},
110+
"gitlens.annotations.file.gutter.hover.changes": {
111+
"type": "boolean",
112+
"default": true,
113+
"description": "Specifies whether or not to provide a changes (diff) hover annotation over the gutter blame annotations"
114+
},
110115
"gitlens.annotations.file.gutter.hover.wholeLine": {
111116
"type": "boolean",
112117
"default": true,
113118
"description": "Specifies whether or not to trigger hover annotations over the whole line"
114119
},
115-
"gitlens.annotations.file.hover.heatmap.enabled": {
120+
"gitlens.annotations.file.hover.details": {
116121
"type": "boolean",
117122
"default": true,
118-
"description": "Specifies whether or not to provide heatmap indicators on the left edge of each line"
123+
"description": "Specifies whether or not to provide a commit details hover annotation over each line"
119124
},
120-
"gitlens.annotations.file.hover.wholeLine": {
125+
"gitlens.annotations.file.hover.changes": {
121126
"type": "boolean",
122127
"default": true,
123-
"description": "Specifies whether or not to trigger hover annotations over the whole line"
128+
"description": "Specifies whether or not to provide a changes (diff) hover annotation over each line"
129+
},
130+
"gitlens.annotations.file.hover.heatmap.enabled": {
131+
"type": "boolean",
132+
"default": true,
133+
"description": "Specifies whether or not to provide heatmap indicators on the left edge of each line"
124134
},
125135
"gitlens.annotations.file.recentChanges.hover.details": {
126136
"type": "boolean",

src/annotations/blameAnnotationProvider.ts

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AnnotationProviderBase } from './annotationProvider';
55
import { Annotations, endOfLineIndex } from './annotations';
66
import { GitBlame, GitCommit, GitService, GitUri } from '../gitService';
77

8-
export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase implements HoverProvider {
8+
export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase {
99

1010
protected _blame: Promise<GitBlame | undefined>;
1111
protected _hoverProviderDisposable: Disposable;
@@ -74,23 +74,22 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
7474
return blame;
7575
}
7676

77-
registerHoverProvider() {
78-
this._hoverProviderDisposable = languages.registerHoverProvider({ pattern: this.document.uri.fsPath }, this);
79-
}
80-
81-
async provideHover(document: TextDocument, position: Position, token: CancellationToken): Promise<Hover | undefined> {
82-
// Avoid double annotations if we are showing the whole-file hover blame annotations
83-
if (this._config.blame.line.enabled && this.editor.selection.start.line === position.line) return undefined;
77+
registerHoverProviders(providers: { details: boolean, changes: boolean }) {
78+
if (!providers.details && !providers.changes) return;
8479

85-
const cfg = this._config.annotations.file.gutter;
86-
if (!cfg.hover.wholeLine && position.character !== 0) return undefined;
87-
88-
const blame = await this.getBlame();
89-
if (blame === undefined) return undefined;
80+
const subscriptions: Disposable[] = [];
81+
if (providers.changes) {
82+
subscriptions.push(languages.registerHoverProvider({ pattern: this.document.uri.fsPath }, { provideHover: this.provideChangesHover.bind(this) } as HoverProvider));
83+
}
84+
if (providers.details) {
85+
subscriptions.push(languages.registerHoverProvider({ pattern: this.document.uri.fsPath }, { provideHover: this.provideDetailsHover.bind(this) } as HoverProvider));
86+
}
9087

91-
const line = blame.lines[position.line];
88+
this._hoverProviderDisposable = Disposable.from(...subscriptions);
89+
}
9290

93-
const commit = blame.commits.get(line.sha);
91+
async provideDetailsHover(document: TextDocument, position: Position, token: CancellationToken): Promise<Hover | undefined> {
92+
const commit = await this.getCommitForHover(position);
9493
if (commit === undefined) return undefined;
9594

9695
// Get the full commit message -- since blame only returns the summary
@@ -107,4 +106,27 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
107106
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType);
108107
return new Hover(message, document.validateRange(new Range(position.line, 0, position.line, endOfLineIndex)));
109108
}
109+
110+
async provideChangesHover(document: TextDocument, position: Position, token: CancellationToken): Promise<Hover | undefined> {
111+
const commit = await this.getCommitForHover(position);
112+
if (commit === undefined) return undefined;
113+
114+
const hover = await Annotations.changesHover(commit, position.line, await GitUri.fromUri(document.uri, this.git), this.git);
115+
return new Hover(hover.hoverMessage!, document.validateRange(new Range(position.line, 0, position.line, endOfLineIndex)));
116+
}
117+
118+
private async getCommitForHover(position: Position): Promise<GitCommit | undefined> {
119+
// Avoid double annotations if we are showing the whole-file hover blame annotations
120+
if (this._config.blame.line.enabled && this.editor.selection.start.line === position.line) return undefined;
121+
122+
const cfg = this._config.annotations.file.gutter;
123+
if (!cfg.hover.wholeLine && position.character !== 0) return undefined;
124+
125+
const blame = await this.getBlame();
126+
if (blame === undefined) return undefined;
127+
128+
const line = blame.lines[position.line];
129+
130+
return blame.commits.get(line.sha);
131+
}
110132
}

src/annotations/gutterBlameAnnotationProvider.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
119119
const duration = process.hrtime(start);
120120
Logger.log(`${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms to compute gutter blame annotations`);
121121

122-
if (cfg.hover.details) {
123-
this.registerHoverProvider();
124-
}
125-
122+
this.registerHoverProviders(cfg.hover);
126123
this.selection(shaOrLine, blame);
127124
return true;
128125
}

src/annotations/hoverBlameAnnotationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
6363
Logger.log(`${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms to compute hover blame annotations`);
6464
}
6565

66-
this.registerHoverProvider();
66+
this.registerHoverProviders(cfg);
6767
this.selection(shaOrLine, blame);
6868
return true;
6969
}

src/configuration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,17 @@ export interface IConfig {
238238
};
239239
hover: {
240240
details: boolean;
241+
changes: boolean;
241242
wholeLine: boolean;
242243
};
243244
};
244245

245246
hover: {
247+
details: boolean;
248+
changes: boolean;
246249
heatmap: {
247250
enabled: boolean;
248251
};
249-
wholeLine: boolean;
250252
};
251253

252254
recentChanges: {
@@ -267,8 +269,8 @@ export interface IConfig {
267269
format: string;
268270
dateFormat: string | null;
269271
hover: {
270-
changes: boolean;
271272
details: boolean;
273+
changes: boolean;
272274
wholeLine: boolean;
273275
};
274276
};

src/currentLineController.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,7 @@ export class CurrentLineController extends Disposable {
338338
break;
339339
}
340340
case FileAnnotationType.Hover: {
341-
const cfgHover = this._config.annotations.file.hover;
342-
if (cfgHover.wholeLine) {
343-
showStartIndex = 0;
344-
}
345-
else if (showStartIndex !== 0) {
346-
showAtStart = true;
347-
}
341+
showStartIndex = 0;
348342

349343
break;
350344
}

0 commit comments

Comments
 (0)