mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-12 19:18:32 -05:00
Closes #116 - adds full commit msg to annotations
Switches to use HoverProvider for hovers in file blames
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { DecorationOptions, Range } from 'vscode';
|
||||
import { FileAnnotationType } from './annotationController';
|
||||
import { Annotations, endOfLineIndex } from './annotations';
|
||||
import { Annotations } from './annotations';
|
||||
import { BlameAnnotationProviderBase } from './blameAnnotationProvider';
|
||||
import { GitBlameCommit } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
@@ -11,80 +11,60 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
|
||||
async provideAnnotation(shaOrLine?: string | number): Promise<boolean> {
|
||||
this.annotationType = FileAnnotationType.Hover;
|
||||
|
||||
const blame = await this.getBlame(this._config.annotations.file.hover.heatmap.enabled);
|
||||
if (blame === undefined) return false;
|
||||
|
||||
const start = process.hrtime();
|
||||
|
||||
const cfg = this._config.annotations.file.hover;
|
||||
|
||||
const now = Date.now();
|
||||
const offset = this.uri.offset;
|
||||
const renderOptions = Annotations.hoverRenderOptions(this._config.theme, cfg.heatmap);
|
||||
const dateFormat = this._config.defaultDateFormat;
|
||||
const blame = await this.getBlame(cfg.heatmap.enabled);
|
||||
if (blame === undefined) return false;
|
||||
|
||||
const decorations: DecorationOptions[] = [];
|
||||
const decorationsMap: { [sha: string]: DecorationOptions } = Object.create(null);
|
||||
const document = this.document;
|
||||
if (cfg.heatmap.enabled) {
|
||||
const start = process.hrtime();
|
||||
|
||||
let commit: GitBlameCommit | undefined;
|
||||
let hasRemotes: boolean | undefined;
|
||||
let hover: DecorationOptions | undefined;
|
||||
const now = Date.now();
|
||||
const offset = this.uri.offset;
|
||||
const renderOptions = Annotations.hoverRenderOptions(this._config.theme, cfg.heatmap);
|
||||
|
||||
for (const l of blame.lines) {
|
||||
const line = l.line + offset;
|
||||
const decorations: DecorationOptions[] = [];
|
||||
const decorationsMap: { [sha: string]: DecorationOptions } = Object.create(null);
|
||||
|
||||
hover = decorationsMap[l.sha];
|
||||
let commit: GitBlameCommit | undefined;
|
||||
let hover: DecorationOptions | undefined;
|
||||
|
||||
if (hover !== undefined) {
|
||||
hover = { ...hover } as DecorationOptions;
|
||||
for (const l of blame.lines) {
|
||||
const line = l.line + offset;
|
||||
|
||||
if (cfg.wholeLine) {
|
||||
hover.range = document.validateRange(new Range(line, 0, line, endOfLineIndex));
|
||||
}
|
||||
else {
|
||||
const endIndex = document.lineAt(line).firstNonWhitespaceCharacterIndex;
|
||||
hover.range = new Range(line, 0, line, endIndex);
|
||||
hover = decorationsMap[l.sha];
|
||||
|
||||
if (hover !== undefined) {
|
||||
hover = {
|
||||
...hover,
|
||||
range: new Range(line, 0, line, 0)
|
||||
} as DecorationOptions;
|
||||
|
||||
decorations.push(hover);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
commit = blame.commits.get(l.sha);
|
||||
if (commit === undefined) continue;
|
||||
|
||||
hover = Annotations.hover(commit, renderOptions, now);
|
||||
hover.range = new Range(line, 0, line, 0);
|
||||
|
||||
decorations.push(hover);
|
||||
decorationsMap[l.sha] = hover;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
commit = blame.commits.get(l.sha);
|
||||
if (commit === undefined) continue;
|
||||
|
||||
if (hasRemotes === undefined) {
|
||||
hasRemotes = this.git.hasRemotes(commit.repoPath);
|
||||
if (decorations.length) {
|
||||
this.editor.setDecorations(this.decoration!, decorations);
|
||||
}
|
||||
|
||||
hover = Annotations.hover(commit, renderOptions, cfg.heatmap.enabled, dateFormat, hasRemotes);
|
||||
|
||||
if (cfg.wholeLine) {
|
||||
hover.range = document.validateRange(new Range(line, 0, line, endOfLineIndex));
|
||||
}
|
||||
else {
|
||||
const endIndex = document.lineAt(line).firstNonWhitespaceCharacterIndex;
|
||||
hover.range = new Range(line, 0, line, endIndex);
|
||||
}
|
||||
|
||||
if (cfg.heatmap.enabled) {
|
||||
Annotations.applyHeatmap(hover, commit.date, now);
|
||||
}
|
||||
|
||||
decorations.push(hover);
|
||||
decorationsMap[l.sha] = hover;
|
||||
|
||||
const duration = process.hrtime(start);
|
||||
Logger.log(`${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms to compute hover blame annotations`);
|
||||
}
|
||||
|
||||
if (decorations.length) {
|
||||
this.editor.setDecorations(this.decoration!, decorations);
|
||||
}
|
||||
|
||||
const duration = process.hrtime(start);
|
||||
Logger.log(`${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms to compute hover blame annotations`);
|
||||
|
||||
this.registerHoverProvider();
|
||||
this.selection(shaOrLine, blame);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user