Adds CodeLens for Diff'ing in blame

Other fixes and refactoring
This commit is contained in:
Eric Amodio
2016-08-31 21:15:06 -04:00
parent 0e064f15c7
commit 70cc92ddd6
9 changed files with 162 additions and 29 deletions

View File

@@ -2,6 +2,7 @@
import {commands, Disposable, Position, Range, Uri, window} from 'vscode';
import {Commands, VsCodeCommands} from './constants';
import GitProvider from './gitProvider';
import {basename} from 'path';
abstract class Command extends Disposable {
private _subscriptions: Disposable;
@@ -41,4 +42,33 @@ export class BlameCommand extends Command {
return commands.executeCommand(VsCodeCommands.ShowReferences, uri, position, locations);
});
}
}
export class DiffWithPreviousCommand extends Command {
constructor(private git: GitProvider) {
super(Commands.DiffWithPrevious);
}
execute(uri?: Uri, sha?: string, compareWithSha?: string) {
// TODO: Execute these in parallel rather than series
return this.git.getVersionedFile(uri.path, sha).then(source => {
this.git.getVersionedFile(uri.path, compareWithSha).then(compare => {
const fileName = basename(uri.path);
return commands.executeCommand(VsCodeCommands.Diff, Uri.file(source), Uri.file(compare), `${fileName} (${sha}) ↔ ${fileName} (${compareWithSha})`);
})
});
}
}
export class DiffWithWorkingCommand extends Command {
constructor(private git: GitProvider) {
super(Commands.DiffWithWorking);
}
execute(uri?: Uri, sha?: string) {
return this.git.getVersionedFile(uri.path, sha).then(compare => {
const fileName = basename(uri.path);
return commands.executeCommand(VsCodeCommands.Diff, uri, Uri.file(compare), `${fileName} (index) ↔ ${fileName} (${sha})`);
});
}
}