diff --git a/CHANGELOG.md b/CHANGELOG.md index 140fbd9..120971e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 7184bf6..2378c0f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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`) @@ -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
`left` - adds a heatmap indicator on the left edge of the gutter blame annotations
`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 diff --git a/package.json b/package.json index f4245cb..c6378e8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/annotations/blameAnnotationProvider.ts b/src/annotations/blameAnnotationProvider.ts index 6719430..74edfe1 100644 --- a/src/annotations/blameAnnotationProvider.ts +++ b/src/annotations/blameAnnotationProvider.ts @@ -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; protected _hoverProviderDisposable: Disposable; @@ -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 { - // 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 { + const commit = await this.getCommitForHover(position); if (commit === undefined) return undefined; // Get the full commit message -- since blame only returns the summary @@ -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 { + 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 { + // 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); + } } \ No newline at end of file diff --git a/src/annotations/gutterBlameAnnotationProvider.ts b/src/annotations/gutterBlameAnnotationProvider.ts index 9cfea3b..053fe5f 100644 --- a/src/annotations/gutterBlameAnnotationProvider.ts +++ b/src/annotations/gutterBlameAnnotationProvider.ts @@ -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; } diff --git a/src/annotations/hoverBlameAnnotationProvider.ts b/src/annotations/hoverBlameAnnotationProvider.ts index 493fce3..97f19f1 100644 --- a/src/annotations/hoverBlameAnnotationProvider.ts +++ b/src/annotations/hoverBlameAnnotationProvider.ts @@ -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; } diff --git a/src/configuration.ts b/src/configuration.ts index d7f5a7f..e0687d6 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -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: { @@ -267,8 +269,8 @@ export interface IConfig { format: string; dateFormat: string | null; hover: { - changes: boolean; details: boolean; + changes: boolean; wholeLine: boolean; }; }; diff --git a/src/currentLineController.ts b/src/currentLineController.ts index e7b2004..98bbb00 100644 --- a/src/currentLineController.ts +++ b/src/currentLineController.ts @@ -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; }