Skip to content

Commit

Permalink
Adds changes hover to file annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 11, 2017
1 parent a38f163 commit c02ff46
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 36 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Adds `changes` (diff) hover annotation support to both the `gutter` and `hover` file blame annotations
- 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
- Adds `gitlens.annotations.file.hover.details` setting to specify whether or not to provide a commit details hover annotation over each line
- Adds `gitlens.annotations.file.hover.changes` setting to specify whether or not to provide a changes (diff) hover annotation over each line

### Changed
- Changes `gitlens.codeLens.customLocationSymbols` setting to both include and exclude (using a `!` prefix) symbols and therefore is always applied

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

### Fixed
- Fixes issue where changing `gitlens.blame.file.annotationType` wouldn't correctly update the blame annotations if they were currently active
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
- Contains the commit message and date, by [default](#file-blame-annotation-settings)
- Adds a `details` hover annotation to the line's annotation, which provides more commit details ([optional](#file-blame-annotation-settings), on by default)

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

- Provides a **quick-access command bar** with `Open Changes`, `Blame Previous Revision`, `Open in Remote`, and `Show More Actions` command buttons
- Clicking the commit id will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
- 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)
- Clicking on `Changes` will run the `Compare File Revisions` command (`gitlens.diffWith`)
- Clicking the current and previous commit ids will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
- 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)
- Indicator ranges from bright yellow (newer) to dark brown (older)
- Press `Escape` to quickly toggle the annotations off
Expand Down Expand Up @@ -76,7 +79,7 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,

- Adds on-demand, [customizable](#file-recent-changes-annotation-settings) and [themeable](#theme-settings), **recent changes annotations** of the whole file
- Highlights all of lines changed in the most recent commit
- Adds a `details` hover annotation to each line, which provides more commit details ([optional](#file-blame-annotation-settings), on by default)
- Adds a `details` hover annotation to each line, which provides more commit details ([optional](#file-recent-changes-annotation-settings), on by default)
- Clicking the commit id will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
- 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)
- Clicking on `Changes` will run the `Compare File Revisions` command (`gitlens.diffWith`)
Expand Down Expand Up @@ -316,9 +319,11 @@ GitLens is highly customizable and provides many configuration settings to allow
|`gitlens.annotations.file.gutter.heatmap.enabled`|Specifies whether or not to provide a heatmap indicator in the gutter blame annotations
|`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
|`gitlens.annotations.file.gutter.hover.details`|Specifies whether or not to provide a commit details hover annotation over the gutter blame annotations
|`gitlens.annotations.file.gutter.hover.changes`|Specifies whether or not to provide a changes (diff) hover annotation over the gutter blame annotations
|`gitlens.annotations.file.gutter.hover.wholeLine`|Specifies whether or not to trigger hover annotations over the whole line
|`gitlens.annotations.file.hover.details`|Specifies whether or not to provide a commit details hover annotation over each line
|`gitlens.annotations.file.hover.changes`|Specifies whether or not to provide a changes (diff) hover annotation over each line
|`gitlens.annotations.file.hover.heatmap.enabled`|Specifies whether or not to provide heatmap indicators on the left edge of each line
|`gitlens.annotations.file.hover.wholeLine`|Specifies whether or not to trigger hover annotations over the whole line

#### Line Blame Annotation Settings

Expand Down
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,30 @@
"default": true,
"description": "Specifies whether or not to provide a commit details hover annotation over the gutter blame annotations"
},
"gitlens.annotations.file.gutter.hover.changes": {
"type": "boolean",
"default": true,
"description": "Specifies whether or not to provide a changes (diff) hover annotation over the gutter blame annotations"
},
"gitlens.annotations.file.gutter.hover.wholeLine": {
"type": "boolean",
"default": true,
"description": "Specifies whether or not to trigger hover annotations over the whole line"
},
"gitlens.annotations.file.hover.heatmap.enabled": {
"gitlens.annotations.file.hover.details": {
"type": "boolean",
"default": true,
"description": "Specifies whether or not to provide heatmap indicators on the left edge of each line"
"description": "Specifies whether or not to provide a commit details hover annotation over each line"
},
"gitlens.annotations.file.hover.wholeLine": {
"gitlens.annotations.file.hover.changes": {
"type": "boolean",
"default": true,
"description": "Specifies whether or not to trigger hover annotations over the whole line"
"description": "Specifies whether or not to provide a changes (diff) hover annotation over each line"
},
"gitlens.annotations.file.hover.heatmap.enabled": {
"type": "boolean",
"default": true,
"description": "Specifies whether or not to provide heatmap indicators on the left edge of each line"
},
"gitlens.annotations.file.recentChanges.hover.details": {
"type": "boolean",
Expand Down
52 changes: 37 additions & 15 deletions src/annotations/blameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AnnotationProviderBase } from './annotationProvider';
import { Annotations, endOfLineIndex } from './annotations';
import { GitBlame, GitCommit, GitService, GitUri } from '../gitService';

export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase implements HoverProvider {
export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase {

protected _blame: Promise<GitBlame | undefined>;
protected _hoverProviderDisposable: Disposable;
Expand Down Expand Up @@ -74,23 +74,22 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
return blame;
}

registerHoverProvider() {
this._hoverProviderDisposable = languages.registerHoverProvider({ pattern: this.document.uri.fsPath }, this);
}

async provideHover(document: TextDocument, position: Position, token: CancellationToken): Promise<Hover | undefined> {
// Avoid double annotations if we are showing the whole-file hover blame annotations
if (this._config.blame.line.enabled && this.editor.selection.start.line === position.line) return undefined;
registerHoverProviders(providers: { details: boolean, changes: boolean }) {
if (!providers.details && !providers.changes) return;

const cfg = this._config.annotations.file.gutter;
if (!cfg.hover.wholeLine && position.character !== 0) return undefined;

const blame = await this.getBlame();
if (blame === undefined) return undefined;
const subscriptions: Disposable[] = [];
if (providers.changes) {
subscriptions.push(languages.registerHoverProvider({ pattern: this.document.uri.fsPath }, { provideHover: this.provideChangesHover.bind(this) } as HoverProvider));
}
if (providers.details) {
subscriptions.push(languages.registerHoverProvider({ pattern: this.document.uri.fsPath }, { provideHover: this.provideDetailsHover.bind(this) } as HoverProvider));
}

const line = blame.lines[position.line];
this._hoverProviderDisposable = Disposable.from(...subscriptions);
}

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

// Get the full commit message -- since blame only returns the summary
Expand All @@ -107,4 +106,27 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType);
return new Hover(message, document.validateRange(new Range(position.line, 0, position.line, endOfLineIndex)));
}

async provideChangesHover(document: TextDocument, position: Position, token: CancellationToken): Promise<Hover | undefined> {
const commit = await this.getCommitForHover(position);
if (commit === undefined) return undefined;

const hover = await Annotations.changesHover(commit, position.line, await GitUri.fromUri(document.uri, this.git), this.git);
return new Hover(hover.hoverMessage!, document.validateRange(new Range(position.line, 0, position.line, endOfLineIndex)));
}

private async getCommitForHover(position: Position): Promise<GitCommit | undefined> {
// Avoid double annotations if we are showing the whole-file hover blame annotations
if (this._config.blame.line.enabled && this.editor.selection.start.line === position.line) return undefined;

const cfg = this._config.annotations.file.gutter;
if (!cfg.hover.wholeLine && position.character !== 0) return undefined;

const blame = await this.getBlame();
if (blame === undefined) return undefined;

const line = blame.lines[position.line];

return blame.commits.get(line.sha);
}
}
5 changes: 1 addition & 4 deletions src/annotations/gutterBlameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
const duration = process.hrtime(start);
Logger.log(`${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms to compute gutter blame annotations`);

if (cfg.hover.details) {
this.registerHoverProvider();
}

this.registerHoverProviders(cfg.hover);
this.selection(shaOrLine, blame);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/hoverBlameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
Logger.log(`${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms to compute hover blame annotations`);
}

this.registerHoverProvider();
this.registerHoverProviders(cfg);
this.selection(shaOrLine, blame);
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,17 @@ export interface IConfig {
};
hover: {
details: boolean;
changes: boolean;
wholeLine: boolean;
};
};

hover: {
details: boolean;
changes: boolean;
heatmap: {
enabled: boolean;
};
wholeLine: boolean;
};

recentChanges: {
Expand All @@ -267,8 +269,8 @@ export interface IConfig {
format: string;
dateFormat: string | null;
hover: {
changes: boolean;
details: boolean;
changes: boolean;
wholeLine: boolean;
};
};
Expand Down
8 changes: 1 addition & 7 deletions src/currentLineController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,7 @@ export class CurrentLineController extends Disposable {
break;
}
case FileAnnotationType.Hover: {
const cfgHover = this._config.annotations.file.hover;
if (cfgHover.wholeLine) {
showStartIndex = 0;
}
else if (showStartIndex !== 0) {
showAtStart = true;
}
showStartIndex = 0;

break;
}
Expand Down

0 comments on commit c02ff46

Please sign in to comment.