mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-20 01:35:36 -05:00
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
'use strict'
|
|
import {TextEditor, TextEditorEdit, Uri} from 'vscode';
|
|
import BlameAnnotationController from '../blameAnnotationController';
|
|
import {EditorCommand} from './commands';
|
|
import {Commands} from '../constants';
|
|
import GitProvider from '../gitProvider';
|
|
|
|
export default class ShowBlameCommand extends EditorCommand {
|
|
constructor(private git: GitProvider, private annotationController: BlameAnnotationController) {
|
|
super(Commands.ShowBlame);
|
|
}
|
|
|
|
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string) {
|
|
if (sha) {
|
|
return this.annotationController.toggleBlameAnnotation(editor, sha);
|
|
}
|
|
|
|
if (!(uri instanceof Uri)) {
|
|
if (!editor.document) return;
|
|
uri = editor.document.uri;
|
|
}
|
|
|
|
return this.git.getBlameForLine(uri.fsPath, editor.selection.active.line)
|
|
.catch(ex => console.error('[GitLens.ShowBlameCommand]', `getBlameForLine(${editor.selection.active.line})`, ex))
|
|
.then(blame => this.annotationController.showBlameAnnotation(editor, blame && blame.commit.sha));
|
|
}
|
|
} |