From ba59fb29ad1734cc4dd65a681deae76033aa1d0d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 9 Jun 2017 11:48:33 -0400 Subject: [PATCH] Fixes #85 - Show File Commit Details doesn't work on last line if it is empty --- src/currentLineController.ts | 10 +++++----- src/gitService.ts | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/currentLineController.ts b/src/currentLineController.ts index e02e90d..a7b57f5 100644 --- a/src/currentLineController.ts +++ b/src/currentLineController.ts @@ -190,7 +190,7 @@ export class CurrentLineController extends Disposable { } if (commit !== undefined && commitLine !== undefined) { - this.show(commit, commitLine, editor); + this.show(commit, commitLine, editor, line); } else { this.clear(editor); @@ -215,12 +215,12 @@ export class CurrentLineController extends Disposable { editor.setDecorations(annotationDecoration, []); } - async show(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor) { + async show(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor, line: number) { // I have no idea why I need this protection -- but it happens if (editor.document === undefined) return; this._updateStatusBar(commit); - await this._updateAnnotations(commit, blameLine, editor); + await this._updateAnnotations(commit, blameLine, editor, line); } async showAnnotations(editor: TextEditor, type: LineAnnotationType) { @@ -247,11 +247,11 @@ export class CurrentLineController extends Disposable { await this._updateBlame(editor.selection.active.line, editor); } - private async _updateAnnotations(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor) { + private async _updateAnnotations(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor, line?: number) { const cfg = this._config.blame.line; if (!cfg.enabled) return; - const line = blameLine.line + this._uri.offset; + line = line === undefined ? blameLine.line + this._uri.offset : line; const decorationOptions: DecorationOptions[] = []; diff --git a/src/gitService.ts b/src/gitService.ts index ca77d87..1a1607e 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -423,8 +423,11 @@ export class GitService extends Disposable { const blame = await this.getBlameForFile(uri); if (blame === undefined) return undefined; - const blameLine = blame.lines[line]; - if (blameLine === undefined) return undefined; + let blameLine = blame.lines[line]; + if (blameLine === undefined) { + if (blame.lines.length !== line) return undefined; + blameLine = blame.lines[line - 1]; + } const commit = blame.commits.get(blameLine.sha); if (commit === undefined) return undefined;