mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-15 17:25:33 -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';
|
||||
import { commands, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorTracker } from '../activeEditorTracker';
|
||||
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
|
||||
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||
import { TextEditorComparer, UriComparer } from '../comparers';
|
||||
import { BuiltInCommands } from '../constants';
|
||||
import { GitService } from '../gitService';
|
||||
@@ -18,27 +18,13 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
|
||||
super(Commands.CloseUnchangedFiles);
|
||||
}
|
||||
|
||||
async run(context: CommandContext, args: CloseUnchangedFilesCommandArgs = {}): 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':
|
||||
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 = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: CloseUnchangedFilesCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
try {
|
||||
if (args.uris === undefined) {
|
||||
args = { ...args };
|
||||
|
||||
const repoPath = await this.git.getRepoPathFromUri(uri);
|
||||
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;
|
||||
}
|
||||
|
||||
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';
|
||||
scmResourceGroups: SourceControlResourceGroup[];
|
||||
}
|
||||
|
||||
export interface ScmStatesCommandContext {
|
||||
export interface CommandScmStatesContext extends CommandBaseContext {
|
||||
type: 'scm-states';
|
||||
scmResourceStates: SourceControlResourceState[];
|
||||
}
|
||||
|
||||
export interface UnknownCommandContext {
|
||||
export interface CommandUnknownContext extends CommandBaseContext {
|
||||
type: 'unknown';
|
||||
editor?: TextEditor;
|
||||
}
|
||||
|
||||
export interface UriCommandContext {
|
||||
export interface CommandUriContext extends CommandBaseContext {
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
|
||||
export interface Command {
|
||||
run?(context: CommandContext, ...args: any[]): any;
|
||||
}
|
||||
|
||||
export abstract class Command extends Disposable {
|
||||
|
||||
protected readonly contextParsingOptions: CommandContextParsingOptions = { editor: false, uri: false };
|
||||
|
||||
private _disposable: Disposable;
|
||||
|
||||
constructor(protected command: Commands) {
|
||||
super(() => this.dispose());
|
||||
|
||||
this._disposable = commands.registerCommand(command, this._execute, this);
|
||||
}
|
||||
|
||||
@@ -146,91 +152,81 @@ export abstract class Command extends Disposable {
|
||||
this._disposable && this._disposable.dispose();
|
||||
}
|
||||
|
||||
protected _execute(...args: any[]): 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);
|
||||
}
|
||||
|
||||
protected async preExecute(context: CommandContext, ...args: any[]): Promise<any> {
|
||||
return this.execute(...args);
|
||||
}
|
||||
|
||||
abstract execute(...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 {
|
||||
protected _execute(...args: any[]): any {
|
||||
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 {
|
||||
|
||||
protected readonly contextParsingOptions: CommandContextParsingOptions = { editor: true, uri: true };
|
||||
|
||||
constructor(public readonly command: Commands) {
|
||||
super(command);
|
||||
}
|
||||
|
||||
protected async preExecute(context: CommandContext, ...args: any[]): Promise<any> {
|
||||
return this.execute(context.editor, context.uri, ...args);
|
||||
}
|
||||
|
||||
protected _execute(...args: any[]): any {
|
||||
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;
|
||||
@@ -255,6 +251,27 @@ export abstract class ActiveEditorCachedCommand extends ActiveEditorCommand {
|
||||
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> {
|
||||
try {
|
||||
const defaults: TextDocumentShowOptions = {
|
||||
|
||||
@@ -17,10 +17,12 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
|
||||
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);
|
||||
|
||||
try {
|
||||
args = { ...args };
|
||||
|
||||
// If we don't have an editor then get the message of the last commit to the branch
|
||||
if (uri === undefined) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
@@ -16,10 +16,12 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
|
||||
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);
|
||||
|
||||
try {
|
||||
args = { ...args };
|
||||
|
||||
// If we don't have an editor then get the sha of the last commit to the branch
|
||||
if (uri === undefined) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
@@ -19,7 +19,7 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
|
||||
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');
|
||||
if (!diffTool) {
|
||||
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 (!args.shaOrBranch1) {
|
||||
args = { ...args };
|
||||
|
||||
const branches = await this.git.getBranches(repoPath);
|
||||
const current = Iterables.find(branches, _ => _.current);
|
||||
if (current == null) return window.showWarningMessage(`Unable to open directory compare`);
|
||||
|
||||
@@ -21,12 +21,16 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
|
||||
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);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
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 (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
||||
|
||||
@@ -18,12 +18,16 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
|
||||
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);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
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 (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
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 { GitService, GitUri } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
@@ -21,25 +21,11 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
|
||||
super(Commands.DiffWithBranch);
|
||||
}
|
||||
|
||||
async run(context: CommandContext, 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> {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithBranchCommandArgs = {}): Promise<any> {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.line === undefined) {
|
||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
|
||||
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);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.line === undefined) {
|
||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
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 { DiffWithWorkingCommandArgs } from './diffWithWorking';
|
||||
import { GitCommit, GitService, GitUri } from '../gitService';
|
||||
@@ -22,25 +22,11 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
|
||||
super(Commands.DiffWithPrevious);
|
||||
}
|
||||
|
||||
async run(context: CommandContext, 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> {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithPreviousCommandArgs = {}): Promise<any> {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.line === undefined) {
|
||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
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 { GitService, GitUri } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
@@ -20,25 +20,11 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
|
||||
super(Commands.DiffWithRevision);
|
||||
}
|
||||
|
||||
async run(context: CommandContext, 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> {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: DiffWithRevisionCommandArgs = {}): Promise<any> {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.line === undefined) {
|
||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||
}
|
||||
|
||||
@@ -19,10 +19,11 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
|
||||
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);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.line === undefined) {
|
||||
args.line = editor === undefined ? 0 : editor.selection.active.line;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
|
||||
super(Commands.OpenBranchInRemote);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: OpenBranchInRemoteCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: OpenBranchInRemoteCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||
@@ -28,6 +28,8 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
|
||||
|
||||
try {
|
||||
if (args.branch === undefined) {
|
||||
args = { ...args };
|
||||
|
||||
const branches = await this.git.getBranches(repoPath);
|
||||
|
||||
const pick = await BranchesQuickPick.show(branches, `Show history for branch${GlyphChars.Ellipsis}`);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
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 { Logger } from '../logger';
|
||||
import { Messages } from '../messages';
|
||||
@@ -15,27 +15,13 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand {
|
||||
super(Commands.OpenChangedFiles);
|
||||
}
|
||||
|
||||
async run(context: CommandContext, args: OpenChangedFilesCommandArgs = {}): 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':
|
||||
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 = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: OpenChangedFilesCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
try {
|
||||
if (args.uris === undefined) {
|
||||
args = { ...args };
|
||||
|
||||
const repoPath = await this.git.getRepoPathFromUri(uri);
|
||||
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open changed files`);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
|
||||
super(Commands.OpenCommitInRemote);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri) {
|
||||
async execute(editor?: TextEditor, uri?: Uri) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return undefined;
|
||||
if (editor !== undefined && editor.document !== undefined && editor.document.isDirty) return undefined;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { Arrays } from '../system';
|
||||
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 { Logger } from '../logger';
|
||||
import { OpenInRemoteCommandArgs } from './openInRemote';
|
||||
@@ -12,21 +12,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
|
||||
super(Commands.OpenFileInRemote);
|
||||
}
|
||||
|
||||
async run(context: CommandContext): Promise<any> {
|
||||
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) {
|
||||
async execute(editor?: TextEditor, uri?: Uri) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
|
||||
@@ -23,9 +23,10 @@ export class OpenInRemoteCommand extends ActiveEditorCommand {
|
||||
async execute(editor: TextEditor, uri?: Uri, args: OpenInRemoteCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
try {
|
||||
if (args.remotes === undefined || args.resource === undefined) return undefined;
|
||||
args = { ...args };
|
||||
if (args.remotes === undefined || args.resource === undefined) return undefined;
|
||||
|
||||
try {
|
||||
if (args.remotes.length === 1) {
|
||||
const command = new OpenRemoteCommandQuickPickItem(args.remotes[0], args.resource);
|
||||
return command.execute();
|
||||
|
||||
@@ -12,7 +12,7 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand {
|
||||
super(Commands.OpenRepoInRemote);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri) {
|
||||
async execute(editor?: TextEditor, uri?: Uri) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||
|
||||
@@ -24,6 +24,8 @@ export class ShowBlameHistoryCommand extends EditorCommand {
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
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)
|
||||
args.range = editor.document.validateRange(new Range(0, 0, 1000000, 1000000));
|
||||
args.position = editor.document.validateRange(new Range(0, 0, 0, 1000000)).start;
|
||||
|
||||
@@ -30,7 +30,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
|
||||
super(Commands.ShowCommitSearch);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: ShowCommitSearchCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowCommitSearchCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
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;
|
||||
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show commit search`);
|
||||
|
||||
args = { ...args };
|
||||
if (!args.search || args.searchBy == null) {
|
||||
try {
|
||||
if (!args.search) {
|
||||
@@ -95,14 +96,17 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
|
||||
originalSearch = `@${args.search}`;
|
||||
placeHolder = `commits with author matching '${args.search}'`;
|
||||
break;
|
||||
|
||||
case GitRepoSearchBy.Files:
|
||||
originalSearch = `:${args.search}`;
|
||||
placeHolder = `commits with files matching '${args.search}'`;
|
||||
break;
|
||||
|
||||
case GitRepoSearchBy.Message:
|
||||
originalSearch = args.search;
|
||||
placeHolder = `commits with message matching '${args.search}'`;
|
||||
break;
|
||||
|
||||
case GitRepoSearchBy.Sha:
|
||||
originalSearch = `#${args.search}`;
|
||||
placeHolder = `commits with id matching '${args.search}'`;
|
||||
|
||||
@@ -21,6 +21,8 @@ export class ShowFileBlameCommand extends EditorCommand {
|
||||
|
||||
try {
|
||||
if (args.type === undefined) {
|
||||
args = { ...args };
|
||||
|
||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||
args.type = cfg.blame.file.annotationType;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ export class ShowFileHistoryCommand extends EditorCommand {
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
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)
|
||||
args.position = editor.document.validateRange(new Range(0, 0, 0, 1000000)).start;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export class ShowLastQuickPickCommand extends Command {
|
||||
|
||||
async execute() {
|
||||
const command = getLastCommand();
|
||||
if (!command) return undefined;
|
||||
if (command === undefined) return undefined;
|
||||
|
||||
try {
|
||||
return commands.executeCommand(command.command, ...command.args);
|
||||
|
||||
@@ -20,6 +20,8 @@ export class ShowLineBlameCommand extends EditorCommand {
|
||||
|
||||
try {
|
||||
if (args.type === undefined) {
|
||||
args = { ...args };
|
||||
|
||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||
args.type = cfg.blame.line.annotationType;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,12 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
|
||||
super(Commands.ShowQuickBranchHistory);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickBranchHistoryCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickBranchHistoryCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||
|
||||
args = { ...args };
|
||||
if (args.maxCount == null) {
|
||||
args.maxCount = this.git.config.advanced.maxQuickHistory;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
|
||||
super(Commands.ShowQuickCommitDetails);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickCommitDetailsCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitDetailsCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
@@ -33,6 +33,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
|
||||
let repoPath = gitUri.repoPath;
|
||||
let workingFileName = path.relative(repoPath || '', gitUri.fsPath);
|
||||
|
||||
args = { ...args };
|
||||
if (args.sha === undefined) {
|
||||
if (editor === undefined) return undefined;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
|
||||
super(Commands.ShowQuickCommitFileDetails);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickCommitFileDetailsCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCommitFileDetailsCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return undefined;
|
||||
|
||||
@@ -32,6 +32,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
|
||||
|
||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||
|
||||
args = { ...args };
|
||||
if (args.sha === undefined) {
|
||||
if (editor === undefined) return undefined;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export class ShowQuickCurrentBranchHistoryCommand extends ActiveEditorCachedComm
|
||||
super(Commands.ShowQuickCurrentBranchHistory);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickCurrentBranchHistoryCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickCurrentBranchHistoryCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { Strings } from '../system';
|
||||
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 { GitLog, GitService, GitUri } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
@@ -25,27 +25,13 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
|
||||
super(Commands.ShowQuickFileHistory);
|
||||
}
|
||||
|
||||
async run(context: CommandContext, args: ShowQuickFileHistoryCommandArgs = {}): 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: ShowQuickFileHistoryCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);
|
||||
|
||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||
|
||||
args = { ...args };
|
||||
if (args.maxCount == null) {
|
||||
args.maxCount = this.git.config.advanced.maxQuickHistory;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand {
|
||||
super(Commands.ShowQuickRepoStatus);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickRepoStatusCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickRepoStatusCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
try {
|
||||
|
||||
@@ -19,7 +19,7 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
|
||||
super(Commands.ShowQuickStashList);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickStashListCommandArgs = {}) {
|
||||
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickStashListCommandArgs = {}) {
|
||||
uri = getCommandUri(uri, editor);
|
||||
|
||||
try {
|
||||
|
||||
@@ -25,6 +25,7 @@ export class StashApplyCommand extends Command {
|
||||
async execute(args: StashApplyCommandArgs = { confirm: true, deleteAfter: false }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.stashItem === undefined || args.stashItem.stashName === undefined) {
|
||||
const stash = await this.git.getStashList(this.git.repoPath);
|
||||
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 }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.stashItem === undefined || args.stashItem.stashName === undefined) return undefined;
|
||||
|
||||
if (args.confirm === undefined) {
|
||||
|
||||
@@ -21,6 +21,7 @@ export class StashSaveCommand extends Command {
|
||||
async execute(args: StashSaveCommandArgs = { unstagedOnly : false }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.unstagedOnly === undefined) {
|
||||
args.unstagedOnly = false;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ export class ToggleFileBlameCommand extends EditorCommand {
|
||||
|
||||
try {
|
||||
if (args.type === undefined) {
|
||||
args = { ...args };
|
||||
|
||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||
args.type = cfg.blame.file.annotationType;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ export class ToggleLineBlameCommand extends EditorCommand {
|
||||
|
||||
try {
|
||||
if (args.type === undefined) {
|
||||
args = { ...args };
|
||||
|
||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||
args.type = cfg.blame.line.annotationType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user