This commit is contained in:
Eric Amodio
2016-11-03 03:09:33 -04:00
parent 8df6b80725
commit 409be335f9
38 changed files with 1094 additions and 520 deletions

View File

@@ -1,37 +1,31 @@
'use strict'
import {TextEditor, TextEditorEdit, Uri} from 'vscode';
'use strict';
import { TextEditor, TextEditorEdit, Uri } from 'vscode';
import BlameAnnotationController from '../blameAnnotationController';
import {EditorCommand} from './commands';
import {Commands} from '../constants';
import { EditorCommand } from './commands';
import { Commands } from '../constants';
import GitProvider from '../gitProvider';
export default class ToggleBlameCommand extends EditorCommand {
constructor(private git: GitProvider, private blameController: BlameAnnotationController) {
constructor(private git: GitProvider, private annotationController: BlameAnnotationController) {
super(Commands.ToggleBlame);
}
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string) {
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string) {
if (sha) {
return this.blameController.toggleBlameAnnotation(editor, sha);
return this.annotationController.toggleBlameAnnotation(editor, sha);
}
if (!(uri instanceof Uri)) {
if (!editor.document) return;
if (!editor.document) return undefined;
uri = editor.document.uri;
}
return this.git.getBlameForLine(uri.fsPath, editor.selection.active.line)
.then(blame => this.blameController.toggleBlameAnnotation(editor, blame && blame.commit.sha))
.catch(ex => console.error('[GitLens.ToggleBlameCommand]', `getBlameForLine(${editor.selection.active.line})`, ex));
}
}
export class ToggleCodeLensCommand extends EditorCommand {
constructor(private git: GitProvider) {
super(Commands.ToggleCodeLens);
}
execute(editor: TextEditor, edit: TextEditorEdit) {
return this.git.toggleCodeLens(editor);
try {
const blame = await this.git.getBlameForLine(uri.fsPath, editor.selection.active.line);
this.annotationController.toggleBlameAnnotation(editor, blame && blame.commit.sha);
}
catch (ex) {
console.error('[GitLens.ToggleBlameCommand]', `getBlameForLine(${editor.selection.active.line})`, ex);
}
}
}