Browse Source

Removes QuickCommand namespace

main
Eric Amodio 1 year ago
parent
commit
c7f288b5e2
22 changed files with 317 additions and 263 deletions
  1. +16
    -12
      src/commands/git/branch.ts
  2. +6
    -3
      src/commands/git/cherry-pick.ts
  3. +2
    -2
      src/commands/git/coauthors.ts
  4. +12
    -4
      src/commands/git/fetch.ts
  5. +2
    -2
      src/commands/git/log.ts
  6. +6
    -4
      src/commands/git/merge.ts
  7. +4
    -2
      src/commands/git/pull.ts
  8. +4
    -2
      src/commands/git/push.ts
  9. +6
    -4
      src/commands/git/rebase.ts
  10. +16
    -12
      src/commands/git/remote.ts
  11. +11
    -3
      src/commands/git/reset.ts
  12. +11
    -3
      src/commands/git/revert.ts
  13. +6
    -3
      src/commands/git/search.ts
  14. +4
    -4
      src/commands/git/show.ts
  15. +18
    -15
      src/commands/git/stash.ts
  16. +3
    -3
      src/commands/git/status.ts
  17. +4
    -2
      src/commands/git/switch.ts
  18. +18
    -14
      src/commands/git/tag.ts
  19. +21
    -17
      src/commands/git/worktree.ts
  20. +5
    -5
      src/commands/gitCommands.ts
  21. +59
    -62
      src/commands/quickCommand.steps.ts
  22. +83
    -85
      src/commands/quickCommand.ts

+ 16
- 12
src/commands/git/branch.ts View File

@ -19,6 +19,10 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
createConfirmStep,
createPickStep,
endSteps,
inputBranchNameStep, inputBranchNameStep,
pickBranchesStep, pickBranchesStep,
pickBranchOrTagStep, pickBranchOrTagStep,
@ -243,7 +247,7 @@ export class BranchGitCommand extends QuickCommand {
state.name = undefined!; state.name = undefined!;
break; break;
default: default:
QuickCommand.endSteps(state);
endSteps(state);
break; break;
} }
@ -257,7 +261,7 @@ export class BranchGitCommand extends QuickCommand {
} }
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> { private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title, title: this.title,
placeholder: `Choose a ${this.label} command`, placeholder: `Choose a ${this.label} command`,
items: [ items: [
@ -283,7 +287,7 @@ export class BranchGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back], buttons: [QuickInputButtons.Back],
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> { private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> {
@ -328,7 +332,7 @@ export class BranchGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
if (state.flags.includes('--switch')) { if (state.flags.includes('--switch')) {
await state.repo.switch(state.reference.ref, { createBranch: state.name }); await state.repo.switch(state.reference.ref, { createBranch: state.name });
} else { } else {
@ -341,7 +345,7 @@ export class BranchGitCommand extends QuickCommand {
state: CreateStepState<CreateState>, state: CreateStepState<CreateState>,
context: Context, context: Context,
): StepResultGenerator<CreateFlags[]> { ): StepResultGenerator<CreateFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
createFlagsQuickPickItem<CreateFlags>(state.flags, [], { createFlagsQuickPickItem<CreateFlags>(state.flags, [], {
@ -361,7 +365,7 @@ export class BranchGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *deleteCommandSteps(state: DeleteStepState, context: Context): AsyncStepResultGenerator<void> { private async *deleteCommandSteps(state: DeleteStepState, context: Context): AsyncStepResultGenerator<void> {
@ -404,7 +408,7 @@ export class BranchGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
state.repo.branchDelete(state.references, { state.repo.branchDelete(state.references, {
force: state.flags.includes('--force'), force: state.flags.includes('--force'),
remote: state.flags.includes('--remotes'), remote: state.flags.includes('--remotes'),
@ -455,13 +459,13 @@ export class BranchGitCommand extends QuickCommand {
} }
} }
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
confirmations, confirmations,
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *renameCommandSteps(state: RenameStepState, context: Context): AsyncStepResultGenerator<void> { private async *renameCommandSteps(state: RenameStepState, context: Context): AsyncStepResultGenerator<void> {
@ -500,7 +504,7 @@ export class BranchGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
state.repo.branch(...state.flags, state.reference.ref, state.name); state.repo.branch(...state.flags, state.reference.ref, state.name);
} }
} }
@ -509,7 +513,7 @@ export class BranchGitCommand extends QuickCommand {
state: RenameStepState<RenameState>, state: RenameStepState<RenameState>,
context: Context, context: Context,
): StepResultGenerator<RenameFlags[]> { ): StepResultGenerator<RenameFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<RenameFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<RenameFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
createFlagsQuickPickItem<RenameFlags>(state.flags, ['-m'], { createFlagsQuickPickItem<RenameFlags>(state.flags, ['-m'], {
@ -520,6 +524,6 @@ export class BranchGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 6
- 3
src/commands/git/cherry-pick.ts View File

@ -16,6 +16,9 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
createConfirmStep,
endSteps,
pickBranchOrTagStep, pickBranchOrTagStep,
pickCommitsStep, pickCommitsStep,
pickRepositoryStep, pickRepositoryStep,
@ -203,7 +206,7 @@ export class CherryPickGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as CherryPickStepState<State<GitReference[]>>); this.execute(state as CherryPickStepState<State<GitReference[]>>);
} }
@ -211,7 +214,7 @@ export class CherryPickGitCommand extends QuickCommand {
} }
private *confirmStep(state: CherryPickStepState, context: Context): StepResultGenerator<Flags[]> { private *confirmStep(state: CherryPickStepState, context: Context): StepResultGenerator<Flags[]> {
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
createFlagsQuickPickItem<Flags>(state.flags, [], { createFlagsQuickPickItem<Flags>(state.flags, [], {
@ -238,6 +241,6 @@ export class CherryPickGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 2
- 2
src/commands/git/coauthors.ts View File

@ -6,7 +6,7 @@ import { executeCoreCommand } from '../../system/command';
import { normalizePath } from '../../system/path'; import { normalizePath } from '../../system/path';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type { PartialStepState, StepGenerator, StepState } from '../quickCommand'; import type { PartialStepState, StepGenerator, StepState } from '../quickCommand';
import { pickContributorsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import { endSteps , pickContributorsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
interface Context { interface Context {
repos: Repository[]; repos: Repository[];
@ -154,7 +154,7 @@ export class CoAuthorsGitCommand extends QuickCommand {
state.contributors = result; state.contributors = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as CoAuthorStepState); void this.execute(state as CoAuthorStepState);
} }

+ 12
- 4
src/commands/git/fetch.ts View File

@ -17,7 +17,15 @@ import type {
StepSelection, StepSelection,
StepState, StepState,
} from '../quickCommand'; } from '../quickCommand';
import { appendReposToTitle, pickRepositoriesStep, QuickCommand, StepResult } from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
createConfirmStep,
endSteps,
pickRepositoriesStep,
QuickCommand,
StepResult,
} from '../quickCommand';
interface Context { interface Context {
repos: Repository[]; repos: Repository[];
@ -122,7 +130,7 @@ export class FetchGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as FetchStepState); void this.execute(state as FetchStepState);
} }
@ -156,7 +164,7 @@ export class FetchGitCommand extends QuickCommand {
? `$(repo) ${state.repos[0].formattedName}` ? `$(repo) ${state.repos[0].formattedName}`
: `${state.repos.length} repositories`; : `${state.repos.length} repositories`;
step = QuickCommand.createConfirmStep(
step = createConfirmStep(
appendReposToTitle(`Confirm ${this.title}`, state, context, lastFetchedOn), appendReposToTitle(`Confirm ${this.title}`, state, context, lastFetchedOn),
[ [
createFlagsQuickPickItem<Flags>(state.flags, [], { createFlagsQuickPickItem<Flags>(state.flags, [], {
@ -184,6 +192,6 @@ export class FetchGitCommand extends QuickCommand {
} }
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 2
- 2
src/commands/git/log.ts View File

@ -10,7 +10,7 @@ import { pad } from '../../system/string';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import { getSteps } from '../gitCommands.utils'; import { getSteps } from '../gitCommands.utils';
import type { PartialStepState, StepGenerator } from '../quickCommand'; import type { PartialStepState, StepGenerator } from '../quickCommand';
import { pickBranchOrTagStep, pickCommitStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import { endSteps , pickBranchOrTagStep, pickCommitStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
interface Context { interface Context {
repos: Repository[]; repos: Repository[];
@ -213,7 +213,7 @@ export class LogGitCommand extends QuickCommand {
state.counter--; state.counter--;
if (result === StepResult.Break) { if (result === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
} }
} }

+ 6
- 4
src/commands/git/merge.ts View File

@ -4,7 +4,7 @@ import type { GitLog } from '../../git/models/log';
import { GitReference, GitRevision } from '../../git/models/reference'; import { GitReference, GitRevision } from '../../git/models/reference';
import type { Repository } from '../../git/models/repository'; import type { Repository } from '../../git/models/repository';
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive'; import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
import { pluralize } from '../../system/string'; import { pluralize } from '../../system/string';
@ -19,6 +19,8 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
endSteps,
pickBranchOrTagStep, pickBranchOrTagStep,
pickCommitStep, pickCommitStep,
pickRepositoryStep, pickRepositoryStep,
@ -200,7 +202,7 @@ export class MergeGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as MergeStepState); this.execute(state as MergeStepState);
} }
@ -224,7 +226,7 @@ export class MergeGitCommand extends QuickCommand {
}), }),
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
QuickCommand.canPickStepContinue(step, state, selection);
canPickStepContinue(step, state, selection);
return StepResult.Break; return StepResult.Break;
} }
@ -271,6 +273,6 @@ export class MergeGitCommand extends QuickCommand {
], ],
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 4
- 2
src/commands/git/pull.ts View File

@ -21,6 +21,8 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
endSteps,
pickRepositoriesStep, pickRepositoriesStep,
QuickCommand, QuickCommand,
QuickCommandButtons, QuickCommandButtons,
@ -135,7 +137,7 @@ export class PullGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as PullStepState); void this.execute(state as PullStepState);
} }
@ -246,6 +248,6 @@ export class PullGitCommand extends QuickCommand {
} }
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 4
- 2
src/commands/git/push.ts View File

@ -22,6 +22,8 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
endSteps,
pickRepositoriesStep, pickRepositoriesStep,
pickRepositoryStep, pickRepositoryStep,
QuickCommand, QuickCommand,
@ -150,7 +152,7 @@ export class PushGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as State<Repository[]>); void this.execute(state as State<Repository[]>);
} }
@ -410,6 +412,6 @@ export class PushGitCommand extends QuickCommand {
} }
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 6
- 4
src/commands/git/rebase.ts View File

@ -4,7 +4,7 @@ import type { GitLog } from '../../git/models/log';
import { GitReference, GitRevision } from '../../git/models/reference'; import { GitReference, GitRevision } from '../../git/models/reference';
import type { Repository } from '../../git/models/repository'; import type { Repository } from '../../git/models/repository';
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive'; import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
import { pluralize } from '../../system/string'; import { pluralize } from '../../system/string';
@ -20,6 +20,8 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
endSteps,
pickBranchOrTagStep, pickBranchOrTagStep,
pickCommitStep, pickCommitStep,
pickRepositoryStep, pickRepositoryStep,
@ -209,7 +211,7 @@ export class RebaseGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as RebaseStepState); void this.execute(state as RebaseStepState);
} }
@ -236,7 +238,7 @@ export class RebaseGitCommand extends QuickCommand {
}), }),
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
QuickCommand.canPickStepContinue(step, state, selection);
canPickStepContinue(step, state, selection);
return StepResult.Break; return StepResult.Break;
} }
@ -260,6 +262,6 @@ export class RebaseGitCommand extends QuickCommand {
], ],
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 16
- 12
src/commands/git/remote.ts View File

@ -21,6 +21,10 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
createConfirmStep,
createPickStep,
endSteps,
inputRemoteNameStep, inputRemoteNameStep,
inputRemoteUrlStep, inputRemoteUrlStep,
pickRemoteStep, pickRemoteStep,
@ -233,7 +237,7 @@ export class RemoteGitCommand extends QuickCommand {
yield* this.removeCommandSteps(state, context); yield* this.removeCommandSteps(state, context);
break; break;
default: default:
QuickCommand.endSteps(state);
endSteps(state);
break; break;
} }
@ -247,7 +251,7 @@ export class RemoteGitCommand extends QuickCommand {
} }
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> { private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title, title: this.title,
placeholder: `Choose a ${this.label} command`, placeholder: `Choose a ${this.label} command`,
items: [ items: [
@ -273,7 +277,7 @@ export class RemoteGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back], buttons: [QuickInputButtons.Back],
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *addCommandSteps(state: AddStepState, context: Context): AsyncStepResultGenerator<void> { private async *addCommandSteps(state: AddStepState, context: Context): AsyncStepResultGenerator<void> {
@ -317,7 +321,7 @@ export class RemoteGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
await state.repo.addRemote(state.name, state.url, state.flags.includes('-f') ? { fetch: true } : undefined); await state.repo.addRemote(state.name, state.url, state.flags.includes('-f') ? { fetch: true } : undefined);
if (state.reveal !== false) { if (state.reveal !== false) {
@ -330,7 +334,7 @@ export class RemoteGitCommand extends QuickCommand {
} }
private *addCommandConfirmStep(state: AddStepState<AddState>, context: Context): StepResultGenerator<AddFlags[]> { private *addCommandConfirmStep(state: AddStepState<AddState>, context: Context): StepResultGenerator<AddFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<AddFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<AddFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
createFlagsQuickPickItem<AddFlags>(state.flags, [], { createFlagsQuickPickItem<AddFlags>(state.flags, [], {
@ -346,7 +350,7 @@ export class RemoteGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *removeCommandSteps(state: RemoveStepState, context: Context): AsyncStepResultGenerator<void> { private async *removeCommandSteps(state: RemoveStepState, context: Context): AsyncStepResultGenerator<void> {
@ -379,7 +383,7 @@ export class RemoteGitCommand extends QuickCommand {
const result = yield* this.removeCommandConfirmStep(state, context); const result = yield* this.removeCommandConfirmStep(state, context);
if (result === StepResult.Break) continue; if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
try { try {
await state.repo.removeRemote(state.remote.name); await state.repo.removeRemote(state.remote.name);
} catch (ex) { } catch (ex) {
@ -393,7 +397,7 @@ export class RemoteGitCommand extends QuickCommand {
state: RemoveStepState<ExcludeSome<RemoveState, 'remote', string>>, state: RemoveStepState<ExcludeSome<RemoveState, 'remote', string>>,
context: Context, context: Context,
): StepResultGenerator<void> { ): StepResultGenerator<void> {
const step: QuickPickStep<QuickPickItem> = QuickCommand.createConfirmStep(
const step: QuickPickStep<QuickPickItem> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
{ {
@ -404,7 +408,7 @@ export class RemoteGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
} }
private async *pruneCommandSteps(state: PruneStepState, context: Context): AsyncStepResultGenerator<void> { private async *pruneCommandSteps(state: PruneStepState, context: Context): AsyncStepResultGenerator<void> {
@ -435,7 +439,7 @@ export class RemoteGitCommand extends QuickCommand {
const result = yield* this.pruneCommandConfirmStep(state, context); const result = yield* this.pruneCommandConfirmStep(state, context);
if (result === StepResult.Break) continue; if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
void state.repo.pruneRemote(state.remote.name); void state.repo.pruneRemote(state.remote.name);
} }
} }
@ -444,7 +448,7 @@ export class RemoteGitCommand extends QuickCommand {
state: PruneStepState<ExcludeSome<PruneState, 'remote', string>>, state: PruneStepState<ExcludeSome<PruneState, 'remote', string>>,
context: Context, context: Context,
): StepResultGenerator<void> { ): StepResultGenerator<void> {
const step: QuickPickStep<QuickPickItem> = QuickCommand.createConfirmStep(
const step: QuickPickStep<QuickPickItem> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
{ {
@ -455,6 +459,6 @@ export class RemoteGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
} }
} }

+ 11
- 3
src/commands/git/reset.ts View File

@ -15,7 +15,15 @@ import type {
StepSelection, StepSelection,
StepState, StepState,
} from '../quickCommand'; } from '../quickCommand';
import { appendReposToTitle, pickCommitStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickCommitStep,
pickRepositoryStep,
QuickCommand,
StepResult,
} from '../quickCommand';
interface Context { interface Context {
repos: Repository[]; repos: Repository[];
@ -153,7 +161,7 @@ export class ResetGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as ResetStepState); this.execute(state as ResetStepState);
} }
@ -187,6 +195,6 @@ export class ResetGitCommand extends QuickCommand {
], ],
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 11
- 3
src/commands/git/revert.ts View File

@ -15,7 +15,15 @@ import type {
StepSelection, StepSelection,
StepState, StepState,
} from '../quickCommand'; } from '../quickCommand';
import { appendReposToTitle, pickCommitsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand';
import {
appendReposToTitle,
canPickStepContinue,
endSteps,
pickCommitsStep,
pickRepositoryStep,
QuickCommand,
StepResult,
} from '../quickCommand';
interface Context { interface Context {
repos: Repository[]; repos: Repository[];
@ -157,7 +165,7 @@ export class RevertGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
this.execute(state as RevertStepState<State<GitRevisionReference[]>>); this.execute(state as RevertStepState<State<GitRevisionReference[]>>);
} }
@ -181,6 +189,6 @@ export class RevertGitCommand extends QuickCommand {
], ],
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 6
- 3
src/commands/git/search.ts View File

@ -17,6 +17,9 @@ import { getSteps } from '../gitCommands.utils';
import type { PartialStepState, StepGenerator, StepResultGenerator, StepSelection, StepState } from '../quickCommand'; import type { PartialStepState, StepGenerator, StepResultGenerator, StepSelection, StepState } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
createPickStep,
endSteps,
pickCommitStep, pickCommitStep,
pickRepositoryStep, pickRepositoryStep,
QuickCommand, QuickCommand,
@ -266,7 +269,7 @@ export class SearchGitCommand extends QuickCommand {
state.counter--; state.counter--;
if (result === StepResult.Break) { if (result === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
} }
} }
@ -310,7 +313,7 @@ export class SearchGitCommand extends QuickCommand {
const matchAllButton = new QuickCommandButtons.MatchAllToggle(state.matchAll); const matchAllButton = new QuickCommandButtons.MatchAllToggle(state.matchAll);
const matchRegexButton = new QuickCommandButtons.MatchRegexToggle(state.matchRegex); const matchRegexButton = new QuickCommandButtons.MatchRegexToggle(state.matchRegex);
const step = QuickCommand.createPickStep<QuickPickItemOfT<SearchOperators>>({
const step = createPickStep<QuickPickItemOfT<SearchOperators>>({
title: appendReposToTitle(context.title, state, context), title: appendReposToTitle(context.title, state, context),
placeholder: 'e.g. "Updates dependencies" author:eamodio', placeholder: 'e.g. "Updates dependencies" author:eamodio',
matchOnDescription: true, matchOnDescription: true,
@ -386,7 +389,7 @@ export class SearchGitCommand extends QuickCommand {
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
if (!QuickCommand.canPickStepContinue(step, state, selection)) {
if (!canPickStepContinue(step, state, selection)) {
// Since we simulated a step above, we need to remove it here // Since we simulated a step above, we need to remove it here
state.counter--; state.counter--;
return StepResult.Break; return StepResult.Break;

+ 4
- 4
src/commands/git/show.ts View File

@ -8,7 +8,7 @@ import { CommandQuickPickItem } from '../../quickpicks/items/common';
import { GitCommandQuickPickItem } from '../../quickpicks/items/gitCommands'; import { GitCommandQuickPickItem } from '../../quickpicks/items/gitCommands';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type { PartialStepState, StepGenerator } from '../quickCommand'; import type { PartialStepState, StepGenerator } from '../quickCommand';
import {
import { endSteps ,
pickCommitStep, pickCommitStep,
pickRepositoryStep, pickRepositoryStep,
QuickCommand, QuickCommand,
@ -186,14 +186,14 @@ export class ShowGitCommand extends QuickCommand {
const r = yield* result.executeSteps(this.pickedVia); const r = yield* result.executeSteps(this.pickedVia);
state.counter--; state.counter--;
if (r === StepResult.Break) { if (r === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
} }
continue; continue;
} }
if (result instanceof CommandQuickPickItem && !(result instanceof CommitFilesQuickPickItem)) { if (result instanceof CommandQuickPickItem && !(result instanceof CommitFilesQuickPickItem)) {
QuickCommand.endSteps(state);
endSteps(state);
void result.execute(); void result.execute();
break; break;
@ -236,7 +236,7 @@ export class ShowGitCommand extends QuickCommand {
} }
if (result instanceof CommandQuickPickItem) { if (result instanceof CommandQuickPickItem) {
QuickCommand.endSteps(state);
endSteps(state);
void result.execute(); void result.execute();
break; break;

+ 18
- 15
src/commands/git/stash.ts View File

@ -29,6 +29,12 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createInputStep,
createPickStep,
endSteps,
pickRepositoryStep, pickRepositoryStep,
pickStashStep, pickStashStep,
QuickCommand, QuickCommand,
@ -219,7 +225,7 @@ export class StashGitCommand extends QuickCommand {
yield* this.pushCommandSteps(state as PushStepState, context); yield* this.pushCommandSteps(state as PushStepState, context);
break; break;
default: default:
QuickCommand.endSteps(state);
endSteps(state);
break; break;
} }
@ -233,7 +239,7 @@ export class StashGitCommand extends QuickCommand {
} }
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> { private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title, title: this.title,
placeholder: `Choose a ${this.label} command`, placeholder: `Choose a ${this.label} command`,
items: [ items: [
@ -273,7 +279,7 @@ export class StashGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back], buttons: [QuickInputButtons.Back],
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *applyOrPopCommandSteps(state: ApplyStepState | PopStepState, context: Context): StepGenerator { private async *applyOrPopCommandSteps(state: ApplyStepState | PopStepState, context: Context): StepGenerator {
@ -300,7 +306,7 @@ export class StashGitCommand extends QuickCommand {
state.subcommand = result; state.subcommand = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
try { try {
await state.repo.stashApply( await state.repo.stashApply(
@ -382,7 +388,7 @@ export class StashGitCommand extends QuickCommand {
}, },
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *dropCommandSteps(state: DropStepState, context: Context): StepGenerator { private async *dropCommandSteps(state: DropStepState, context: Context): StepGenerator {
@ -403,7 +409,7 @@ export class StashGitCommand extends QuickCommand {
const result = yield* this.dropCommandConfirmStep(state, context); const result = yield* this.dropCommandConfirmStep(state, context);
if (result === StepResult.Break) continue; if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
try { try {
// drop can only take a stash index, e.g. `stash@{1}` // drop can only take a stash index, e.g. `stash@{1}`
await state.repo.stashDelete(`stash@{${state.reference.number}}`, state.reference.ref); await state.repo.stashDelete(`stash@{${state.reference.number}}`, state.reference.ref);
@ -446,7 +452,7 @@ export class StashGitCommand extends QuickCommand {
}, },
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
} }
private async *listCommandSteps(state: ListStepState, context: Context): StepGenerator { private async *listCommandSteps(state: ListStepState, context: Context): StepGenerator {
@ -479,7 +485,7 @@ export class StashGitCommand extends QuickCommand {
); );
state.counter--; state.counter--;
if (result === StepResult.Break) { if (result === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
} }
} }
} }
@ -510,7 +516,7 @@ export class StashGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
try { try {
await state.repo.stashSave(state.message, state.uris, { await state.repo.stashSave(state.message, state.uris, {
includeUntracked: state.flags.includes('--include-untracked'), includeUntracked: state.flags.includes('--include-untracked'),
@ -537,7 +543,7 @@ export class StashGitCommand extends QuickCommand {
state: PushStepState, state: PushStepState,
context: Context, context: Context,
): AsyncStepResultGenerator<string> { ): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle( title: appendReposToTitle(
context.title, context.title,
state, state,
@ -556,10 +562,7 @@ export class StashGitCommand extends QuickCommand {
}); });
const value: StepSelection<typeof step> = yield step; const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break; return StepResult.Break;
} }
@ -608,6 +611,6 @@ export class StashGitCommand extends QuickCommand {
{ placeholder: `Confirm ${context.title}` }, { placeholder: `Confirm ${context.title}` },
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 3
- 3
src/commands/git/status.ts View File

@ -8,7 +8,7 @@ import { GitCommandQuickPickItem } from '../../quickpicks/items/gitCommands';
import { pad } from '../../system/string'; import { pad } from '../../system/string';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type { PartialStepState, StepGenerator, StepState } from '../quickCommand'; import type { PartialStepState, StepGenerator, StepState } from '../quickCommand';
import { pickRepositoryStep, QuickCommand, showRepositoryStatusStep, StepResult } from '../quickCommand';
import { endSteps, pickRepositoryStep, QuickCommand, showRepositoryStatusStep, StepResult } from '../quickCommand';
interface Context { interface Context {
repos: Repository[]; repos: Repository[];
@ -109,14 +109,14 @@ export class StatusGitCommand extends QuickCommand {
const r = yield* result.executeSteps(this.pickedVia); const r = yield* result.executeSteps(this.pickedVia);
state.counter--; state.counter--;
if (r === StepResult.Break) { if (r === StepResult.Break) {
QuickCommand.endSteps(state);
endSteps(state);
} }
continue; continue;
} }
if (result instanceof CommandQuickPickItem) { if (result instanceof CommandQuickPickItem) {
QuickCommand.endSteps(state);
endSteps(state);
void result.execute(); void result.execute();
break; break;

+ 4
- 2
src/commands/git/switch.ts View File

@ -16,6 +16,8 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canPickStepContinue,
endSteps,
inputBranchNameStep, inputBranchNameStep,
pickBranchOrTagStepMultiRepo, pickBranchOrTagStepMultiRepo,
pickRepositoriesStep, pickRepositoriesStep,
@ -191,7 +193,7 @@ export class SwitchGitCommand extends QuickCommand {
} }
} }
QuickCommand.endSteps(state);
endSteps(state);
void this.execute(state as SwitchStepState); void this.execute(state as SwitchStepState);
} }
@ -244,6 +246,6 @@ export class SwitchGitCommand extends QuickCommand {
{ placeholder: `Confirm ${context.title}` }, { placeholder: `Confirm ${context.title}` },
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 18
- 14
src/commands/git/tag.ts View File

@ -20,6 +20,13 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createConfirmStep,
createInputStep,
createPickStep,
endSteps,
inputTagNameStep, inputTagNameStep,
pickBranchOrTagStep, pickBranchOrTagStep,
pickRepositoryStep, pickRepositoryStep,
@ -186,7 +193,7 @@ export class TagGitCommand extends QuickCommand {
yield* this.deleteCommandSteps(state as DeleteStepState, context); yield* this.deleteCommandSteps(state as DeleteStepState, context);
break; break;
default: default:
QuickCommand.endSteps(state);
endSteps(state);
break; break;
} }
@ -200,7 +207,7 @@ export class TagGitCommand extends QuickCommand {
} }
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> { private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title, title: this.title,
placeholder: `Choose a ${this.label} command`, placeholder: `Choose a ${this.label} command`,
items: [ items: [
@ -220,7 +227,7 @@ export class TagGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back], buttons: [QuickInputButtons.Back],
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> { private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> {
@ -272,7 +279,7 @@ export class TagGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
} }
QuickCommand.endSteps(state);
endSteps(state);
state.repo.tag( state.repo.tag(
...state.flags, ...state.flags,
...(state.message.length !== 0 ? [`"${state.message}"`] : []), ...(state.message.length !== 0 ? [`"${state.message}"`] : []),
@ -286,7 +293,7 @@ export class TagGitCommand extends QuickCommand {
state: CreateStepState, state: CreateStepState,
context: Context, context: Context,
): AsyncStepResultGenerator<string> { ): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle( title: appendReposToTitle(
`${context.title} at ${GitReference.toString(state.reference, { capitalize: true, icon: false })}`, `${context.title} at ${GitReference.toString(state.reference, { capitalize: true, icon: false })}`,
state, state,
@ -299,10 +306,7 @@ export class TagGitCommand extends QuickCommand {
const value: StepSelection<typeof step> = yield step; const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break; return StepResult.Break;
} }
@ -313,7 +317,7 @@ export class TagGitCommand extends QuickCommand {
state: CreateStepState<CreateState>, state: CreateStepState<CreateState>,
context: Context, context: Context,
): StepResultGenerator<CreateFlags[]> { ): StepResultGenerator<CreateFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
createFlagsQuickPickItem<CreateFlags>(state.flags, state.message.length !== 0 ? ['-m'] : [], { createFlagsQuickPickItem<CreateFlags>(state.flags, state.message.length !== 0 ? ['-m'] : [], {
@ -336,7 +340,7 @@ export class TagGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *deleteCommandSteps(state: DeleteStepState, context: Context): StepGenerator { private async *deleteCommandSteps(state: DeleteStepState, context: Context): StepGenerator {
@ -363,7 +367,7 @@ export class TagGitCommand extends QuickCommand {
const result = yield* this.deleteCommandConfirmStep(state, context); const result = yield* this.deleteCommandConfirmStep(state, context);
if (result === StepResult.Break) continue; if (result === StepResult.Break) continue;
QuickCommand.endSteps(state);
endSteps(state);
state.repo.tagDelete(state.references); state.repo.tagDelete(state.references);
} }
} }
@ -372,7 +376,7 @@ export class TagGitCommand extends QuickCommand {
state: DeleteStepState<DeleteState>, state: DeleteStepState<DeleteState>,
context: Context, context: Context,
): StepResultGenerator<void> { ): StepResultGenerator<void> {
const step: QuickPickStep<QuickPickItem> = QuickCommand.createConfirmStep(
const step: QuickPickStep<QuickPickItem> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
{ {
@ -383,6 +387,6 @@ export class TagGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
} }
} }

+ 21
- 17
src/commands/git/worktree.ts View File

@ -36,6 +36,13 @@ import type {
} from '../quickCommand'; } from '../quickCommand';
import { import {
appendReposToTitle, appendReposToTitle,
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createConfirmStep,
createCustomStep,
createPickStep,
endSteps,
ensureAccessStep, ensureAccessStep,
inputBranchNameStep, inputBranchNameStep,
pickBranchOrTagStep, pickBranchOrTagStep,
@ -238,7 +245,7 @@ export class WorktreeGitCommand extends QuickCommand {
break; break;
} }
default: default:
QuickCommand.endSteps(state);
endSteps(state);
break; break;
} }
@ -252,7 +259,7 @@ export class WorktreeGitCommand extends QuickCommand {
} }
private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> { private *pickSubcommandStep(state: PartialStepState<State>): StepResultGenerator<State['subcommand']> {
const step = QuickCommand.createPickStep<QuickPickItemOfT<State['subcommand']>>({
const step = createPickStep<QuickPickItemOfT<State['subcommand']>>({
title: this.title, title: this.title,
placeholder: `Choose a ${this.label} command`, placeholder: `Choose a ${this.label} command`,
items: [ items: [
@ -278,7 +285,7 @@ export class WorktreeGitCommand extends QuickCommand {
buttons: [QuickInputButtons.Back], buttons: [QuickInputButtons.Back],
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> { private async *createCommandSteps(state: CreateStepState, context: Context): AsyncStepResultGenerator<void> {
@ -487,7 +494,7 @@ export class WorktreeGitCommand extends QuickCommand {
} }
} }
QuickCommand.endSteps(state);
endSteps(state);
} }
} }
@ -496,7 +503,7 @@ export class WorktreeGitCommand extends QuickCommand {
context: Context, context: Context,
options: { titleContext: string; defaultUri?: Uri }, options: { titleContext: string; defaultUri?: Uri },
): AsyncStepResultGenerator<Uri> { ): AsyncStepResultGenerator<Uri> {
const step = QuickCommand.createCustomStep<Uri>({
const step = createCustomStep<Uri>({
show: async (_step: CustomStep<Uri>) => { show: async (_step: CustomStep<Uri>) => {
const hasDefault = options?.defaultUri != null; const hasDefault = options?.defaultUri != null;
const result = await window.showInformationMessage( const result = await window.showInformationMessage(
@ -526,10 +533,7 @@ export class WorktreeGitCommand extends QuickCommand {
const value: StepSelection<typeof step> = yield step; const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break; return StepResult.Break;
} }
@ -587,7 +591,7 @@ export class WorktreeGitCommand extends QuickCommand {
const isRemoteBranch = state.reference?.refType === 'branch' && state.reference?.remote; const isRemoteBranch = state.reference?.refType === 'branch' && state.reference?.remote;
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags, Uri>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags, Uri>> = createConfirmStep(
appendReposToTitle( appendReposToTitle(
`Confirm ${context.title} \u2022 ${GitReference.toString(state.reference, { `Confirm ${context.title} \u2022 ${GitReference.toString(state.reference, {
icon: false, icon: false,
@ -650,7 +654,7 @@ export class WorktreeGitCommand extends QuickCommand {
context, context,
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection)
return canPickStepContinue(step, state, selection)
? [selection[0].context, selection[0].item] ? [selection[0].context, selection[0].item]
: StepResult.Break; : StepResult.Break;
} }
@ -685,7 +689,7 @@ export class WorktreeGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
for (const uri of state.uris) { for (const uri of state.uris) {
let retry = false; let retry = false;
@ -743,7 +747,7 @@ export class WorktreeGitCommand extends QuickCommand {
} }
private *deleteCommandConfirmStep(state: DeleteStepState, context: Context): StepResultGenerator<DeleteFlags[]> { private *deleteCommandConfirmStep(state: DeleteStepState, context: Context): StepResultGenerator<DeleteFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<DeleteFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
createFlagsQuickPickItem<DeleteFlags>(state.flags, [], { createFlagsQuickPickItem<DeleteFlags>(state.flags, [], {
@ -766,7 +770,7 @@ export class WorktreeGitCommand extends QuickCommand {
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
private async *openCommandSteps(state: OpenStepState, context: Context): StepGenerator { private async *openCommandSteps(state: OpenStepState, context: Context): StepGenerator {
@ -798,7 +802,7 @@ export class WorktreeGitCommand extends QuickCommand {
state.flags = result; state.flags = result;
QuickCommand.endSteps(state);
endSteps(state);
const worktree = context.worktrees.find(wt => wt.uri.toString() === state.uri.toString())!; const worktree = context.worktrees.find(wt => wt.uri.toString() === state.uri.toString())!;
if (state.flags.includes('--reveal-explorer')) { if (state.flags.includes('--reveal-explorer')) {
@ -814,7 +818,7 @@ export class WorktreeGitCommand extends QuickCommand {
} }
private *openCommandConfirmStep(state: OpenStepState, context: Context): StepResultGenerator<OpenFlags[]> { private *openCommandConfirmStep(state: OpenStepState, context: Context): StepResultGenerator<OpenFlags[]> {
const step: QuickPickStep<FlagsQuickPickItem<OpenFlags>> = QuickCommand.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<OpenFlags>> = createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context), appendReposToTitle(`Confirm ${context.title}`, state, context),
[ [
createFlagsQuickPickItem<OpenFlags>(state.flags, [], { createFlagsQuickPickItem<OpenFlags>(state.flags, [], {
@ -840,6 +844,6 @@ export class WorktreeGitCommand extends QuickCommand {
); );
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
} }

+ 5
- 5
src/commands/gitCommands.ts View File

@ -31,8 +31,8 @@ import type { SwitchGitCommandArgs } from './git/switch';
import type { TagGitCommandArgs } from './git/tag'; import type { TagGitCommandArgs } from './git/tag';
import type { WorktreeGitCommandArgs } from './git/worktree'; import type { WorktreeGitCommandArgs } from './git/worktree';
import { PickCommandStep } from './gitCommands.utils'; import { PickCommandStep } from './gitCommands.utils';
import type { CustomStep, QuickInputStep, QuickPickStep, StepSelection } from './quickCommand';
import { isCustomStep, isQuickInputStep, isQuickPickStep, QuickCommand, StepResult } from './quickCommand';
import type { CustomStep, QuickCommand, QuickInputStep, QuickPickStep, StepSelection } from './quickCommand';
import { isCustomStep , isQuickCommand, isQuickInputStep, isQuickPickStep, StepResult } from './quickCommand';
import { QuickCommandButtons, ToggleQuickInputButton } from './quickCommand.buttons'; import { QuickCommandButtons, ToggleQuickInputButton } from './quickCommand.buttons';
const sanitizeLabel = /\$\(.+?\)|\s/g; const sanitizeLabel = /\$\(.+?\)|\s/g;
@ -538,7 +538,7 @@ export class GitCommandsCommand extends Command {
let activeCommand; let activeCommand;
if (commandsStep.command == null && quickpick.activeItems.length !== 0) { if (commandsStep.command == null && quickpick.activeItems.length !== 0) {
const active = quickpick.activeItems[0]; const active = quickpick.activeItems[0];
if (QuickCommand.is(active)) {
if (isQuickCommand(active)) {
activeCommand = active; activeCommand = active;
} }
} }
@ -657,7 +657,7 @@ export class GitCommandsCommand extends Command {
if (commandsStep.command != null || quickpick.activeItems.length === 0) return; if (commandsStep.command != null || quickpick.activeItems.length === 0) return;
const command = quickpick.activeItems[0]; const command = quickpick.activeItems[0];
if (!QuickCommand.is(command)) return;
if (!isQuickCommand(command)) return;
quickpick.buttons = this.getButtons(undefined, command); quickpick.buttons = this.getButtons(undefined, command);
}), }),
@ -744,7 +744,7 @@ export class GitCommandsCommand extends Command {
if (commandsStep.command == null) { if (commandsStep.command == null) {
const [command] = items; const [command] = items;
if (!QuickCommand.is(command)) return;
if (!isQuickCommand(command)) return;
commandsStep.setCommand(command, this.startedWith); commandsStep.setCommand(command, this.startedWith);
} }

+ 59
- 62
src/commands/quickCommand.steps.ts View File

@ -99,7 +99,16 @@ import type {
StepSelection, StepSelection,
StepState, StepState,
} from './quickCommand'; } from './quickCommand';
import { QuickCommand, QuickCommandButtons, StepResult } from './quickCommand';
import {
canInputStepContinue,
canPickStepContinue,
canStepContinue,
createInputStep,
createPickStep,
endSteps,
QuickCommandButtons,
StepResult,
} from './quickCommand';
export function appendReposToTitle< export function appendReposToTitle<
State extends { repo: Repository } | { repos: Repository[] }, State extends { repo: Repository } | { repos: Repository[] },
@ -485,7 +494,7 @@ export async function* inputBranchNameStep<
context: Context, context: Context,
options: { placeholder: string; titleContext?: string; value?: string }, options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> { ): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder, placeholder: options.placeholder,
value: options.value, value: options.value,
@ -515,10 +524,7 @@ export async function* inputBranchNameStep<
}); });
const value: StepSelection<typeof step> = yield step; const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break; return StepResult.Break;
} }
@ -533,7 +539,7 @@ export async function* inputRemoteNameStep<
context: Context, context: Context,
options: { placeholder: string; titleContext?: string; value?: string }, options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> { ): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder, placeholder: options.placeholder,
value: options.value, value: options.value,
@ -559,10 +565,7 @@ export async function* inputRemoteNameStep<
}); });
const value: StepSelection<typeof step> = yield step; const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break; return StepResult.Break;
} }
@ -577,7 +580,7 @@ export async function* inputRemoteUrlStep<
context: Context, context: Context,
options: { placeholder: string; titleContext?: string; value?: string }, options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> { ): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder, placeholder: options.placeholder,
value: options.value, value: options.value,
@ -594,10 +597,7 @@ export async function* inputRemoteUrlStep<
}); });
const value: StepSelection<typeof step> = yield step; const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break; return StepResult.Break;
} }
@ -612,7 +612,7 @@ export async function* inputTagNameStep<
context: Context, context: Context,
options: { placeholder: string; titleContext?: string; value?: string }, options: { placeholder: string; titleContext?: string; value?: string },
): AsyncStepResultGenerator<string> { ): AsyncStepResultGenerator<string> {
const step = QuickCommand.createInputStep({
const step = createInputStep({
title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context),
placeholder: options.placeholder, placeholder: options.placeholder,
value: options.value, value: options.value,
@ -642,10 +642,7 @@ export async function* inputTagNameStep<
}); });
const value: StepSelection<typeof step> = yield step; const value: StepSelection<typeof step> = yield step;
if (
!QuickCommand.canStepContinue(step, state, value) ||
!(await QuickCommand.canInputStepContinue(step, state, value))
) {
if (!canStepContinue(step, state, value) || !(await canInputStepContinue(step, state, value))) {
return StepResult.Break; return StepResult.Break;
} }
@ -676,7 +673,7 @@ export async function* pickBranchStep<
picked: picked, picked: picked,
}); });
const step = QuickCommand.createPickStep<BranchQuickPickItem>({
const step = createPickStep<BranchQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder, placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder,
matchOnDetail: true, matchOnDetail: true,
@ -701,7 +698,7 @@ export async function* pickBranchStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
export async function* pickBranchesStep< export async function* pickBranchesStep<
@ -731,7 +728,7 @@ export async function* pickBranchesStep<
sort: sort, sort: sort,
}); });
const step = QuickCommand.createPickStep<BranchQuickPickItem>({
const step = createPickStep<BranchQuickPickItem>({
multiselect: branches.length !== 0, multiselect: branches.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder, placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder,
@ -757,7 +754,7 @@ export async function* pickBranchesStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
} }
export async function* pickBranchOrTagStep< export async function* pickBranchOrTagStep<
@ -801,7 +798,7 @@ export async function* pickBranchOrTagStep<
}; };
const branchesAndOrTags = await getBranchesAndOrTagsFn(); const branchesAndOrTags = await getBranchesAndOrTagsFn();
const step = QuickCommand.createPickStep<ReferencesQuickPickItem>({
const step = createPickStep<ReferencesQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: placeholder:
branchesAndOrTags.length === 0 branchesAndOrTags.length === 0
@ -872,7 +869,7 @@ export async function* pickBranchOrTagStep<
onValidateValue: getValidateGitReferenceFn(state.repo, { ranges: ranges }), onValidateValue: getValidateGitReferenceFn(state.repo, { ranges: ranges }),
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
export async function* pickBranchOrTagStepMultiRepo< export async function* pickBranchOrTagStepMultiRepo<
@ -910,7 +907,7 @@ export async function* pickBranchOrTagStepMultiRepo<
}; };
const branchesAndOrTags = await getBranchesAndOrTagsFn(); const branchesAndOrTags = await getBranchesAndOrTagsFn();
const step = QuickCommand.createPickStep<ReferencesQuickPickItem>({
const step = createPickStep<ReferencesQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: placeholder:
branchesAndOrTags.length === 0 branchesAndOrTags.length === 0
@ -986,7 +983,7 @@ export async function* pickBranchOrTagStepMultiRepo<
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
export async function* pickCommitStep< export async function* pickCommitStep<
@ -1038,7 +1035,7 @@ export async function* pickCommitStep<
]; ];
} }
const step = QuickCommand.createPickStep<CommandQuickPickItem | CommitQuickPickItem>({
const step = createPickStep<CommandQuickPickItem | CommitQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log), placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log),
ignoreFocusOut: ignoreFocusOut, ignoreFocusOut: ignoreFocusOut,
@ -1111,10 +1108,10 @@ export async function* pickCommitStep<
}), }),
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
if (!QuickCommand.canPickStepContinue(step, state, selection)) return StepResult.Break;
if (!canPickStepContinue(step, state, selection)) return StepResult.Break;
if (CommandQuickPickItem.is(selection[0])) { if (CommandQuickPickItem.is(selection[0])) {
QuickCommand.endSteps(state);
endSteps(state);
await selection[0].execute(); await selection[0].execute();
return StepResult.Break; return StepResult.Break;
@ -1164,7 +1161,7 @@ export function* pickCommitsStep<
]; ];
} }
const step = QuickCommand.createPickStep<CommitQuickPickItem>({
const step = createPickStep<CommitQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
multiselect: log != null, multiselect: log != null,
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log), placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log),
@ -1215,7 +1212,7 @@ export function* pickCommitsStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
} }
export async function* pickContributorsStep< export async function* pickContributorsStep<
@ -1228,7 +1225,7 @@ export async function* pickContributorsStep<
): AsyncStepResultGenerator<GitContributor[]> { ): AsyncStepResultGenerator<GitContributor[]> {
const message = (await Container.instance.git.getOrOpenScmRepository(state.repo.path))?.inputBox.value; const message = (await Container.instance.git.getOrOpenScmRepository(state.repo.path))?.inputBox.value;
const step = QuickCommand.createPickStep<ContributorQuickPickItem>({
const step = createPickStep<ContributorQuickPickItem>({
title: appendReposToTitle(context.title, state, context), title: appendReposToTitle(context.title, state, context),
allowEmpty: true, allowEmpty: true,
multiselect: true, multiselect: true,
@ -1256,7 +1253,7 @@ export async function* pickContributorsStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
} }
export async function* pickRemoteStep< export async function* pickRemoteStep<
@ -1283,7 +1280,7 @@ export async function* pickRemoteStep<
picked: picked, picked: picked,
}); });
const step = QuickCommand.createPickStep<RemoteQuickPickItem>({
const step = createPickStep<RemoteQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder, placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder,
matchOnDetail: true, matchOnDetail: true,
@ -1308,7 +1305,7 @@ export async function* pickRemoteStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
export async function* pickRemotesStep< export async function* pickRemotesStep<
@ -1335,7 +1332,7 @@ export async function* pickRemotesStep<
picked: picked, picked: picked,
}); });
const step = QuickCommand.createPickStep<RemoteQuickPickItem>({
const step = createPickStep<RemoteQuickPickItem>({
multiselect: remotes.length !== 0, multiselect: remotes.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder, placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder,
@ -1361,7 +1358,7 @@ export async function* pickRemotesStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
} }
export async function* pickRepositoryStep< export async function* pickRepositoryStep<
@ -1374,7 +1371,7 @@ export async function* pickRepositoryStep<
} }
const active = state.repo ?? (await Container.instance.git.getOrOpenRepositoryForEditor()); const active = state.repo ?? (await Container.instance.git.getOrOpenRepositoryForEditor());
const step = QuickCommand.createPickStep<RepositoryQuickPickItem>({
const step = createPickStep<RepositoryQuickPickItem>({
title: context.title, title: context.title,
placeholder: placeholder, placeholder: placeholder,
items: items:
@ -1411,7 +1408,7 @@ export async function* pickRepositoryStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
export async function* pickRepositoriesStep< export async function* pickRepositoriesStep<
@ -1439,7 +1436,7 @@ export async function* pickRepositoriesStep<
actives = active != null ? [active] : []; actives = active != null ? [active] : [];
} }
const step = QuickCommand.createPickStep<RepositoryQuickPickItem>({
const step = createPickStep<RepositoryQuickPickItem>({
multiselect: true, multiselect: true,
title: context.title, title: context.title,
placeholder: options.placeholder, placeholder: options.placeholder,
@ -1481,7 +1478,7 @@ export async function* pickRepositoriesStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
} }
export function* pickStashStep< export function* pickStashStep<
@ -1504,7 +1501,7 @@ export function* pickStashStep<
titleContext?: string; titleContext?: string;
}, },
): StepResultGenerator<GitStashCommit> { ): StepResultGenerator<GitStashCommit> {
const step = QuickCommand.createPickStep<CommitQuickPickItem<GitStashCommit>>({
const step = createPickStep<CommitQuickPickItem<GitStashCommit>>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, stash), placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, stash),
ignoreFocusOut: ignoreFocusOut, ignoreFocusOut: ignoreFocusOut,
@ -1540,7 +1537,7 @@ export function* pickStashStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
export async function* pickTagsStep< export async function* pickTagsStep<
@ -1567,7 +1564,7 @@ export async function* pickTagsStep<
picked: picked, picked: picked,
}); });
const step = QuickCommand.createPickStep<TagQuickPickItem>({
const step = createPickStep<TagQuickPickItem>({
multiselect: tags.length !== 0, multiselect: tags.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: tags.length === 0 ? `No tags found in ${state.repo.formattedName}` : placeholder, placeholder: tags.length === 0 ? `No tags found in ${state.repo.formattedName}` : placeholder,
@ -1597,7 +1594,7 @@ export async function* pickTagsStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
} }
export async function* pickWorktreeStep< export async function* pickWorktreeStep<
@ -1627,7 +1624,7 @@ export async function* pickWorktreeStep<
picked: picked, picked: picked,
}); });
const step = QuickCommand.createPickStep<WorktreeQuickPickItem>({
const step = createPickStep<WorktreeQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder, placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder,
matchOnDetail: true, matchOnDetail: true,
@ -1657,7 +1654,7 @@ export async function* pickWorktreeStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
} }
export async function* pickWorktreesStep< export async function* pickWorktreesStep<
@ -1687,7 +1684,7 @@ export async function* pickWorktreesStep<
picked: picked, picked: picked,
}); });
const step = QuickCommand.createPickStep<WorktreeQuickPickItem>({
const step = createPickStep<WorktreeQuickPickItem>({
multiselect: worktrees.length !== 0, multiselect: worktrees.length !== 0,
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder, placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder,
@ -1718,7 +1715,7 @@ export async function* pickWorktreesStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection.map(i => i.item) : StepResult.Break;
} }
export async function* showCommitOrStashStep< export async function* showCommitOrStashStep<
@ -1729,7 +1726,7 @@ export async function* showCommitOrStashStep<
context: Context, context: Context,
): AsyncStepResultGenerator<CommitFilesQuickPickItem | GitCommandQuickPickItem | CommandQuickPickItem> { ): AsyncStepResultGenerator<CommitFilesQuickPickItem | GitCommandQuickPickItem | CommandQuickPickItem> {
const step: QuickPickStep<CommitFilesQuickPickItem | GitCommandQuickPickItem | CommandQuickPickItem> = const step: QuickPickStep<CommitFilesQuickPickItem | GitCommandQuickPickItem | CommandQuickPickItem> =
QuickCommand.createPickStep({
createPickStep({
title: appendReposToTitle( title: appendReposToTitle(
GitReference.toString(state.reference, { GitReference.toString(state.reference, {
capitalize: true, capitalize: true,
@ -1779,7 +1776,7 @@ export async function* showCommitOrStashStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
} }
async function getShowCommitOrStashStepItems< async function getShowCommitOrStashStepItems<
@ -2003,7 +2000,7 @@ export function* showCommitOrStashFilesStep<
debugger; debugger;
} }
const step: QuickPickStep<CommitFilesQuickPickItem | CommitFileQuickPickItem> = QuickCommand.createPickStep({
const step: QuickPickStep<CommitFilesQuickPickItem | CommitFileQuickPickItem> = createPickStep({
title: appendReposToTitle( title: appendReposToTitle(
GitReference.toString(state.reference, { GitReference.toString(state.reference, {
capitalize: true, capitalize: true,
@ -2063,7 +2060,7 @@ export function* showCommitOrStashFilesStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
} }
export async function* showCommitOrStashFileStep< export async function* showCommitOrStashFileStep<
@ -2074,7 +2071,7 @@ export async function* showCommitOrStashFileStep<
}, },
Context extends { repos: Repository[]; title: string }, Context extends { repos: Repository[]; title: string },
>(state: State, context: Context): AsyncStepResultGenerator<CommandQuickPickItem> { >(state: State, context: Context): AsyncStepResultGenerator<CommandQuickPickItem> {
const step: QuickPickStep<CommandQuickPickItem> = QuickCommand.createPickStep<CommandQuickPickItem>({
const step: QuickPickStep<CommandQuickPickItem> = createPickStep<CommandQuickPickItem>({
title: appendReposToTitle( title: appendReposToTitle(
GitReference.toString(state.reference, { GitReference.toString(state.reference, {
capitalize: true, capitalize: true,
@ -2130,7 +2127,7 @@ export async function* showCommitOrStashFileStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
} }
async function getShowCommitOrStashFileStepItems< async function getShowCommitOrStashFileStepItems<
@ -2242,7 +2239,7 @@ export function* showRepositoryStatusStep<
>(state: State, context: Context): StepResultGenerator<CommandQuickPickItem> { >(state: State, context: Context): StepResultGenerator<CommandQuickPickItem> {
const upstream = context.status.getUpstreamStatus({ expand: true, separator: ', ' }); const upstream = context.status.getUpstreamStatus({ expand: true, separator: ', ' });
const working = context.status.getFormattedDiffStatus({ expand: true, separator: ', ' }); const working = context.status.getFormattedDiffStatus({ expand: true, separator: ', ' });
const step: QuickPickStep<CommandQuickPickItem> = QuickCommand.createPickStep<CommandQuickPickItem>({
const step: QuickPickStep<CommandQuickPickItem> = createPickStep<CommandQuickPickItem>({
title: appendReposToTitle(context.title, state, context), title: appendReposToTitle(context.title, state, context),
placeholder: `${upstream ? `${upstream}, ${working}` : working}`, //'Changes to be committed', placeholder: `${upstream ? `${upstream}, ${working}` : working}`, //'Changes to be committed',
ignoreFocusOut: true, ignoreFocusOut: true,
@ -2255,7 +2252,7 @@ export function* showRepositoryStatusStep<
}, },
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break;
} }
function getShowRepositoryStatusStepItems< function getShowRepositoryStatusStepItems<
@ -2415,12 +2412,12 @@ export async function* ensureAccessStep<
} }
} }
const step = QuickCommand.createPickStep<DirectiveQuickPickItem>({
const step = createPickStep<DirectiveQuickPickItem>({
title: appendReposToTitle(context.title, state, context), title: appendReposToTitle(context.title, state, context),
placeholder: placeholder, placeholder: placeholder,
items: [...directives, createDirectiveQuickPickItem(Directive.Cancel)], items: [...directives, createDirectiveQuickPickItem(Directive.Cancel)],
}); });
const selection: StepSelection<typeof step> = yield step; const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
} }

+ 83
- 85
src/commands/quickCommand.ts View File

@ -3,7 +3,7 @@ import { configuration } from '../configuration';
import type { Container } from '../container'; import type { Container } from '../container';
import type { Keys } from '../keyboard'; import type { Keys } from '../keyboard';
import type { DirectiveQuickPickItem } from '../quickpicks/items/directive'; import type { DirectiveQuickPickItem } from '../quickpicks/items/directive';
import { createDirectiveQuickPickItem , Directive, isDirective } from '../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive, isDirective } from '../quickpicks/items/directive';
export * from './quickCommand.buttons'; export * from './quickCommand.buttons';
export * from './quickCommand.steps'; export * from './quickCommand.steps';
@ -243,7 +243,7 @@ export abstract class QuickCommand implements QuickPickItem {
cancel?: DirectiveQuickPickItem, cancel?: DirectiveQuickPickItem,
options: Partial<QuickPickStep<T>> = {}, options: Partial<QuickPickStep<T>> = {},
): QuickPickStep<T> { ): QuickPickStep<T> {
return QuickCommand.createConfirmStep(title, confirmations, { title: this.title }, cancel, options);
return createConfirmStep(title, confirmations, { title: this.title }, cancel, options);
} }
protected getStepState(limitBackNavigation: boolean): PartialStepState<State> { protected getStepState(limitBackNavigation: boolean): PartialStepState<State> {
@ -257,103 +257,101 @@ export abstract class QuickCommand implements QuickPickItem {
} }
} }
export namespace QuickCommand {
export function is(item: QuickPickItem): item is QuickCommand {
return item instanceof QuickCommand;
export function isQuickCommand(item: QuickPickItem): item is QuickCommand {
return item instanceof QuickCommand;
}
export async function canInputStepContinue<T extends QuickInputStep>(
step: T,
state: PartialStepState,
value: Directive | StepItemType<T>,
) {
if (!canStepContinue(step, state, value)) return false;
const [valid] = (await step.validate?.(value)) ?? [true];
if (valid) {
state.counter++;
return true;
} }
export async function canInputStepContinue<T extends QuickInputStep>(
step: T,
state: PartialStepState,
value: Directive | StepItemType<T>,
) {
if (!canStepContinue(step, state, value)) return false;
return false;
}
const [valid] = (await step.validate?.(value)) ?? [true];
if (valid) {
state.counter++;
return true;
}
export function canPickStepContinue<T extends QuickPickStep>(
step: T,
state: PartialStepState,
selection: StepItemType<T> | Directive,
): selection is StepItemType<T> {
if (!canStepContinue(step, state, selection)) return false;
return false;
if (step.validate?.(selection) ?? true) {
state.counter++;
return true;
} }
export function canPickStepContinue<T extends QuickPickStep>(
step: T,
state: PartialStepState,
selection: StepItemType<T> | Directive,
): selection is StepItemType<T> {
if (!canStepContinue(step, state, selection)) return false;
return false;
}
if (step.validate?.(selection) ?? true) {
state.counter++;
return true;
export function canStepContinue<T extends QuickInputStep | QuickPickStep>(
step: T,
state: PartialStepState,
result: Directive | StepItemType<T>,
): result is StepItemType<T> {
if (result == null) return false;
if (isDirective(result)) {
switch (result) {
case Directive.Back:
state.counter--;
if (state.counter <= (state.startingStep ?? 0)) {
state.counter = 0;
}
break;
case Directive.Cancel:
endSteps(state);
break;
// case Directive.Noop:
// case Directive.RequiresVerification:
// case Directive.RequiresFreeSubscription:
// case Directive.RequiresProSubscription:
// break;
} }
return false; return false;
} }
export function canStepContinue<T extends QuickInputStep | QuickPickStep>(
step: T,
state: PartialStepState,
result: Directive | StepItemType<T>,
): result is StepItemType<T> {
if (result == null) return false;
if (isDirective(result)) {
switch (result) {
case Directive.Back:
state.counter--;
if (state.counter <= (state.startingStep ?? 0)) {
state.counter = 0;
}
break;
case Directive.Cancel:
endSteps(state);
break;
// case Directive.Noop:
// case Directive.RequiresVerification:
// case Directive.RequiresFreeSubscription:
// case Directive.RequiresProSubscription:
// break;
}
return false;
}
return true;
}
return true;
}
export function createConfirmStep<T extends QuickPickItem, Context extends { title: string }>(
title: string,
confirmations: T[],
context: Context,
cancel?: DirectiveQuickPickItem,
options: Partial<QuickPickStep<T>> = {},
): QuickPickStep<T> {
return createPickStep<T>({
placeholder: `Confirm ${context.title}`,
title: title,
ignoreFocusOut: true,
items: [...confirmations, cancel ?? createDirectiveQuickPickItem(Directive.Cancel)],
selectedItems: [confirmations.find(c => c.picked) ?? confirmations[0]],
...options,
});
}
export function createConfirmStep<T extends QuickPickItem, Context extends { title: string }>(
title: string,
confirmations: T[],
context: Context,
cancel?: DirectiveQuickPickItem,
options: Partial<QuickPickStep<T>> = {},
): QuickPickStep<T> {
return createPickStep<T>({
placeholder: `Confirm ${context.title}`,
title: title,
ignoreFocusOut: true,
items: [...confirmations, cancel ?? createDirectiveQuickPickItem(Directive.Cancel)],
selectedItems: [confirmations.find(c => c.picked) ?? confirmations[0]],
...options,
});
}
export function createInputStep(step: QuickInputStep): QuickInputStep {
// Make sure any input steps won't close on focus loss
step.ignoreFocusOut = true;
return step;
}
export function createInputStep(step: QuickInputStep): QuickInputStep {
// Make sure any input steps won't close on focus loss
step.ignoreFocusOut = true;
return step;
}
export function createPickStep<T extends QuickPickItem>(step: QuickPickStep<T>): QuickPickStep<T> {
return step;
}
export function createPickStep<T extends QuickPickItem>(step: QuickPickStep<T>): QuickPickStep<T> {
return step;
}
export function createCustomStep<T>(step: CustomStep<T>): CustomStep<T> {
return step;
}
export function createCustomStep<T>(step: CustomStep<T>): CustomStep<T> {
return step;
}
export function endSteps(state: PartialStepState) {
state.counter = -1;
}
export function endSteps(state: PartialStepState) {
state.counter = -1;
} }

Loading…
Cancel
Save