Reworks git abstraction and acccess

Adds commands module
Adds git commit message to blame hover decorator
This commit is contained in:
Eric Amodio
2016-08-31 17:20:53 -04:00
parent 9964ea691b
commit 0e064f15c7
7 changed files with 181 additions and 130 deletions

44
src/commands.ts Normal file
View File

@@ -0,0 +1,44 @@
'use strict'
import {commands, Disposable, Position, Range, Uri, window} from 'vscode';
import {Commands, VsCodeCommands} from './constants';
import GitProvider from './gitProvider';
abstract class Command extends Disposable {
private _subscriptions: Disposable;
constructor(command: Commands) {
super(() => this.dispose());
this._subscriptions = commands.registerCommand(command, this.execute.bind(this));
}
dispose() {
this._subscriptions && this._subscriptions.dispose();
super.dispose();
}
abstract execute(...args): any;
}
export class BlameCommand extends Command {
constructor(private git: GitProvider) {
super(Commands.ShowBlameHistory);
}
execute(uri?: Uri, range?: Range, position?: Position) {
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
if (!uri) {
const doc = window.activeTextEditor && window.activeTextEditor.document;
if (doc) {
uri = doc.uri;
range = doc.validateRange(new Range(0, 0, 1000000, 1000000));
position = doc.validateRange(new Range(0, 0, 0, 1000000)).start;
}
if (!uri) return;
}
return this.git.getBlameLocations(uri.path, range).then(locations => {
return commands.executeCommand(VsCodeCommands.ShowReferences, uri, position, locations);
});
}
}