mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-25 09:35:40 -05:00
Adds code actions to open diffs
Adds context menus for toggling blame Adds context menus for opening diffs More refactoring and many bug fixes
This commit is contained in:
39
src/gitCodeActionProvider.ts
Normal file
39
src/gitCodeActionProvider.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
'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;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user