Files
vscode-gitlens/src/gitCodeActionProvider.ts
Eric Amodio d04696ac1d Adds code actions to open diffs
Adds context menus for toggling blame
Adds context menus for opening diffs
More refactoring and many bug fixes
2016-09-04 21:46:40 -04:00

39 lines
1.8 KiB
TypeScript

'use strict';
import {CancellationToken, CodeActionContext, CodeActionProvider, Command, DocumentSelector, ExtensionContext, Range, TextDocument, Uri, window} from 'vscode';
import {Commands, DocumentSchemes} from './constants';
import GitProvider from './gitProvider';
import {DiagnosticSource} from './constants';
export default class GitCodeActionProvider implements CodeActionProvider {
static selector: DocumentSelector = { scheme: DocumentSchemes.File };
constructor(context: ExtensionContext, private git: GitProvider) { }
provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): Command[] | Thenable<Command[]> {
if (!context.diagnostics.some(d => d.source !== DiagnosticSource)) {
return [];
}
return this.git.getBlameForLine(document.fileName, range.start.line)
.then(blame => {
const actions: Command[] = [];
if (blame.commit.sha) {
actions.push({
title: `GitLens: Diff ${blame.commit.sha} with working tree`,
command: Commands.DiffWithWorking,
arguments: [Uri.file(document.fileName), blame.commit.sha, range]
});
}
if (blame.commit.sha && blame.commit.previousSha) {
actions.push({
title: `GitLens: Diff ${blame.commit.sha} with previous ${blame.commit.previousSha}`,
command: Commands.DiffWithPrevious,
arguments: [Uri.file(document.fileName), blame.commit.sha, blame.commit.previousSha, range]
});
}
return actions;
});
}
}