Increases performance of blame annotations

especially for larger file
This commit is contained in:
Eric Amodio
2017-07-28 17:09:34 -04:00
parent 9d9c3181f7
commit e10d7eb648
3 changed files with 65 additions and 19 deletions

View File

@@ -1,8 +1,9 @@
'use strict';
import { DecorationOptions, Range } from 'vscode';
import { FileAnnotationType } from './annotationController';
import { BlameAnnotationProviderBase } from './blameAnnotationProvider';
import { Annotations, endOfLineIndex } from './annotations';
import { BlameAnnotationProviderBase } from './blameAnnotationProvider';
import { GitBlameCommit } from '../gitService';
import * as moment from 'moment';
export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
@@ -13,6 +14,8 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
const blame = await this.getBlame(this._config.annotations.file.hover.heatmap.enabled);
if (blame === undefined) return false;
// console.time('Computing blame annotations...');
const cfg = this._config.annotations.file.hover;
const now = moment();
@@ -22,13 +25,16 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
const decorations: DecorationOptions[] = [];
let commit: GitBlameCommit | undefined;
let hover: DecorationOptions | undefined;
for (const l of blame.lines) {
const commit = blame.commits.get(l.sha);
commit = blame.commits.get(l.sha);
if (commit === undefined) continue;
const line = l.line + offset;
const hover = Annotations.hover(commit, renderOptions, cfg.heatmap.enabled, dateFormat);
hover = Annotations.hover(commit, renderOptions, cfg.heatmap.enabled, dateFormat);
const endIndex = cfg.wholeLine ? endOfLineIndex : this.editor.document.lineAt(line).firstNonWhitespaceCharacterIndex;
hover.range = this.editor.document.validateRange(new Range(line, 0, line, endIndex));
@@ -44,6 +50,8 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
this.editor.setDecorations(this.decoration!, decorations);
}
// console.timeEnd('Computing blame annotations...');
this.selection(shaOrLine, blame);
return true;
}