Fixes #85 - Show File Commit Details doesn't work on last line if it is empty

This commit is contained in:
Eric Amodio
2017-06-09 11:48:33 -04:00
parent 50ba3e1446
commit ba59fb29ad
2 changed files with 10 additions and 7 deletions

View File

@@ -190,7 +190,7 @@ export class CurrentLineController extends Disposable {
} }
if (commit !== undefined && commitLine !== undefined) { if (commit !== undefined && commitLine !== undefined) {
this.show(commit, commitLine, editor); this.show(commit, commitLine, editor, line);
} }
else { else {
this.clear(editor); this.clear(editor);
@@ -215,12 +215,12 @@ export class CurrentLineController extends Disposable {
editor.setDecorations(annotationDecoration, []); 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 // I have no idea why I need this protection -- but it happens
if (editor.document === undefined) return; if (editor.document === undefined) return;
this._updateStatusBar(commit); this._updateStatusBar(commit);
await this._updateAnnotations(commit, blameLine, editor); await this._updateAnnotations(commit, blameLine, editor, line);
} }
async showAnnotations(editor: TextEditor, type: LineAnnotationType) { async showAnnotations(editor: TextEditor, type: LineAnnotationType) {
@@ -247,11 +247,11 @@ export class CurrentLineController extends Disposable {
await this._updateBlame(editor.selection.active.line, editor); 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; const cfg = this._config.blame.line;
if (!cfg.enabled) return; if (!cfg.enabled) return;
const line = blameLine.line + this._uri.offset; line = line === undefined ? blameLine.line + this._uri.offset : line;
const decorationOptions: DecorationOptions[] = []; const decorationOptions: DecorationOptions[] = [];

View File

@@ -423,8 +423,11 @@ export class GitService extends Disposable {
const blame = await this.getBlameForFile(uri); const blame = await this.getBlameForFile(uri);
if (blame === undefined) return undefined; if (blame === undefined) return undefined;
const blameLine = blame.lines[line]; let blameLine = blame.lines[line];
if (blameLine === undefined) return undefined; if (blameLine === undefined) {
if (blame.lines.length !== line) return undefined;
blameLine = blame.lines[line - 1];
}
const commit = blame.commits.get(blameLine.sha); const commit = blame.commits.get(blameLine.sha);
if (commit === undefined) return undefined; if (commit === undefined) return undefined;