Преглед изворни кода

Reworks commanding structure for less redundancy

Adds command args copying when needed
main
Eric Amodio пре 7 година
родитељ
комит
0a9559f5a5
36 измењених фајлова са 169 додато и 209 уклоњено
  1. +4
    -18
      src/commands/closeUnchangedFiles.ts
  2. +84
    -67
      src/commands/common.ts
  3. +3
    -1
      src/commands/copyMessageToClipboard.ts
  4. +3
    -1
      src/commands/copyShaToClipboard.ts
  5. +3
    -1
      src/commands/diffDirectory.ts
  6. +6
    -2
      src/commands/diffLineWithPrevious.ts
  7. +6
    -2
      src/commands/diffLineWithWorking.ts
  8. +3
    -17
      src/commands/diffWithBranch.ts
  9. +2
    -1
      src/commands/diffWithNext.ts
  10. +3
    -17
      src/commands/diffWithPrevious.ts
  11. +3
    -17
      src/commands/diffWithRevision.ts
  12. +2
    -1
      src/commands/diffWithWorking.ts
  13. +3
    -1
      src/commands/openBranchInRemote.ts
  14. +4
    -18
      src/commands/openChangedFiles.ts
  15. +1
    -1
      src/commands/openCommitInRemote.ts
  16. +2
    -16
      src/commands/openFileInRemote.ts
  17. +3
    -2
      src/commands/openInRemote.ts
  18. +1
    -1
      src/commands/openRepoInRemote.ts
  19. +2
    -0
      src/commands/showBlameHistory.ts
  20. +5
    -1
      src/commands/showCommitSearch.ts
  21. +2
    -0
      src/commands/showFileBlame.ts
  22. +2
    -0
      src/commands/showFileHistory.ts
  23. +1
    -1
      src/commands/showLastQuickPick.ts
  24. +2
    -0
      src/commands/showLineBlame.ts
  25. +2
    -1
      src/commands/showQuickBranchHistory.ts
  26. +2
    -1
      src/commands/showQuickCommitDetails.ts
  27. +2
    -1
      src/commands/showQuickCommitFileDetails.ts
  28. +1
    -1
      src/commands/showQuickCurrentBranchHistory.ts
  29. +3
    -17
      src/commands/showQuickFileHistory.ts
  30. +1
    -1
      src/commands/showQuickRepoStatus.ts
  31. +1
    -1
      src/commands/showQuickStashList.ts
  32. +1
    -0
      src/commands/stashApply.ts
  33. +1
    -0
      src/commands/stashDelete.ts
  34. +1
    -0
      src/commands/stashSave.ts
  35. +2
    -0
      src/commands/toggleFileBlame.ts
  36. +2
    -0
      src/commands/toggleLineBlame.ts

+ 4
- 18
src/commands/closeUnchangedFiles.ts Прегледај датотеку

@ -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`);

+ 84
- 67
src/commands/common.ts Прегледај датотеку

@ -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 async preExecute(context: CommandContext, ...args: any[]): Promise<any> {
return this.execute(...args);
}
abstract execute(...args: any[]): any;
protected _execute(...args: any[]): any {
Telemetry.trackEvent(this.command);
if (typeof this.run === 'function') {
let editor: TextEditor | undefined = undefined;
const [context, rest] = Command._parseContext(this.contextParsingOptions, ...args);
return this.preExecute(context, ...rest);
}
let firstArg = args[0];
if (firstArg === undefined || isTextEditor(firstArg)) {
editor = firstArg;
args = args.slice(1);
firstArg = args[0];
}
private static _parseContext(options: CommandContextParsingOptions, ...args: any[]): [CommandContext, any[]] {
let editor: TextEditor | undefined = undefined;
if (firstArg instanceof Uri) {
const [uri, ...rest] = args;
return this.run({ type: 'uri', editor: editor, uri: uri }, ...rest);
}
let firstArg = args[0];
if (options.editor && (firstArg === undefined || isTextEditor(firstArg))) {
editor = firstArg;
args = args.slice(1);
firstArg = args[0];
}
if (isScmResourceState(firstArg)) {
const states = [];
let count = 0;
for (const arg of args) {
if (!isScmResourceState(arg)) break;
if (options.uri && (firstArg === undefined || firstArg instanceof Uri)) {
const [uri, ...rest] = args as [Uri, any];
return [{ type: 'uri', editor: editor, uri: uri }, rest];
}
count++;
states.push(arg);
}
if (isScmResourceState(firstArg)) {
const states = [];
let count = 0;
for (const arg of args) {
if (!isScmResourceState(arg)) break;
return this.run({ type: 'scm-states', scmResourceStates: states }, ...args.slice(count));
count++;
states.push(arg);
}
if (isScmResourceGroup(firstArg)) {
const groups = [];
let count = 0;
for (const arg of args) {
if (!isScmResourceGroup(arg)) break;
return [{ type: 'scm-states', scmResourceStates: states, uri: states[0].resourceUri }, args.slice(count)];
}
count++;
groups.push(arg);
}
if (isScmResourceGroup(firstArg)) {
const groups = [];
let count = 0;
for (const arg of args) {
if (!isScmResourceGroup(arg)) break;
return this.run({ type: 'scm-groups', scmResourceGroups: groups }, ...args.slice(count));
count++;
groups.push(arg);
}
return this.run({ type: 'unknown', editor: editor }, ...args);
return [{ type: 'scm-groups', scmResourceGroups: groups }, args.slice(count)];
}
return this.execute(...args);
return [{ type: 'unknown', editor: editor }, args];
}
abstract execute(...args: any[]): any;
}
export abstract class EditorCommand extends Disposable {
export abstract class ActiveEditorCommand extends Command {
private _disposable: Disposable;
protected readonly contextParsingOptions: CommandContextParsingOptions = { editor: true, uri: true };
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);
super(command);
}
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
}
export abstract class ActiveEditorCommand extends Command {
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 = {

+ 3
- 1
src/commands/copyMessageToClipboard.ts Прегледај датотеку

@ -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;

+ 3
- 1
src/commands/copyShaToClipboard.ts Прегледај датотеку

@ -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;

+ 3
- 1
src/commands/diffDirectory.ts Прегледај датотеку

@ -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`);

+ 6
- 2
src/commands/diffLineWithPrevious.ts Прегледај датотеку

@ -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;

+ 6
- 2
src/commands/diffLineWithWorking.ts Прегледај датотеку

@ -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;

+ 3
- 17
src/commands/diffWithBranch.ts Прегледај датотеку

@ -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;
}

+ 2
- 1
src/commands/diffWithNext.ts Прегледај датотеку

@ -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;
}

+ 3
- 17
src/commands/diffWithPrevious.ts Прегледај датотеку

@ -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;
}

+ 3
- 17
src/commands/diffWithRevision.ts Прегледај датотеку

@ -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;
}

+ 2
- 1
src/commands/diffWithWorking.ts Прегледај датотеку

@ -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;
}

+ 3
- 1
src/commands/openBranchInRemote.ts Прегледај датотеку

@ -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}`);

+ 4
- 18
src/commands/openChangedFiles.ts Прегледај датотеку

@ -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`);

+ 1
- 1
src/commands/openCommitInRemote.ts Прегледај датотеку

@ -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;

+ 2
- 16
src/commands/openFileInRemote.ts Прегледај датотеку

@ -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;

+ 3
- 2
src/commands/openInRemote.ts Прегледај датотеку

@ -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();

+ 1
- 1
src/commands/openRepoInRemote.ts Прегледај датотеку

@ -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);

+ 2
- 0
src/commands/showBlameHistory.ts Прегледај датотеку

@ -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;

+ 5
- 1
src/commands/showCommitSearch.ts Прегледај датотеку

@ -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}'`;

+ 2
- 0
src/commands/showFileBlame.ts Прегледај датотеку

@ -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;
}

+ 2
- 0
src/commands/showFileHistory.ts Прегледај датотеку

@ -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;
}

+ 1
- 1
src/commands/showLastQuickPick.ts Прегледај датотеку

@ -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);

+ 2
- 0
src/commands/showLineBlame.ts Прегледај датотеку

@ -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;
}

+ 2
- 1
src/commands/showQuickBranchHistory.ts Прегледај датотеку

@ -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;
}

+ 2
- 1
src/commands/showQuickCommitDetails.ts Прегледај датотеку

@ -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;

+ 2
- 1
src/commands/showQuickCommitFileDetails.ts Прегледај датотеку

@ -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;

+ 1
- 1
src/commands/showQuickCurrentBranchHistory.ts Прегледај датотеку

@ -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 {

+ 3
- 17
src/commands/showQuickFileHistory.ts Прегледај датотеку

@ -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;
}

+ 1
- 1
src/commands/showQuickRepoStatus.ts Прегледај датотеку

@ -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 {

+ 1
- 1
src/commands/showQuickStashList.ts Прегледај датотеку

@ -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 {

+ 1
- 0
src/commands/stashApply.ts Прегледај датотеку

@ -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`);

+ 1
- 0
src/commands/stashDelete.ts Прегледај датотеку

@ -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) {

+ 1
- 0
src/commands/stashSave.ts Прегледај датотеку

@ -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;
}

+ 2
- 0
src/commands/toggleFileBlame.ts Прегледај датотеку

@ -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;
}

+ 2
- 0
src/commands/toggleLineBlame.ts Прегледај датотеку

@ -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;
}

Loading…
Откажи
Сачувај