mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 18:48:45 -05:00
Reworks commanding structure for less redundancy
Adds command args copying when needed
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { commands, TextEditor, Uri, window } from 'vscode';
|
import { commands, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorTracker } from '../activeEditorTracker';
|
import { ActiveEditorTracker } from '../activeEditorTracker';
|
||||||
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
|
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||||
import { TextEditorComparer, UriComparer } from '../comparers';
|
import { TextEditorComparer, UriComparer } from '../comparers';
|
||||||
import { BuiltInCommands } from '../constants';
|
import { BuiltInCommands } from '../constants';
|
||||||
import { GitService } from '../gitService';
|
import { GitService } from '../gitService';
|
||||||
@@ -18,27 +18,13 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.CloseUnchangedFiles);
|
super(Commands.CloseUnchangedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(context: CommandContext, args: CloseUnchangedFilesCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: CloseUnchangedFilesCommandArgs = {}) {
|
||||||
// Since we can change the args and they could be cached -- make a copy
|
|
||||||
switch (context.type) {
|
|
||||||
case 'uri':
|
|
||||||
return this.execute(context.editor, context.uri, { ...args });
|
|
||||||
case 'scm-states':
|
|
||||||
return undefined;
|
|
||||||
case 'scm-groups':
|
|
||||||
// const group = context.scmResourceGroups[0];
|
|
||||||
// args.uris = group.resourceStates.map(_ => _.resourceUri);
|
|
||||||
return this.execute(undefined, undefined, { ...args });
|
|
||||||
default:
|
|
||||||
return this.execute(context.editor, undefined, { ...args });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async execute(editor: TextEditor | undefined, uri?: Uri, args: CloseUnchangedFilesCommandArgs = {}) {
|
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.uris === undefined) {
|
if (args.uris === undefined) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const repoPath = await this.git.getRepoPathFromUri(uri);
|
const repoPath = await this.git.getRepoPathFromUri(uri);
|
||||||
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to close unchanged files`);
|
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to close unchanged files`);
|
||||||
|
|
||||||
|
|||||||
@@ -88,28 +88,35 @@ export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {
|
|||||||
return editor.document.uri;
|
return editor.document.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScmGroupsCommandContext {
|
export interface CommandContextParsingOptions {
|
||||||
|
editor: boolean;
|
||||||
|
uri: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CommandBaseContext {
|
||||||
|
editor?: TextEditor;
|
||||||
|
uri?: Uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CommandScmGroupsContext extends CommandBaseContext {
|
||||||
type: 'scm-groups';
|
type: 'scm-groups';
|
||||||
scmResourceGroups: SourceControlResourceGroup[];
|
scmResourceGroups: SourceControlResourceGroup[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScmStatesCommandContext {
|
export interface CommandScmStatesContext extends CommandBaseContext {
|
||||||
type: 'scm-states';
|
type: 'scm-states';
|
||||||
scmResourceStates: SourceControlResourceState[];
|
scmResourceStates: SourceControlResourceState[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnknownCommandContext {
|
export interface CommandUnknownContext extends CommandBaseContext {
|
||||||
type: 'unknown';
|
type: 'unknown';
|
||||||
editor?: TextEditor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UriCommandContext {
|
export interface CommandUriContext extends CommandBaseContext {
|
||||||
type: 'uri';
|
type: 'uri';
|
||||||
editor?: TextEditor;
|
|
||||||
uri: Uri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CommandContext = ScmGroupsCommandContext | ScmStatesCommandContext | UnknownCommandContext | UriCommandContext;
|
export type CommandContext = CommandScmGroupsContext | CommandScmStatesContext | CommandUnknownContext | CommandUriContext;
|
||||||
|
|
||||||
function isScmResourceGroup(group: any): group is SourceControlResourceGroup {
|
function isScmResourceGroup(group: any): group is SourceControlResourceGroup {
|
||||||
if (group === undefined) return false;
|
if (group === undefined) return false;
|
||||||
@@ -129,16 +136,15 @@ function isTextEditor(editor: any): editor is TextEditor {
|
|||||||
return editor.id !== undefined && ((editor as TextEditor).edit !== undefined || (editor as TextEditor).document !== undefined);
|
return editor.id !== undefined && ((editor as TextEditor).edit !== undefined || (editor as TextEditor).document !== undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Command {
|
|
||||||
run?(context: CommandContext, ...args: any[]): any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export abstract class Command extends Disposable {
|
export abstract class Command extends Disposable {
|
||||||
|
|
||||||
|
protected readonly contextParsingOptions: CommandContextParsingOptions = { editor: false, uri: false };
|
||||||
|
|
||||||
private _disposable: Disposable;
|
private _disposable: Disposable;
|
||||||
|
|
||||||
constructor(protected command: Commands) {
|
constructor(protected command: Commands) {
|
||||||
super(() => this.dispose());
|
super(() => this.dispose());
|
||||||
|
|
||||||
this._disposable = commands.registerCommand(command, this._execute, this);
|
this._disposable = commands.registerCommand(command, this._execute, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,91 +152,81 @@ export abstract class Command extends Disposable {
|
|||||||
this._disposable && this._disposable.dispose();
|
this._disposable && this._disposable.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _execute(...args: any[]): any {
|
protected async preExecute(context: CommandContext, ...args: any[]): Promise<any> {
|
||||||
Telemetry.trackEvent(this.command);
|
|
||||||
|
|
||||||
if (typeof this.run === 'function') {
|
|
||||||
let editor: TextEditor | undefined = undefined;
|
|
||||||
|
|
||||||
let firstArg = args[0];
|
|
||||||
if (firstArg === undefined || isTextEditor(firstArg)) {
|
|
||||||
editor = firstArg;
|
|
||||||
args = args.slice(1);
|
|
||||||
firstArg = args[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstArg instanceof Uri) {
|
|
||||||
const [uri, ...rest] = args;
|
|
||||||
return this.run({ type: 'uri', editor: editor, uri: uri }, ...rest);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isScmResourceState(firstArg)) {
|
|
||||||
const states = [];
|
|
||||||
let count = 0;
|
|
||||||
for (const arg of args) {
|
|
||||||
if (!isScmResourceState(arg)) break;
|
|
||||||
|
|
||||||
count++;
|
|
||||||
states.push(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.run({ type: 'scm-states', scmResourceStates: states }, ...args.slice(count));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isScmResourceGroup(firstArg)) {
|
|
||||||
const groups = [];
|
|
||||||
let count = 0;
|
|
||||||
for (const arg of args) {
|
|
||||||
if (!isScmResourceGroup(arg)) break;
|
|
||||||
|
|
||||||
count++;
|
|
||||||
groups.push(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.run({ type: 'scm-groups', scmResourceGroups: groups }, ...args.slice(count));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.run({ type: 'unknown', editor: editor }, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.execute(...args);
|
return this.execute(...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract execute(...args: any[]): any;
|
abstract execute(...args: any[]): any;
|
||||||
}
|
|
||||||
|
|
||||||
export abstract class EditorCommand extends Disposable {
|
protected _execute(...args: any[]): any {
|
||||||
|
|
||||||
private _disposable: Disposable;
|
|
||||||
|
|
||||||
constructor(public readonly command: Commands) {
|
|
||||||
super(() => this.dispose());
|
|
||||||
this._disposable = commands.registerTextEditorCommand(command, this._execute, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose() {
|
|
||||||
this._disposable && this._disposable.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any {
|
|
||||||
Telemetry.trackEvent(this.command);
|
Telemetry.trackEvent(this.command);
|
||||||
return this.execute(editor, edit, ...args);
|
|
||||||
|
const [context, rest] = Command._parseContext(this.contextParsingOptions, ...args);
|
||||||
|
return this.preExecute(context, ...rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
|
private static _parseContext(options: CommandContextParsingOptions, ...args: any[]): [CommandContext, any[]] {
|
||||||
|
let editor: TextEditor | undefined = undefined;
|
||||||
|
|
||||||
|
let firstArg = args[0];
|
||||||
|
if (options.editor && (firstArg === undefined || isTextEditor(firstArg))) {
|
||||||
|
editor = firstArg;
|
||||||
|
args = args.slice(1);
|
||||||
|
firstArg = args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.uri && (firstArg === undefined || firstArg instanceof Uri)) {
|
||||||
|
const [uri, ...rest] = args as [Uri, any];
|
||||||
|
return [{ type: 'uri', editor: editor, uri: uri }, rest];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isScmResourceState(firstArg)) {
|
||||||
|
const states = [];
|
||||||
|
let count = 0;
|
||||||
|
for (const arg of args) {
|
||||||
|
if (!isScmResourceState(arg)) break;
|
||||||
|
|
||||||
|
count++;
|
||||||
|
states.push(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [{ type: 'scm-states', scmResourceStates: states, uri: states[0].resourceUri }, args.slice(count)];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isScmResourceGroup(firstArg)) {
|
||||||
|
const groups = [];
|
||||||
|
let count = 0;
|
||||||
|
for (const arg of args) {
|
||||||
|
if (!isScmResourceGroup(arg)) break;
|
||||||
|
|
||||||
|
count++;
|
||||||
|
groups.push(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [{ type: 'scm-groups', scmResourceGroups: groups }, args.slice(count)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [{ type: 'unknown', editor: editor }, args];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class ActiveEditorCommand extends Command {
|
export abstract class ActiveEditorCommand extends Command {
|
||||||
|
|
||||||
|
protected readonly contextParsingOptions: CommandContextParsingOptions = { editor: true, uri: true };
|
||||||
|
|
||||||
constructor(public readonly command: Commands) {
|
constructor(public readonly command: Commands) {
|
||||||
super(command);
|
super(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async preExecute(context: CommandContext, ...args: any[]): Promise<any> {
|
||||||
|
return this.execute(context.editor, context.uri, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
protected _execute(...args: any[]): any {
|
protected _execute(...args: any[]): any {
|
||||||
return super._execute(window.activeTextEditor, ...args);
|
return super._execute(window.activeTextEditor, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract execute(editor: TextEditor, ...args: any[]): any;
|
abstract execute(editor?: TextEditor, ...args: any[]): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastCommand: { command: string, args: any[] } | undefined = undefined;
|
let lastCommand: { command: string, args: any[] } | undefined = undefined;
|
||||||
@@ -255,6 +251,27 @@ export abstract class ActiveEditorCachedCommand extends ActiveEditorCommand {
|
|||||||
abstract execute(editor: TextEditor, ...args: any[]): any;
|
abstract execute(editor: TextEditor, ...args: any[]): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export abstract class EditorCommand extends Disposable {
|
||||||
|
|
||||||
|
private _disposable: Disposable;
|
||||||
|
|
||||||
|
constructor(public readonly command: Commands) {
|
||||||
|
super(() => this.dispose());
|
||||||
|
this._disposable = commands.registerTextEditorCommand(command, this._execute, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
this._disposable && this._disposable.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any {
|
||||||
|
Telemetry.trackEvent(this.command);
|
||||||
|
return this.execute(editor, edit, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
|
||||||
|
}
|
||||||
|
|
||||||
export async function openEditor(uri: Uri, options?: TextDocumentShowOptions): Promise<TextEditor | undefined> {
|
export async function openEditor(uri: Uri, options?: TextDocumentShowOptions): Promise<TextEditor | undefined> {
|
||||||
try {
|
try {
|
||||||
const defaults: TextDocumentShowOptions = {
|
const defaults: TextDocumentShowOptions = {
|
||||||
|
|||||||
@@ -17,10 +17,12 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.CopyMessageToClipboard);
|
super(Commands.CopyMessageToClipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: CopyMessageToClipboardCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: CopyMessageToClipboardCommandArgs = {}): Promise<any> {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
// If we don't have an editor then get the message of the last commit to the branch
|
// If we don't have an editor then get the message of the last commit to the branch
|
||||||
if (uri === undefined) {
|
if (uri === undefined) {
|
||||||
if (!this.git.repoPath) return undefined;
|
if (!this.git.repoPath) return undefined;
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.CopyShaToClipboard);
|
super(Commands.CopyShaToClipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: CopyShaToClipboardCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: CopyShaToClipboardCommandArgs = {}): Promise<any> {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
// If we don't have an editor then get the sha of the last commit to the branch
|
// If we don't have an editor then get the sha of the last commit to the branch
|
||||||
if (uri === undefined) {
|
if (uri === undefined) {
|
||||||
if (!this.git.repoPath) return undefined;
|
if (!this.git.repoPath) return undefined;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffDirectory);
|
super(Commands.DiffDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: DiffDirectoryCommandCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffDirectoryCommandCommandArgs = {}): Promise<any> {
|
||||||
const diffTool = await this.git.getConfig('diff.tool');
|
const diffTool = await this.git.getConfig('diff.tool');
|
||||||
if (!diffTool) {
|
if (!diffTool) {
|
||||||
const result = await window.showWarningMessage(`Unable to open directory compare because there is no Git diff tool configured`, 'View Git Docs');
|
const result = await window.showWarningMessage(`Unable to open directory compare because there is no Git diff tool configured`, 'View Git Docs');
|
||||||
@@ -35,6 +35,8 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
|
|||||||
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open directory compare`);
|
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open directory compare`);
|
||||||
|
|
||||||
if (!args.shaOrBranch1) {
|
if (!args.shaOrBranch1) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const branches = await this.git.getBranches(repoPath);
|
const branches = await this.git.getBranches(repoPath);
|
||||||
const current = Iterables.find(branches, _ => _.current);
|
const current = Iterables.find(branches, _ => _.current);
|
||||||
if (current == null) return window.showWarningMessage(`Unable to open directory compare`);
|
if (current == null) return window.showWarningMessage(`Unable to open directory compare`);
|
||||||
|
|||||||
@@ -21,12 +21,16 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffLineWithPrevious);
|
super(Commands.DiffLineWithPrevious);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: DiffLineWithPreviousCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffLineWithPreviousCommandArgs = {}): Promise<any> {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||||
args.line = args.line || (editor === undefined ? gitUri.offset : editor.selection.active.line);
|
|
||||||
|
args = { ...args };
|
||||||
|
if (args.line === undefined) {
|
||||||
|
args.line = editor === undefined ? gitUri.offset : editor.selection.active.line;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.commit === undefined || GitService.isUncommitted(args.commit.sha)) {
|
if (args.commit === undefined || GitService.isUncommitted(args.commit.sha)) {
|
||||||
if (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
if (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
||||||
|
|||||||
@@ -18,12 +18,16 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffLineWithWorking);
|
super(Commands.DiffLineWithWorking);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: DiffLineWithWorkingCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffLineWithWorkingCommandArgs = {}): Promise<any> {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||||
args.line = args.line || (editor === undefined ? gitUri.offset : editor.selection.active.line);
|
|
||||||
|
args = { ...args };
|
||||||
|
if (args.line === undefined) {
|
||||||
|
args.line = editor === undefined ? gitUri.offset : editor.selection.active.line;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.commit === undefined || GitService.isUncommitted(args.commit.sha)) {
|
if (args.commit === undefined || GitService.isUncommitted(args.commit.sha)) {
|
||||||
if (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
if (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
|
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||||
import { BuiltInCommands, GlyphChars } from '../constants';
|
import { BuiltInCommands, GlyphChars } from '../constants';
|
||||||
import { GitService, GitUri } from '../gitService';
|
import { GitService, GitUri } from '../gitService';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@@ -21,25 +21,11 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffWithBranch);
|
super(Commands.DiffWithBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(context: CommandContext, args: DiffWithBranchCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithBranchCommandArgs = {}): Promise<any> {
|
||||||
// Since we can change the args and they could be cached -- make a copy
|
|
||||||
switch (context.type) {
|
|
||||||
case 'uri':
|
|
||||||
return this.execute(context.editor, context.uri, { ...args });
|
|
||||||
case 'scm-states':
|
|
||||||
const resource = context.scmResourceStates[0];
|
|
||||||
return this.execute(undefined, resource.resourceUri, { ...args });
|
|
||||||
case 'scm-groups':
|
|
||||||
return undefined;
|
|
||||||
default:
|
|
||||||
return this.execute(context.editor, undefined, { ...args });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async execute(editor: TextEditor | undefined, uri?: Uri, args: DiffWithBranchCommandArgs = {}): Promise<any> {
|
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.line === undefined) {
|
if (args.line === undefined) {
|
||||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffWithNext);
|
super(Commands.DiffWithNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: DiffWithNextCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithNextCommandArgs = {}): Promise<any> {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.line === undefined) {
|
if (args.line === undefined) {
|
||||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables } from '../system';
|
import { Iterables } from '../system';
|
||||||
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
|
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||||
import { BuiltInCommands, GlyphChars } from '../constants';
|
import { BuiltInCommands, GlyphChars } from '../constants';
|
||||||
import { DiffWithWorkingCommandArgs } from './diffWithWorking';
|
import { DiffWithWorkingCommandArgs } from './diffWithWorking';
|
||||||
import { GitCommit, GitService, GitUri } from '../gitService';
|
import { GitCommit, GitService, GitUri } from '../gitService';
|
||||||
@@ -22,25 +22,11 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffWithPrevious);
|
super(Commands.DiffWithPrevious);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(context: CommandContext, args: DiffWithPreviousCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithPreviousCommandArgs = {}): Promise<any> {
|
||||||
// Since we can change the args and they could be cached -- make a copy
|
|
||||||
switch (context.type) {
|
|
||||||
case 'uri':
|
|
||||||
return this.execute(context.editor, context.uri, { ...args });
|
|
||||||
case 'scm-states':
|
|
||||||
const resource = context.scmResourceStates[0];
|
|
||||||
return this.execute(undefined, resource.resourceUri, { ...args });
|
|
||||||
case 'scm-groups':
|
|
||||||
return undefined;
|
|
||||||
default:
|
|
||||||
return this.execute(context.editor, undefined, { ...args });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async execute(editor: TextEditor | undefined, uri?: Uri, args: DiffWithPreviousCommandArgs = {}): Promise<any> {
|
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.line === undefined) {
|
if (args.line === undefined) {
|
||||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
|
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||||
import { BuiltInCommands, GlyphChars } from '../constants';
|
import { BuiltInCommands, GlyphChars } from '../constants';
|
||||||
import { GitService, GitUri } from '../gitService';
|
import { GitService, GitUri } from '../gitService';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@@ -20,25 +20,11 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffWithRevision);
|
super(Commands.DiffWithRevision);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(context: CommandContext, args: DiffWithRevisionCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithRevisionCommandArgs = {}): Promise<any> {
|
||||||
// Since we can change the args and they could be cached -- make a copy
|
|
||||||
switch (context.type) {
|
|
||||||
case 'uri':
|
|
||||||
return this.execute(context.editor, context.uri, { ...args });
|
|
||||||
case 'scm-states':
|
|
||||||
const resource = context.scmResourceStates[0];
|
|
||||||
return this.execute(undefined, resource.resourceUri, { ...args });
|
|
||||||
case 'scm-groups':
|
|
||||||
return undefined;
|
|
||||||
default:
|
|
||||||
return this.execute(context.editor, undefined, { ...args });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async execute(editor: TextEditor | undefined, uri?: Uri, args: DiffWithRevisionCommandArgs = {}): Promise<any> {
|
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.line === undefined) {
|
if (args.line === undefined) {
|
||||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.DiffWithWorking);
|
super(Commands.DiffWithWorking);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: DiffWithWorkingCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithWorkingCommandArgs = {}): Promise<any> {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.line === undefined) {
|
if (args.line === undefined) {
|
||||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.OpenBranchInRemote);
|
super(Commands.OpenBranchInRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: OpenBranchInRemoteCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: OpenBranchInRemoteCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||||
@@ -28,6 +28,8 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.branch === undefined) {
|
if (args.branch === undefined) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const branches = await this.git.getBranches(repoPath);
|
const branches = await this.git.getBranches(repoPath);
|
||||||
|
|
||||||
const pick = await BranchesQuickPick.show(branches, `Show history for branch${GlyphChars.Ellipsis}`);
|
const pick = await BranchesQuickPick.show(branches, `Show history for branch${GlyphChars.Ellipsis}`);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, openEditor } from './common';
|
import { ActiveEditorCommand, Commands, getCommandUri, openEditor } from './common';
|
||||||
import { GitService } from '../gitService';
|
import { GitService } from '../gitService';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { Messages } from '../messages';
|
import { Messages } from '../messages';
|
||||||
@@ -15,27 +15,13 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.OpenChangedFiles);
|
super(Commands.OpenChangedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(context: CommandContext, args: OpenChangedFilesCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: OpenChangedFilesCommandArgs = {}) {
|
||||||
// Since we can change the args and they could be cached -- make a copy
|
|
||||||
switch (context.type) {
|
|
||||||
case 'uri':
|
|
||||||
return this.execute(context.editor, context.uri, { ...args });
|
|
||||||
case 'scm-states':
|
|
||||||
return undefined;
|
|
||||||
case 'scm-groups':
|
|
||||||
// const group = context.scmResourceGroups[0];
|
|
||||||
// args.uris = group.resourceStates.map(_ => _.resourceUri);
|
|
||||||
return this.execute(undefined, undefined, { ...args });
|
|
||||||
default:
|
|
||||||
return this.execute(context.editor, undefined, { ...args });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async execute(editor: TextEditor | undefined, uri?: Uri, args: OpenChangedFilesCommandArgs = {}) {
|
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.uris === undefined) {
|
if (args.uris === undefined) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const repoPath = await this.git.getRepoPathFromUri(uri);
|
const repoPath = await this.git.getRepoPathFromUri(uri);
|
||||||
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open changed files`);
|
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open changed files`);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.OpenCommitInRemote);
|
super(Commands.OpenCommitInRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri) {
|
async execute(editor?: TextEditor, uri?: Uri) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
if (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
if (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Arrays } from '../system';
|
import { Arrays } from '../system';
|
||||||
import { commands, Range, TextEditor, Uri, window } from 'vscode';
|
import { commands, Range, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
|
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||||
import { GitService, GitUri } from '../gitService';
|
import { GitService, GitUri } from '../gitService';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { OpenInRemoteCommandArgs } from './openInRemote';
|
import { OpenInRemoteCommandArgs } from './openInRemote';
|
||||||
@@ -12,21 +12,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.OpenFileInRemote);
|
super(Commands.OpenFileInRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(context: CommandContext): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri) {
|
||||||
switch (context.type) {
|
|
||||||
case 'uri':
|
|
||||||
return this.execute(context.editor, context.uri);
|
|
||||||
case 'scm-states':
|
|
||||||
const resource = context.scmResourceStates[0];
|
|
||||||
return this.execute(undefined, resource.resourceUri);
|
|
||||||
case 'scm-groups':
|
|
||||||
return undefined;
|
|
||||||
default:
|
|
||||||
return this.execute(context.editor, undefined);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async execute(editor: TextEditor | undefined, uri?: Uri) {
|
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ export class OpenInRemoteCommand extends ActiveEditorCommand {
|
|||||||
async execute(editor: TextEditor, uri?: Uri, args: OpenInRemoteCommandArgs = {}) {
|
async execute(editor: TextEditor, uri?: Uri, args: OpenInRemoteCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
args = { ...args };
|
||||||
if (args.remotes === undefined || args.resource === undefined) return undefined;
|
if (args.remotes === undefined || args.resource === undefined) return undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
if (args.remotes.length === 1) {
|
if (args.remotes.length === 1) {
|
||||||
const command = new OpenRemoteCommandQuickPickItem(args.remotes[0], args.resource);
|
const command = new OpenRemoteCommandQuickPickItem(args.remotes[0], args.resource);
|
||||||
return command.execute();
|
return command.execute();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand {
|
|||||||
super(Commands.OpenRepoInRemote);
|
super(Commands.OpenRepoInRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri) {
|
async execute(editor?: TextEditor, uri?: Uri) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export class ShowBlameHistoryCommand extends EditorCommand {
|
|||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
if (args.range == null || args.position == null) {
|
if (args.range == null || args.position == null) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
|
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
|
||||||
args.range = editor.document.validateRange(new Range(0, 0, 1000000, 1000000));
|
args.range = editor.document.validateRange(new Range(0, 0, 1000000, 1000000));
|
||||||
args.position = editor.document.validateRange(new Range(0, 0, 0, 1000000)).start;
|
args.position = editor.document.validateRange(new Range(0, 0, 0, 1000000)).start;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
|
|||||||
super(Commands.ShowCommitSearch);
|
super(Commands.ShowCommitSearch);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: ShowCommitSearchCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowCommitSearchCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
const gitUri = uri === undefined ? undefined : await GitUri.fromUri(uri, this.git);
|
const gitUri = uri === undefined ? undefined : await GitUri.fromUri(uri, this.git);
|
||||||
@@ -38,6 +38,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
|
|||||||
const repoPath = gitUri === undefined ? this.git.repoPath : gitUri.repoPath;
|
const repoPath = gitUri === undefined ? this.git.repoPath : gitUri.repoPath;
|
||||||
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show commit search`);
|
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show commit search`);
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (!args.search || args.searchBy == null) {
|
if (!args.search || args.searchBy == null) {
|
||||||
try {
|
try {
|
||||||
if (!args.search) {
|
if (!args.search) {
|
||||||
@@ -95,14 +96,17 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
|
|||||||
originalSearch = `@${args.search}`;
|
originalSearch = `@${args.search}`;
|
||||||
placeHolder = `commits with author matching '${args.search}'`;
|
placeHolder = `commits with author matching '${args.search}'`;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GitRepoSearchBy.Files:
|
case GitRepoSearchBy.Files:
|
||||||
originalSearch = `:${args.search}`;
|
originalSearch = `:${args.search}`;
|
||||||
placeHolder = `commits with files matching '${args.search}'`;
|
placeHolder = `commits with files matching '${args.search}'`;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GitRepoSearchBy.Message:
|
case GitRepoSearchBy.Message:
|
||||||
originalSearch = args.search;
|
originalSearch = args.search;
|
||||||
placeHolder = `commits with message matching '${args.search}'`;
|
placeHolder = `commits with message matching '${args.search}'`;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GitRepoSearchBy.Sha:
|
case GitRepoSearchBy.Sha:
|
||||||
originalSearch = `#${args.search}`;
|
originalSearch = `#${args.search}`;
|
||||||
placeHolder = `commits with id matching '${args.search}'`;
|
placeHolder = `commits with id matching '${args.search}'`;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ export class ShowFileBlameCommand extends EditorCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.type === undefined) {
|
if (args.type === undefined) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||||
args.type = cfg.blame.file.annotationType;
|
args.type = cfg.blame.file.annotationType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ export class ShowFileHistoryCommand extends EditorCommand {
|
|||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
if (args.position == null) {
|
if (args.position == null) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
|
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
|
||||||
args.position = editor.document.validateRange(new Range(0, 0, 0, 1000000)).start;
|
args.position = editor.document.validateRange(new Range(0, 0, 0, 1000000)).start;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class ShowLastQuickPickCommand extends Command {
|
|||||||
|
|
||||||
async execute() {
|
async execute() {
|
||||||
const command = getLastCommand();
|
const command = getLastCommand();
|
||||||
if (!command) return undefined;
|
if (command === undefined) return undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return commands.executeCommand(command.command, ...command.args);
|
return commands.executeCommand(command.command, ...command.args);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ export class ShowLineBlameCommand extends EditorCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.type === undefined) {
|
if (args.type === undefined) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||||
args.type = cfg.blame.line.annotationType;
|
args.type = cfg.blame.line.annotationType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
|
|||||||
super(Commands.ShowQuickBranchHistory);
|
super(Commands.ShowQuickBranchHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickBranchHistoryCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickBranchHistoryCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.maxCount == null) {
|
if (args.maxCount == null) {
|
||||||
args.maxCount = this.git.config.advanced.maxQuickHistory;
|
args.maxCount = this.git.config.advanced.maxQuickHistory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
|
|||||||
super(Commands.ShowQuickCommitDetails);
|
super(Commands.ShowQuickCommitDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickCommitDetailsCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitDetailsCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
|
|||||||
let repoPath = gitUri.repoPath;
|
let repoPath = gitUri.repoPath;
|
||||||
let workingFileName = path.relative(repoPath || '', gitUri.fsPath);
|
let workingFileName = path.relative(repoPath || '', gitUri.fsPath);
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.sha === undefined) {
|
if (args.sha === undefined) {
|
||||||
if (editor === undefined) return undefined;
|
if (editor === undefined) return undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
|
|||||||
super(Commands.ShowQuickCommitFileDetails);
|
super(Commands.ShowQuickCommitFileDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickCommitFileDetailsCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitFileDetailsCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return undefined;
|
if (uri === undefined) return undefined;
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
|
|||||||
|
|
||||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.sha === undefined) {
|
if (args.sha === undefined) {
|
||||||
if (editor === undefined) return undefined;
|
if (editor === undefined) return undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedComm
|
|||||||
super(Commands.ShowQuickCurrentBranchHistory);
|
super(Commands.ShowQuickCurrentBranchHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickCurrentBranchHistoryCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCurrentBranchHistoryCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Strings } from '../system';
|
import { Strings } from '../system';
|
||||||
import { commands, Range, TextEditor, Uri, window } from 'vscode';
|
import { commands, Range, TextEditor, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCachedCommand, CommandContext, Commands, getCommandUri } from './common';
|
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
|
||||||
import { GlyphChars } from '../constants';
|
import { GlyphChars } from '../constants';
|
||||||
import { GitLog, GitService, GitUri } from '../gitService';
|
import { GitLog, GitService, GitUri } from '../gitService';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@@ -25,27 +25,13 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
|
|||||||
super(Commands.ShowQuickFileHistory);
|
super(Commands.ShowQuickFileHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(context: CommandContext, args: ShowQuickFileHistoryCommandArgs = {}): Promise<any> {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) {
|
||||||
// Since we can change the args and they could be cached -- make a copy
|
|
||||||
switch (context.type) {
|
|
||||||
case 'uri':
|
|
||||||
return this.execute(context.editor, context.uri, { ...args });
|
|
||||||
case 'scm-states':
|
|
||||||
const resource = context.scmResourceStates[0];
|
|
||||||
return this.execute(undefined, resource.resourceUri, { ...args });
|
|
||||||
case 'scm-groups':
|
|
||||||
return undefined;
|
|
||||||
default:
|
|
||||||
return this.execute(context.editor, undefined, { ...args });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async execute(editor: TextEditor | undefined, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) {
|
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);
|
if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);
|
||||||
|
|
||||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.maxCount == null) {
|
if (args.maxCount == null) {
|
||||||
args.maxCount = this.git.config.advanced.maxQuickHistory;
|
args.maxCount = this.git.config.advanced.maxQuickHistory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand {
|
|||||||
super(Commands.ShowQuickRepoStatus);
|
super(Commands.ShowQuickRepoStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickRepoStatusCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickRepoStatusCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
|
|||||||
super(Commands.ShowQuickStashList);
|
super(Commands.ShowQuickStashList);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickStashListCommandArgs = {}) {
|
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickStashListCommandArgs = {}) {
|
||||||
uri = getCommandUri(uri, editor);
|
uri = getCommandUri(uri, editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export class StashApplyCommand extends Command {
|
|||||||
async execute(args: StashApplyCommandArgs = { confirm: true, deleteAfter: false }) {
|
async execute(args: StashApplyCommandArgs = { confirm: true, deleteAfter: false }) {
|
||||||
if (!this.git.repoPath) return undefined;
|
if (!this.git.repoPath) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.stashItem === undefined || args.stashItem.stashName === undefined) {
|
if (args.stashItem === undefined || args.stashItem.stashName === undefined) {
|
||||||
const stash = await this.git.getStashList(this.git.repoPath);
|
const stash = await this.git.getStashList(this.git.repoPath);
|
||||||
if (stash === undefined) return window.showInformationMessage(`There are no stashed changes`);
|
if (stash === undefined) return window.showInformationMessage(`There are no stashed changes`);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export class StashDeleteCommand extends Command {
|
|||||||
async execute(args: StashDeleteCommandArgs = { confirm: true }) {
|
async execute(args: StashDeleteCommandArgs = { confirm: true }) {
|
||||||
if (!this.git.repoPath) return undefined;
|
if (!this.git.repoPath) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.stashItem === undefined || args.stashItem.stashName === undefined) return undefined;
|
if (args.stashItem === undefined || args.stashItem.stashName === undefined) return undefined;
|
||||||
|
|
||||||
if (args.confirm === undefined) {
|
if (args.confirm === undefined) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class StashSaveCommand extends Command {
|
|||||||
async execute(args: StashSaveCommandArgs = { unstagedOnly : false }) {
|
async execute(args: StashSaveCommandArgs = { unstagedOnly : false }) {
|
||||||
if (!this.git.repoPath) return undefined;
|
if (!this.git.repoPath) return undefined;
|
||||||
|
|
||||||
|
args = { ...args };
|
||||||
if (args.unstagedOnly === undefined) {
|
if (args.unstagedOnly === undefined) {
|
||||||
args.unstagedOnly = false;
|
args.unstagedOnly = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ export class ToggleFileBlameCommand extends EditorCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.type === undefined) {
|
if (args.type === undefined) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||||
args.type = cfg.blame.file.annotationType;
|
args.type = cfg.blame.file.annotationType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ export class ToggleLineBlameCommand extends EditorCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (args.type === undefined) {
|
if (args.type === undefined) {
|
||||||
|
args = { ...args };
|
||||||
|
|
||||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||||
args.type = cfg.blame.line.annotationType;
|
args.type = cfg.blame.line.annotationType;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user