Browse Source

Renames isCommandContext* commands

main
Eric Amodio 4 years ago
parent
commit
7f06da0e2d
18 changed files with 92 additions and 93 deletions
  1. +41
    -42
      src/commands/common.ts
  2. +2
    -2
      src/commands/copyMessageToClipboard.ts
  3. +6
    -6
      src/commands/copyShaToClipboard.ts
  4. +4
    -4
      src/commands/externalDiff.ts
  5. +2
    -2
      src/commands/inviteToLiveShare.ts
  6. +2
    -2
      src/commands/openBranchOnRemote.ts
  7. +2
    -2
      src/commands/openBranchesOnRemote.ts
  8. +2
    -2
      src/commands/openCommitOnRemote.ts
  9. +2
    -2
      src/commands/openDirectoryCompare.ts
  10. +4
    -4
      src/commands/openFileOnRemote.ts
  11. +3
    -3
      src/commands/openPullRequestOnRemote.ts
  12. +2
    -2
      src/commands/openRepoOnRemote.ts
  13. +3
    -3
      src/commands/remoteProviders.ts
  14. +2
    -2
      src/commands/searchCommits.ts
  15. +2
    -2
      src/commands/showQuickCommit.ts
  16. +2
    -2
      src/commands/showQuickCommitFile.ts
  17. +4
    -4
      src/commands/stashApply.ts
  18. +7
    -7
      src/commands/stashSave.ts

+ 41
- 42
src/commands/common.ts View File

@ -216,82 +216,82 @@ export interface CommandBaseContext {
}
export interface CommandScmGroupsContext extends CommandBaseContext {
type: 'scm-groups';
scmResourceGroups: SourceControlResourceGroup[];
readonly type: 'scm-groups';
readonly scmResourceGroups: SourceControlResourceGroup[];
}
export interface CommandScmStatesContext extends CommandBaseContext {
type: 'scm-states';
scmResourceStates: SourceControlResourceState[];
readonly type: 'scm-states';
readonly scmResourceStates: SourceControlResourceState[];
}
export interface CommandUnknownContext extends CommandBaseContext {
type: 'unknown';
readonly type: 'unknown';
}
export interface CommandUriContext extends CommandBaseContext {
type: 'uri';
readonly type: 'uri';
}
export interface CommandUrisContext extends CommandBaseContext {
type: 'uris';
uris: Uri[];
readonly type: 'uris';
readonly uris: Uri[];
}
// export interface CommandViewContext extends CommandBaseContext {
// type: 'view';
// readonly type: 'view';
// }
export interface CommandViewItemContext extends CommandBaseContext {
type: 'viewItem';
node: ViewNode;
export interface CommandViewNodeContext extends CommandBaseContext {
readonly type: 'viewItem';
readonly node: ViewNode;
}
export function isCommandViewContextWithBranch(
export function isCommandContextViewNodeHasBranch(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { branch: GitBranch } } {
): context is CommandViewNodeContext & { node: ViewNode & { branch: GitBranch } } {
if (context.type !== 'viewItem') return false;
return GitBranch.is((context.node as ViewNode & { branch: GitBranch }).branch);
}
export function isCommandViewContextWithCommit<T extends GitCommit>(
export function isCommandContextViewNodeHasCommit<T extends GitCommit>(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { commit: T } } {
): context is CommandViewNodeContext & { node: ViewNode & { commit: T } } {
if (context.type !== 'viewItem') return false;
return GitCommit.is((context.node as ViewNode & { commit: GitCommit }).commit);
}
export function isCommandViewContextWithContributor(
export function isCommandContextViewNodeHasContributor(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { contributor: GitContributor } } {
): context is CommandViewNodeContext & { node: ViewNode & { contributor: GitContributor } } {
if (context.type !== 'viewItem') return false;
return GitContributor.is((context.node as ViewNode & { contributor: GitContributor }).contributor);
}
export function isCommandViewContextWithFile(
export function isCommandContextViewNodeHasFile(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { file: GitFile; repoPath: string } } {
): context is CommandViewNodeContext & { node: ViewNode & { file: GitFile; repoPath: string } } {
if (context.type !== 'viewItem') return false;
const node = context.node as ViewNode & { file: GitFile; repoPath: string };
return node.file != null && (node.file.repoPath != null || node.repoPath != null);
}
export function isCommandViewContextWithFileCommit(
export function isCommandContextViewNodeHasFileCommit(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { commit: GitCommit; file: GitFile; repoPath: string } } {
): context is CommandViewNodeContext & { node: ViewNode & { commit: GitCommit; file: GitFile; repoPath: string } } {
if (context.type !== 'viewItem') return false;
const node = context.node as ViewNode & { commit: GitCommit; file: GitFile; repoPath: string };
return node.file != null && GitCommit.is(node.commit) && (node.file.repoPath != null || node.repoPath != null);
}
export function isCommandViewContextWithFileRefs(
export function isCommandContextViewNodeHasFileRefs(
context: CommandContext,
): context is CommandViewItemContext & {
): context is CommandViewNodeContext & {
node: ViewNode & { file: GitFile; ref1: string; ref2: string; repoPath: string };
} {
if (context.type !== 'viewItem') return false;
@ -305,39 +305,39 @@ export function isCommandViewContextWithFileRefs(
);
}
export function isCommandViewContextWithRef(
export function isCommandContextViewNodeHasRef(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { ref: string } } {
): context is CommandViewNodeContext & { node: ViewNode & { ref: string } } {
return context.type === 'viewItem' && context.node instanceof ViewRefNode;
}
export function isCommandViewContextWithRemote(
export function isCommandContextViewNodeHasRemote(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { remote: GitRemote } } {
): context is CommandViewNodeContext & { node: ViewNode & { remote: GitRemote } } {
if (context.type !== 'viewItem') return false;
return GitRemote.is((context.node as ViewNode & { remote: GitRemote }).remote);
}
export function isCommandViewContextWithRepo(
export function isCommandContextViewNodeHasRepository(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { repo: Repository } } {
): context is CommandViewNodeContext & { node: ViewNode & { repo: Repository } } {
if (context.type !== 'viewItem') return false;
return (context.node as ViewNode & { repo?: Repository }).repo instanceof Repository;
}
export function isCommandViewContextWithRepoPath(
export function isCommandContextViewNodeHasRepoPath(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { repoPath: string } } {
): context is CommandViewNodeContext & { node: ViewNode & { repoPath: string } } {
if (context.type !== 'viewItem') return false;
return typeof (context.node as ViewNode & { repoPath?: string }).repoPath === 'string';
}
export function isCommandViewContextWithTag(
export function isCommandContextViewNodeHasTag(
context: CommandContext,
): context is CommandViewItemContext & { node: ViewNode & { tag: GitTag } } {
): context is CommandViewNodeContext & { node: ViewNode & { tag: GitTag } } {
if (context.type !== 'viewItem') return false;
return GitTag.is((context.node as ViewNode & { tag: GitTag }).tag);
@ -350,24 +350,23 @@ export type CommandContext =
| CommandUriContext
| CommandUrisContext
// | CommandViewContext
| CommandViewItemContext;
| CommandViewNodeContext;
function isScmResourceGroup(group: any): group is SourceControlResourceGroup {
if (group == null) return false;
return (
(group as SourceControl).inputBox == null &&
(group as SourceControlResourceGroup).id != null &&
(group.handle != null ||
(group as SourceControlResourceGroup).label != null ||
(group as SourceControlResourceGroup).resourceStates != null)
(group as SourceControlResourceGroup).label != null &&
(group as SourceControlResourceGroup).resourceStates != null &&
Array.isArray((group as SourceControlResourceGroup).resourceStates)
);
}
function isScmResourceState(state: any): state is SourceControlResourceState {
if (state == null) return false;
function isScmResourceState(resource: any): resource is SourceControlResourceState {
if (resource == null) return false;
return (state as SourceControlResourceState).resourceUri != null;
return (resource as SourceControlResourceState).resourceUri != null;
}
export abstract class Command implements Disposable {

+ 2
- 2
src/commands/copyMessageToClipboard.ts View File

@ -11,7 +11,7 @@ import {
CommandContext,
Commands,
getCommandUri,
isCommandViewContextWithCommit,
isCommandContextViewNodeHasCommit,
} from './common';
export interface CopyMessageToClipboardCommandArgs {
@ -26,7 +26,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
}
protected preExecute(context: CommandContext, args?: CopyMessageToClipboardCommandArgs) {
if (isCommandViewContextWithCommit(context)) {
if (isCommandContextViewNodeHasCommit(context)) {
args = { ...args };
args.sha = context.node.commit.sha;
return this.execute(context.editor, context.node.commit.uri, args);

+ 6
- 6
src/commands/copyShaToClipboard.ts View File

@ -11,9 +11,9 @@ import {
CommandContext,
Commands,
getCommandUri,
isCommandViewContextWithBranch,
isCommandViewContextWithCommit,
isCommandViewContextWithTag,
isCommandContextViewNodeHasBranch,
isCommandContextViewNodeHasCommit,
isCommandContextViewNodeHasTag,
} from './common';
export interface CopyShaToClipboardCommandArgs {
@ -27,15 +27,15 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
}
protected preExecute(context: CommandContext, args?: CopyShaToClipboardCommandArgs) {
if (isCommandViewContextWithCommit(context)) {
if (isCommandContextViewNodeHasCommit(context)) {
args = { ...args };
args.sha = context.node.commit.sha;
return this.execute(context.editor, context.node.commit.uri, args);
} else if (isCommandViewContextWithBranch(context)) {
} else if (isCommandContextViewNodeHasBranch(context)) {
args = { ...args };
args.sha = context.node.branch.sha;
return this.execute(context.editor, context.node.uri, args);
} else if (isCommandViewContextWithTag(context)) {
} else if (isCommandContextViewNodeHasTag(context)) {
args = { ...args };
args.sha = context.node.tag.sha;
return this.execute(context.editor, context.node.uri, args);

+ 4
- 4
src/commands/externalDiff.ts View File

@ -6,8 +6,8 @@ import {
CommandContext,
Commands,
getRepoPathOrPrompt,
isCommandViewContextWithFileCommit,
isCommandViewContextWithFileRefs,
isCommandContextViewNodeHasFileCommit,
isCommandContextViewNodeHasFileRefs,
} from './common';
import { Container } from '../container';
import { GitRevision } from '../git/git';
@ -68,7 +68,7 @@ export class ExternalDiffCommand extends Command {
protected async preExecute(context: CommandContext, args?: ExternalDiffCommandArgs) {
args = { ...args };
if (isCommandViewContextWithFileCommit(context)) {
if (isCommandContextViewNodeHasFileCommit(context)) {
const ref1 = GitRevision.isUncommitted(context.node.commit.previousFileSha)
? ''
: context.node.commit.previousFileSha;
@ -86,7 +86,7 @@ export class ExternalDiffCommand extends Command {
return this.execute(args);
}
if (isCommandViewContextWithFileRefs(context)) {
if (isCommandContextViewNodeHasFileRefs(context)) {
args.files = [
{
uri: GitUri.fromFile(context.node.file, context.node.file.repoPath ?? context.node.repoPath),

+ 2
- 2
src/commands/inviteToLiveShare.ts View File

@ -1,5 +1,5 @@
'use strict';
import { command, Command, CommandContext, Commands, isCommandViewContextWithContributor } from './common';
import { command, Command, CommandContext, Commands, isCommandContextViewNodeHasContributor } from './common';
import { Container } from '../container';
export interface InviteToLiveShareCommandArgs {
@ -21,7 +21,7 @@ export class InviteToLiveShareCommand extends Command {
}
protected preExecute(context: CommandContext, args?: InviteToLiveShareCommandArgs) {
if (isCommandViewContextWithContributor(context)) {
if (isCommandContextViewNodeHasContributor(context)) {
args = { ...args };
args.email = context.node.contributor.email;
return this.execute(args);

+ 2
- 2
src/commands/openBranchOnRemote.ts View File

@ -8,7 +8,7 @@ import {
executeCommand,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandViewContextWithBranch,
isCommandContextViewNodeHasBranch,
} from './common';
import { BranchSorting } from '../configuration';
import { RemoteResourceType } from '../git/git';
@ -30,7 +30,7 @@ export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
}
protected preExecute(context: CommandContext, args?: OpenBranchOnRemoteCommandArgs) {
if (isCommandViewContextWithBranch(context)) {
if (isCommandContextViewNodeHasBranch(context)) {
args = {
...args,
branch: context.node.branch.name,

+ 2
- 2
src/commands/openBranchesOnRemote.ts View File

@ -11,7 +11,7 @@ import {
executeCommand,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandViewContextWithRemote,
isCommandContextViewNodeHasRemote,
} from './common';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
@ -27,7 +27,7 @@ export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand {
}
protected preExecute(context: CommandContext, args?: OpenBranchesOnRemoteCommandArgs) {
if (isCommandViewContextWithRemote(context)) {
if (isCommandContextViewNodeHasRemote(context)) {
args = { ...args, remote: context.node.remote.name };
}

+ 2
- 2
src/commands/openCommitOnRemote.ts View File

@ -7,7 +7,7 @@ import {
Commands,
executeCommand,
getCommandUri,
isCommandViewContextWithCommit,
isCommandContextViewNodeHasCommit,
} from './common';
import { Container } from '../container';
import { RemoteResourceType } from '../git/git';
@ -37,7 +37,7 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand {
protected preExecute(context: CommandContext, args?: OpenCommitOnRemoteCommandArgs) {
let uri = context.uri;
if (isCommandViewContextWithCommit(context)) {
if (isCommandContextViewNodeHasCommit(context)) {
if (context.node.commit.isUncommitted) return Promise.resolve(undefined);
args = { ...args, sha: context.node.commit.sha };

+ 2
- 2
src/commands/openDirectoryCompare.ts View File

@ -7,7 +7,7 @@ import {
Commands,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandViewContextWithRef,
isCommandContextViewNodeHasRef,
} from './common';
import { Container } from '../container';
import { Logger } from '../logger';
@ -47,7 +47,7 @@ export class OpenDirectoryCompareCommand extends ActiveEditorCommand {
break;
case Commands.ViewsOpenDirectoryDiffWithWorking:
if (isCommandViewContextWithRef(context)) {
if (isCommandContextViewNodeHasRef(context)) {
args = { ...args };
args.ref1 = context.node.ref;
args.ref2 = undefined;

+ 4
- 4
src/commands/openFileOnRemote.ts View File

@ -7,8 +7,8 @@ import {
Commands,
executeCommand,
getCommandUri,
isCommandViewContextWithBranch,
isCommandViewContextWithCommit,
isCommandContextViewNodeHasBranch,
isCommandContextViewNodeHasCommit,
} from './common';
import { UriComparer } from '../comparers';
import { BranchSorting } from '../configuration';
@ -40,13 +40,13 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
if (context.type === 'uris' || context.type === 'scm-states') {
args = { ...args, range: false };
} else if (isCommandViewContextWithCommit(context)) {
} else if (isCommandContextViewNodeHasCommit(context)) {
args = { ...args, range: false };
if (context.command === Commands.CopyRemoteFileUrl) {
// If it is a StatusFileNode then don't include the sha, since it hasn't been pushed yet
args.sha = context.node instanceof StatusFileNode ? undefined : context.node.commit.sha;
} else if (isCommandViewContextWithBranch(context)) {
} else if (isCommandContextViewNodeHasBranch(context)) {
args.branch = context.node.branch?.name;
}

+ 3
- 3
src/commands/openPullRequestOnRemote.ts View File

@ -5,8 +5,8 @@ import {
command,
CommandContext,
Commands,
isCommandViewContextWithCommit,
isCommandViewContextWithFileCommit,
isCommandContextViewNodeHasCommit,
isCommandContextViewNodeHasFileCommit,
} from './common';
import { Container } from '../container';
import { PullRequestNode } from '../views/nodes/pullRequestNode';
@ -31,7 +31,7 @@ export class OpenPullRequestOnRemoteCommand extends Command {
pr: { url: context.node.pullRequest.url },
};
}
} else if (isCommandViewContextWithCommit(context) || isCommandViewContextWithFileCommit(context)) {
} else if (isCommandContextViewNodeHasCommit(context) || isCommandContextViewNodeHasFileCommit(context)) {
args = { ...args, ref: context.node.commit.sha, repoPath: context.node.commit.repoPath };
}

+ 2
- 2
src/commands/openRepoOnRemote.ts View File

@ -8,7 +8,7 @@ import {
executeCommand,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandViewContextWithRemote,
isCommandContextViewNodeHasRemote,
} from './common';
import { RemoteResourceType } from '../git/git';
import { GitUri } from '../git/gitUri';
@ -27,7 +27,7 @@ export class OpenRepoOnRemoteCommand extends ActiveEditorCommand {
}
protected preExecute(context: CommandContext, args?: OpenRepoOnRemoteCommandArgs) {
if (isCommandViewContextWithRemote(context)) {
if (isCommandContextViewNodeHasRemote(context)) {
args = { ...args, remote: context.node.remote.name };
}

+ 3
- 3
src/commands/remoteProviders.ts View File

@ -1,6 +1,6 @@
'use strict';
import { GitCommit, GitRemote } from '../git/git';
import { command, Command, CommandContext, Commands, isCommandViewContextWithRemote } from './common';
import { command, Command, CommandContext, Commands, isCommandContextViewNodeHasRemote } from './common';
import { Container } from '../container';
export interface ConnectRemoteProviderCommandArgs {
@ -31,7 +31,7 @@ export class ConnectRemoteProviderCommand extends Command {
}
protected preExecute(context: CommandContext, args?: ConnectRemoteProviderCommandArgs) {
if (isCommandViewContextWithRemote(context)) {
if (isCommandContextViewNodeHasRemote(context)) {
args = { ...args, remote: context.node.remote.id, repoPath: context.node.remote.repoPath };
}
@ -84,7 +84,7 @@ export class DisconnectRemoteProviderCommand extends Command {
}
protected preExecute(context: CommandContext, args?: ConnectRemoteProviderCommandArgs) {
if (isCommandViewContextWithRemote(context)) {
if (isCommandContextViewNodeHasRemote(context)) {
args = { ...args, remote: context.node.remote.id, repoPath: context.node.remote.repoPath };
}

+ 2
- 2
src/commands/searchCommits.ts View File

@ -1,6 +1,6 @@
'use strict';
import { executeGitCommand } from '../commands';
import { Command, command, CommandContext, Commands, isCommandViewContextWithRepo } from './common';
import { Command, command, CommandContext, Commands, isCommandContextViewNodeHasRepository } from './common';
import { Container } from '../container';
import { SearchPattern } from '../git/git';
import { SearchResultsNode } from '../views/nodes';
@ -31,7 +31,7 @@ export class SearchCommitsCommand extends Command {
args.prefillOnly = true;
}
if (isCommandViewContextWithRepo(context)) {
if (isCommandContextViewNodeHasRepository(context)) {
args.repoPath = context.node.repo.path;
}
} else if (context.command === Commands.SearchCommitsInView) {

+ 2
- 2
src/commands/showQuickCommit.ts View File

@ -6,7 +6,7 @@ import {
CommandContext,
Commands,
getCommandUri,
isCommandViewContextWithCommit,
isCommandContextViewNodeHasCommit,
} from './common';
import { Container } from '../container';
import { GitCommit, GitLog, GitLogCommit } from '../git/git';
@ -46,7 +46,7 @@ export class ShowQuickCommitCommand extends ActiveEditorCachedCommand {
args = { ...args };
args.sha = context.node.uri.sha;
if (isCommandViewContextWithCommit(context)) {
if (isCommandContextViewNodeHasCommit(context)) {
args.commit = context.node.commit;
}
}

+ 2
- 2
src/commands/showQuickCommitFile.ts View File

@ -6,7 +6,7 @@ import {
CommandContext,
Commands,
getCommandUri,
isCommandViewContextWithCommit,
isCommandContextViewNodeHasCommit,
} from './common';
import { Container } from '../container';
import { GitBlameCommit, GitCommit, GitLog, GitLogCommit } from '../git/git';
@ -49,7 +49,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
args = { ...args };
args.sha = context.node.uri.sha;
if (isCommandViewContextWithCommit(context)) {
if (isCommandContextViewNodeHasCommit(context)) {
args.commit = context.node.commit;
}
}

+ 4
- 4
src/commands/stashApply.ts View File

@ -5,8 +5,8 @@ import {
Command,
CommandContext,
Commands,
isCommandViewContextWithCommit,
isCommandViewContextWithRepo,
isCommandContextViewNodeHasCommit,
isCommandContextViewNodeHasRepository,
} from './common';
import { GitStashCommit, GitStashReference } from '../git/git';
import { CommandQuickPickItem } from '../quickpicks';
@ -26,9 +26,9 @@ export class StashApplyCommand extends Command {
}
protected preExecute(context: CommandContext, args?: StashApplyCommandArgs) {
if (isCommandViewContextWithCommit<GitStashCommit>(context)) {
if (isCommandContextViewNodeHasCommit<GitStashCommit>(context)) {
args = { ...args, stashItem: context.node.commit };
} else if (isCommandViewContextWithRepo(context)) {
} else if (isCommandContextViewNodeHasRepository(context)) {
args = { ...args, repoPath: context.node.repo.path };
}

+ 7
- 7
src/commands/stashSave.ts View File

@ -2,13 +2,13 @@
import { Uri } from 'vscode';
import { GitActions } from '../commands';
import {
command,
Command,
command,
CommandContext,
Commands,
isCommandViewContextWithFile,
isCommandViewContextWithRepo,
isCommandViewContextWithRepoPath,
isCommandContextViewNodeHasFile,
isCommandContextViewNodeHasRepoPath,
isCommandContextViewNodeHasRepository,
} from './common';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
@ -33,14 +33,14 @@ export class StashSaveCommand extends Command {
}
protected async preExecute(context: CommandContext, args?: StashSaveCommandArgs) {
if (isCommandViewContextWithFile(context)) {
if (isCommandContextViewNodeHasFile(context)) {
args = { ...args };
args.repoPath = context.node.file.repoPath ?? context.node.repoPath;
args.uris = [GitUri.fromFile(context.node.file, args.repoPath)];
} else if (isCommandViewContextWithRepo(context)) {
} else if (isCommandContextViewNodeHasRepository(context)) {
args = { ...args };
args.repoPath = context.node.repo.path;
} else if (isCommandViewContextWithRepoPath(context)) {
} else if (isCommandContextViewNodeHasRepoPath(context)) {
args = { ...args };
args.repoPath = context.node.repoPath;
} else if (context.type === 'scm-states') {

Loading…
Cancel
Save