mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-25 09:35:40 -05:00
Adds context menus for toggling blame Adds context menus for opening diffs More refactoring and many bug fixes
39 lines
1.8 KiB
TypeScript
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;
|
|
});
|
|
}
|
|
} |