diff --git a/src/commands/git/branch.ts b/src/commands/git/branch.ts index 188d7c2..2db850a 100644 --- a/src/commands/git/branch.ts +++ b/src/commands/git/branch.ts @@ -19,6 +19,10 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + createConfirmStep, + createPickStep, + endSteps, inputBranchNameStep, pickBranchesStep, pickBranchOrTagStep, @@ -243,7 +247,7 @@ export class BranchGitCommand extends QuickCommand { state.name = undefined!; break; default: - QuickCommand.endSteps(state); + endSteps(state); break; } @@ -257,7 +261,7 @@ export class BranchGitCommand extends QuickCommand { } private *pickSubcommandStep(state: PartialStepState): StepResultGenerator { - const step = QuickCommand.createPickStep>({ + const step = createPickStep>({ title: this.title, placeholder: `Choose a ${this.label} command`, items: [ @@ -283,7 +287,7 @@ export class BranchGitCommand extends QuickCommand { buttons: [QuickInputButtons.Back], }); const selection: StepSelection = 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 { @@ -328,7 +332,7 @@ export class BranchGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); if (state.flags.includes('--switch')) { await state.repo.switch(state.reference.ref, { createBranch: state.name }); } else { @@ -341,7 +345,7 @@ export class BranchGitCommand extends QuickCommand { state: CreateStepState, context: Context, ): StepResultGenerator { - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ createFlagsQuickPickItem(state.flags, [], { @@ -361,7 +365,7 @@ export class BranchGitCommand extends QuickCommand { context, ); const selection: StepSelection = 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 { @@ -404,7 +408,7 @@ export class BranchGitCommand extends QuickCommand { state.flags = result; - QuickCommand.endSteps(state); + endSteps(state); state.repo.branchDelete(state.references, { force: state.flags.includes('--force'), remote: state.flags.includes('--remotes'), @@ -455,13 +459,13 @@ export class BranchGitCommand extends QuickCommand { } } - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), confirmations, context, ); const selection: StepSelection = 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 { @@ -500,7 +504,7 @@ export class BranchGitCommand extends QuickCommand { state.flags = result; - QuickCommand.endSteps(state); + endSteps(state); state.repo.branch(...state.flags, state.reference.ref, state.name); } } @@ -509,7 +513,7 @@ export class BranchGitCommand extends QuickCommand { state: RenameStepState, context: Context, ): StepResultGenerator { - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ createFlagsQuickPickItem(state.flags, ['-m'], { @@ -520,6 +524,6 @@ export class BranchGitCommand extends QuickCommand { context, ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/cherry-pick.ts b/src/commands/git/cherry-pick.ts index f161bcd..0400690 100644 --- a/src/commands/git/cherry-pick.ts +++ b/src/commands/git/cherry-pick.ts @@ -16,6 +16,9 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + createConfirmStep, + endSteps, pickBranchOrTagStep, pickCommitsStep, pickRepositoryStep, @@ -203,7 +206,7 @@ export class CherryPickGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); this.execute(state as CherryPickStepState>); } @@ -211,7 +214,7 @@ export class CherryPickGitCommand extends QuickCommand { } private *confirmStep(state: CherryPickStepState, context: Context): StepResultGenerator { - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ createFlagsQuickPickItem(state.flags, [], { @@ -238,6 +241,6 @@ export class CherryPickGitCommand extends QuickCommand { context, ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/coauthors.ts b/src/commands/git/coauthors.ts index 0dd1d1e..2d7a726 100644 --- a/src/commands/git/coauthors.ts +++ b/src/commands/git/coauthors.ts @@ -6,7 +6,7 @@ import { executeCoreCommand } from '../../system/command'; import { normalizePath } from '../../system/path'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { PartialStepState, StepGenerator, StepState } from '../quickCommand'; -import { pickContributorsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand'; +import { endSteps , pickContributorsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand'; interface Context { repos: Repository[]; @@ -154,7 +154,7 @@ export class CoAuthorsGitCommand extends QuickCommand { state.contributors = result; } - QuickCommand.endSteps(state); + endSteps(state); void this.execute(state as CoAuthorStepState); } diff --git a/src/commands/git/fetch.ts b/src/commands/git/fetch.ts index eec6767..04ea481 100644 --- a/src/commands/git/fetch.ts +++ b/src/commands/git/fetch.ts @@ -17,7 +17,15 @@ import type { StepSelection, StepState, } from '../quickCommand'; -import { appendReposToTitle, pickRepositoriesStep, QuickCommand, StepResult } from '../quickCommand'; +import { + appendReposToTitle, + canPickStepContinue, + createConfirmStep, + endSteps, + pickRepositoriesStep, + QuickCommand, + StepResult, +} from '../quickCommand'; interface Context { repos: Repository[]; @@ -122,7 +130,7 @@ export class FetchGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); void this.execute(state as FetchStepState); } @@ -156,7 +164,7 @@ export class FetchGitCommand extends QuickCommand { ? `$(repo) ${state.repos[0].formattedName}` : `${state.repos.length} repositories`; - step = QuickCommand.createConfirmStep( + step = createConfirmStep( appendReposToTitle(`Confirm ${this.title}`, state, context, lastFetchedOn), [ createFlagsQuickPickItem(state.flags, [], { @@ -184,6 +192,6 @@ export class FetchGitCommand extends QuickCommand { } const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/log.ts b/src/commands/git/log.ts index 25db34a..07b4d55 100644 --- a/src/commands/git/log.ts +++ b/src/commands/git/log.ts @@ -10,7 +10,7 @@ import { pad } from '../../system/string'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import { getSteps } from '../gitCommands.utils'; 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 { repos: Repository[]; @@ -213,7 +213,7 @@ export class LogGitCommand extends QuickCommand { state.counter--; if (result === StepResult.Break) { - QuickCommand.endSteps(state); + endSteps(state); } } diff --git a/src/commands/git/merge.ts b/src/commands/git/merge.ts index c33a5ac..78b6f56 100644 --- a/src/commands/git/merge.ts +++ b/src/commands/git/merge.ts @@ -4,7 +4,7 @@ import type { GitLog } from '../../git/models/log'; import { GitReference, GitRevision } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; 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 { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; @@ -19,6 +19,8 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + endSteps, pickBranchOrTagStep, pickCommitStep, pickRepositoryStep, @@ -200,7 +202,7 @@ export class MergeGitCommand extends QuickCommand { state.flags = result; - QuickCommand.endSteps(state); + endSteps(state); this.execute(state as MergeStepState); } @@ -224,7 +226,7 @@ export class MergeGitCommand extends QuickCommand { }), ); const selection: StepSelection = yield step; - QuickCommand.canPickStepContinue(step, state, selection); + canPickStepContinue(step, state, selection); return StepResult.Break; } @@ -271,6 +273,6 @@ export class MergeGitCommand extends QuickCommand { ], ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/pull.ts b/src/commands/git/pull.ts index 6992673..a3a0462 100644 --- a/src/commands/git/pull.ts +++ b/src/commands/git/pull.ts @@ -21,6 +21,8 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + endSteps, pickRepositoriesStep, QuickCommand, QuickCommandButtons, @@ -135,7 +137,7 @@ export class PullGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); void this.execute(state as PullStepState); } @@ -246,6 +248,6 @@ export class PullGitCommand extends QuickCommand { } const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/push.ts b/src/commands/git/push.ts index 02f59ae..5428653 100644 --- a/src/commands/git/push.ts +++ b/src/commands/git/push.ts @@ -22,6 +22,8 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + endSteps, pickRepositoriesStep, pickRepositoryStep, QuickCommand, @@ -150,7 +152,7 @@ export class PushGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); void this.execute(state as State); } @@ -410,6 +412,6 @@ export class PushGitCommand extends QuickCommand { } const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/rebase.ts b/src/commands/git/rebase.ts index 2a32304..bd58b9a 100644 --- a/src/commands/git/rebase.ts +++ b/src/commands/git/rebase.ts @@ -4,7 +4,7 @@ import type { GitLog } from '../../git/models/log'; import { GitReference, GitRevision } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; 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 { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; @@ -20,6 +20,8 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + endSteps, pickBranchOrTagStep, pickCommitStep, pickRepositoryStep, @@ -209,7 +211,7 @@ export class RebaseGitCommand extends QuickCommand { state.flags = result; - QuickCommand.endSteps(state); + endSteps(state); void this.execute(state as RebaseStepState); } @@ -236,7 +238,7 @@ export class RebaseGitCommand extends QuickCommand { }), ); const selection: StepSelection = yield step; - QuickCommand.canPickStepContinue(step, state, selection); + canPickStepContinue(step, state, selection); return StepResult.Break; } @@ -260,6 +262,6 @@ export class RebaseGitCommand extends QuickCommand { ], ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/remote.ts b/src/commands/git/remote.ts index 19d60bb..4508654 100644 --- a/src/commands/git/remote.ts +++ b/src/commands/git/remote.ts @@ -21,6 +21,10 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + createConfirmStep, + createPickStep, + endSteps, inputRemoteNameStep, inputRemoteUrlStep, pickRemoteStep, @@ -233,7 +237,7 @@ export class RemoteGitCommand extends QuickCommand { yield* this.removeCommandSteps(state, context); break; default: - QuickCommand.endSteps(state); + endSteps(state); break; } @@ -247,7 +251,7 @@ export class RemoteGitCommand extends QuickCommand { } private *pickSubcommandStep(state: PartialStepState): StepResultGenerator { - const step = QuickCommand.createPickStep>({ + const step = createPickStep>({ title: this.title, placeholder: `Choose a ${this.label} command`, items: [ @@ -273,7 +277,7 @@ export class RemoteGitCommand extends QuickCommand { buttons: [QuickInputButtons.Back], }); const selection: StepSelection = 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 { @@ -317,7 +321,7 @@ export class RemoteGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); await state.repo.addRemote(state.name, state.url, state.flags.includes('-f') ? { fetch: true } : undefined); if (state.reveal !== false) { @@ -330,7 +334,7 @@ export class RemoteGitCommand extends QuickCommand { } private *addCommandConfirmStep(state: AddStepState, context: Context): StepResultGenerator { - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ createFlagsQuickPickItem(state.flags, [], { @@ -346,7 +350,7 @@ export class RemoteGitCommand extends QuickCommand { context, ); const selection: StepSelection = 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 { @@ -379,7 +383,7 @@ export class RemoteGitCommand extends QuickCommand { const result = yield* this.removeCommandConfirmStep(state, context); if (result === StepResult.Break) continue; - QuickCommand.endSteps(state); + endSteps(state); try { await state.repo.removeRemote(state.remote.name); } catch (ex) { @@ -393,7 +397,7 @@ export class RemoteGitCommand extends QuickCommand { state: RemoveStepState>, context: Context, ): StepResultGenerator { - const step: QuickPickStep = QuickCommand.createConfirmStep( + const step: QuickPickStep = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ { @@ -404,7 +408,7 @@ export class RemoteGitCommand extends QuickCommand { context, ); const selection: StepSelection = 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 { @@ -435,7 +439,7 @@ export class RemoteGitCommand extends QuickCommand { const result = yield* this.pruneCommandConfirmStep(state, context); if (result === StepResult.Break) continue; - QuickCommand.endSteps(state); + endSteps(state); void state.repo.pruneRemote(state.remote.name); } } @@ -444,7 +448,7 @@ export class RemoteGitCommand extends QuickCommand { state: PruneStepState>, context: Context, ): StepResultGenerator { - const step: QuickPickStep = QuickCommand.createConfirmStep( + const step: QuickPickStep = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ { @@ -455,6 +459,6 @@ export class RemoteGitCommand extends QuickCommand { context, ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break; + return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break; } } diff --git a/src/commands/git/reset.ts b/src/commands/git/reset.ts index f510cb9..b77a793 100644 --- a/src/commands/git/reset.ts +++ b/src/commands/git/reset.ts @@ -15,7 +15,15 @@ import type { StepSelection, StepState, } from '../quickCommand'; -import { appendReposToTitle, pickCommitStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand'; +import { + appendReposToTitle, + canPickStepContinue, + endSteps, + pickCommitStep, + pickRepositoryStep, + QuickCommand, + StepResult, +} from '../quickCommand'; interface Context { repos: Repository[]; @@ -153,7 +161,7 @@ export class ResetGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); this.execute(state as ResetStepState); } @@ -187,6 +195,6 @@ export class ResetGitCommand extends QuickCommand { ], ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/revert.ts b/src/commands/git/revert.ts index 34cf288..68260c0 100644 --- a/src/commands/git/revert.ts +++ b/src/commands/git/revert.ts @@ -15,7 +15,15 @@ import type { StepSelection, StepState, } from '../quickCommand'; -import { appendReposToTitle, pickCommitsStep, pickRepositoryStep, QuickCommand, StepResult } from '../quickCommand'; +import { + appendReposToTitle, + canPickStepContinue, + endSteps, + pickCommitsStep, + pickRepositoryStep, + QuickCommand, + StepResult, +} from '../quickCommand'; interface Context { repos: Repository[]; @@ -157,7 +165,7 @@ export class RevertGitCommand extends QuickCommand { state.flags = result; - QuickCommand.endSteps(state); + endSteps(state); this.execute(state as RevertStepState>); } @@ -181,6 +189,6 @@ export class RevertGitCommand extends QuickCommand { ], ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/search.ts b/src/commands/git/search.ts index 9342a0f..49f821b 100644 --- a/src/commands/git/search.ts +++ b/src/commands/git/search.ts @@ -17,6 +17,9 @@ import { getSteps } from '../gitCommands.utils'; import type { PartialStepState, StepGenerator, StepResultGenerator, StepSelection, StepState } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + createPickStep, + endSteps, pickCommitStep, pickRepositoryStep, QuickCommand, @@ -266,7 +269,7 @@ export class SearchGitCommand extends QuickCommand { state.counter--; 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 matchRegexButton = new QuickCommandButtons.MatchRegexToggle(state.matchRegex); - const step = QuickCommand.createPickStep>({ + const step = createPickStep>({ title: appendReposToTitle(context.title, state, context), placeholder: 'e.g. "Updates dependencies" author:eamodio', matchOnDescription: true, @@ -386,7 +389,7 @@ export class SearchGitCommand extends QuickCommand { }, }); const selection: StepSelection = 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 state.counter--; return StepResult.Break; diff --git a/src/commands/git/show.ts b/src/commands/git/show.ts index 4d376ee..9a79102 100644 --- a/src/commands/git/show.ts +++ b/src/commands/git/show.ts @@ -8,7 +8,7 @@ import { CommandQuickPickItem } from '../../quickpicks/items/common'; import { GitCommandQuickPickItem } from '../../quickpicks/items/gitCommands'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { PartialStepState, StepGenerator } from '../quickCommand'; -import { +import { endSteps , pickCommitStep, pickRepositoryStep, QuickCommand, @@ -186,14 +186,14 @@ export class ShowGitCommand extends QuickCommand { const r = yield* result.executeSteps(this.pickedVia); state.counter--; if (r === StepResult.Break) { - QuickCommand.endSteps(state); + endSteps(state); } continue; } if (result instanceof CommandQuickPickItem && !(result instanceof CommitFilesQuickPickItem)) { - QuickCommand.endSteps(state); + endSteps(state); void result.execute(); break; @@ -236,7 +236,7 @@ export class ShowGitCommand extends QuickCommand { } if (result instanceof CommandQuickPickItem) { - QuickCommand.endSteps(state); + endSteps(state); void result.execute(); break; diff --git a/src/commands/git/stash.ts b/src/commands/git/stash.ts index 55c587a..af5a489 100644 --- a/src/commands/git/stash.ts +++ b/src/commands/git/stash.ts @@ -29,6 +29,12 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canInputStepContinue, + canPickStepContinue, + canStepContinue, + createInputStep, + createPickStep, + endSteps, pickRepositoryStep, pickStashStep, QuickCommand, @@ -219,7 +225,7 @@ export class StashGitCommand extends QuickCommand { yield* this.pushCommandSteps(state as PushStepState, context); break; default: - QuickCommand.endSteps(state); + endSteps(state); break; } @@ -233,7 +239,7 @@ export class StashGitCommand extends QuickCommand { } private *pickSubcommandStep(state: PartialStepState): StepResultGenerator { - const step = QuickCommand.createPickStep>({ + const step = createPickStep>({ title: this.title, placeholder: `Choose a ${this.label} command`, items: [ @@ -273,7 +279,7 @@ export class StashGitCommand extends QuickCommand { buttons: [QuickInputButtons.Back], }); const selection: StepSelection = 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 { @@ -300,7 +306,7 @@ export class StashGitCommand extends QuickCommand { state.subcommand = result; } - QuickCommand.endSteps(state); + endSteps(state); try { await state.repo.stashApply( @@ -382,7 +388,7 @@ export class StashGitCommand extends QuickCommand { }, ); const selection: StepSelection = 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 { @@ -403,7 +409,7 @@ export class StashGitCommand extends QuickCommand { const result = yield* this.dropCommandConfirmStep(state, context); if (result === StepResult.Break) continue; - QuickCommand.endSteps(state); + endSteps(state); try { // drop can only take a stash index, e.g. `stash@{1}` await state.repo.stashDelete(`stash@{${state.reference.number}}`, state.reference.ref); @@ -446,7 +452,7 @@ export class StashGitCommand extends QuickCommand { }, ); const selection: StepSelection = 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 { @@ -479,7 +485,7 @@ export class StashGitCommand extends QuickCommand { ); state.counter--; if (result === StepResult.Break) { - QuickCommand.endSteps(state); + endSteps(state); } } } @@ -510,7 +516,7 @@ export class StashGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); try { await state.repo.stashSave(state.message, state.uris, { includeUntracked: state.flags.includes('--include-untracked'), @@ -537,7 +543,7 @@ export class StashGitCommand extends QuickCommand { state: PushStepState, context: Context, ): AsyncStepResultGenerator { - const step = QuickCommand.createInputStep({ + const step = createInputStep({ title: appendReposToTitle( context.title, state, @@ -556,10 +562,7 @@ export class StashGitCommand extends QuickCommand { }); const value: StepSelection = 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; } @@ -608,6 +611,6 @@ export class StashGitCommand extends QuickCommand { { placeholder: `Confirm ${context.title}` }, ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/status.ts b/src/commands/git/status.ts index a8851f5..2f93ede 100644 --- a/src/commands/git/status.ts +++ b/src/commands/git/status.ts @@ -8,7 +8,7 @@ import { GitCommandQuickPickItem } from '../../quickpicks/items/gitCommands'; import { pad } from '../../system/string'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { PartialStepState, StepGenerator, StepState } from '../quickCommand'; -import { pickRepositoryStep, QuickCommand, showRepositoryStatusStep, StepResult } from '../quickCommand'; +import { endSteps, pickRepositoryStep, QuickCommand, showRepositoryStatusStep, StepResult } from '../quickCommand'; interface Context { repos: Repository[]; @@ -109,14 +109,14 @@ export class StatusGitCommand extends QuickCommand { const r = yield* result.executeSteps(this.pickedVia); state.counter--; if (r === StepResult.Break) { - QuickCommand.endSteps(state); + endSteps(state); } continue; } if (result instanceof CommandQuickPickItem) { - QuickCommand.endSteps(state); + endSteps(state); void result.execute(); break; diff --git a/src/commands/git/switch.ts b/src/commands/git/switch.ts index 7ed2abc..2cf42cb 100644 --- a/src/commands/git/switch.ts +++ b/src/commands/git/switch.ts @@ -16,6 +16,8 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canPickStepContinue, + endSteps, inputBranchNameStep, pickBranchOrTagStepMultiRepo, pickRepositoriesStep, @@ -191,7 +193,7 @@ export class SwitchGitCommand extends QuickCommand { } } - QuickCommand.endSteps(state); + endSteps(state); void this.execute(state as SwitchStepState); } @@ -244,6 +246,6 @@ export class SwitchGitCommand extends QuickCommand { { placeholder: `Confirm ${context.title}` }, ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/git/tag.ts b/src/commands/git/tag.ts index cc748ae..3a9e0fc 100644 --- a/src/commands/git/tag.ts +++ b/src/commands/git/tag.ts @@ -20,6 +20,13 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canInputStepContinue, + canPickStepContinue, + canStepContinue, + createConfirmStep, + createInputStep, + createPickStep, + endSteps, inputTagNameStep, pickBranchOrTagStep, pickRepositoryStep, @@ -186,7 +193,7 @@ export class TagGitCommand extends QuickCommand { yield* this.deleteCommandSteps(state as DeleteStepState, context); break; default: - QuickCommand.endSteps(state); + endSteps(state); break; } @@ -200,7 +207,7 @@ export class TagGitCommand extends QuickCommand { } private *pickSubcommandStep(state: PartialStepState): StepResultGenerator { - const step = QuickCommand.createPickStep>({ + const step = createPickStep>({ title: this.title, placeholder: `Choose a ${this.label} command`, items: [ @@ -220,7 +227,7 @@ export class TagGitCommand extends QuickCommand { buttons: [QuickInputButtons.Back], }); const selection: StepSelection = 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 { @@ -272,7 +279,7 @@ export class TagGitCommand extends QuickCommand { state.flags = result; } - QuickCommand.endSteps(state); + endSteps(state); state.repo.tag( ...state.flags, ...(state.message.length !== 0 ? [`"${state.message}"`] : []), @@ -286,7 +293,7 @@ export class TagGitCommand extends QuickCommand { state: CreateStepState, context: Context, ): AsyncStepResultGenerator { - const step = QuickCommand.createInputStep({ + const step = createInputStep({ title: appendReposToTitle( `${context.title} at ${GitReference.toString(state.reference, { capitalize: true, icon: false })}`, state, @@ -299,10 +306,7 @@ export class TagGitCommand extends QuickCommand { const value: StepSelection = 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; } @@ -313,7 +317,7 @@ export class TagGitCommand extends QuickCommand { state: CreateStepState, context: Context, ): StepResultGenerator { - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ createFlagsQuickPickItem(state.flags, state.message.length !== 0 ? ['-m'] : [], { @@ -336,7 +340,7 @@ export class TagGitCommand extends QuickCommand { context, ); const selection: StepSelection = 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 { @@ -363,7 +367,7 @@ export class TagGitCommand extends QuickCommand { const result = yield* this.deleteCommandConfirmStep(state, context); if (result === StepResult.Break) continue; - QuickCommand.endSteps(state); + endSteps(state); state.repo.tagDelete(state.references); } } @@ -372,7 +376,7 @@ export class TagGitCommand extends QuickCommand { state: DeleteStepState, context: Context, ): StepResultGenerator { - const step: QuickPickStep = QuickCommand.createConfirmStep( + const step: QuickPickStep = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ { @@ -383,6 +387,6 @@ export class TagGitCommand extends QuickCommand { context, ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break; + return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break; } } diff --git a/src/commands/git/worktree.ts b/src/commands/git/worktree.ts index fe61fe8..61bfe96 100644 --- a/src/commands/git/worktree.ts +++ b/src/commands/git/worktree.ts @@ -36,6 +36,13 @@ import type { } from '../quickCommand'; import { appendReposToTitle, + canInputStepContinue, + canPickStepContinue, + canStepContinue, + createConfirmStep, + createCustomStep, + createPickStep, + endSteps, ensureAccessStep, inputBranchNameStep, pickBranchOrTagStep, @@ -238,7 +245,7 @@ export class WorktreeGitCommand extends QuickCommand { break; } default: - QuickCommand.endSteps(state); + endSteps(state); break; } @@ -252,7 +259,7 @@ export class WorktreeGitCommand extends QuickCommand { } private *pickSubcommandStep(state: PartialStepState): StepResultGenerator { - const step = QuickCommand.createPickStep>({ + const step = createPickStep>({ title: this.title, placeholder: `Choose a ${this.label} command`, items: [ @@ -278,7 +285,7 @@ export class WorktreeGitCommand extends QuickCommand { buttons: [QuickInputButtons.Back], }); const selection: StepSelection = 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 { @@ -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, options: { titleContext: string; defaultUri?: Uri }, ): AsyncStepResultGenerator { - const step = QuickCommand.createCustomStep({ + const step = createCustomStep({ show: async (_step: CustomStep) => { const hasDefault = options?.defaultUri != null; const result = await window.showInformationMessage( @@ -526,10 +533,7 @@ export class WorktreeGitCommand extends QuickCommand { const value: StepSelection = 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; } @@ -587,7 +591,7 @@ export class WorktreeGitCommand extends QuickCommand { const isRemoteBranch = state.reference?.refType === 'branch' && state.reference?.remote; - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle( `Confirm ${context.title} \u2022 ${GitReference.toString(state.reference, { icon: false, @@ -650,7 +654,7 @@ export class WorktreeGitCommand extends QuickCommand { context, ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) + return canPickStepContinue(step, state, selection) ? [selection[0].context, selection[0].item] : StepResult.Break; } @@ -685,7 +689,7 @@ export class WorktreeGitCommand extends QuickCommand { state.flags = result; - QuickCommand.endSteps(state); + endSteps(state); for (const uri of state.uris) { let retry = false; @@ -743,7 +747,7 @@ export class WorktreeGitCommand extends QuickCommand { } private *deleteCommandConfirmStep(state: DeleteStepState, context: Context): StepResultGenerator { - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ createFlagsQuickPickItem(state.flags, [], { @@ -766,7 +770,7 @@ export class WorktreeGitCommand extends QuickCommand { ); const selection: StepSelection = 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 { @@ -798,7 +802,7 @@ export class WorktreeGitCommand extends QuickCommand { state.flags = result; - QuickCommand.endSteps(state); + endSteps(state); const worktree = context.worktrees.find(wt => wt.uri.toString() === state.uri.toString())!; if (state.flags.includes('--reveal-explorer')) { @@ -814,7 +818,7 @@ export class WorktreeGitCommand extends QuickCommand { } private *openCommandConfirmStep(state: OpenStepState, context: Context): StepResultGenerator { - const step: QuickPickStep> = QuickCommand.createConfirmStep( + const step: QuickPickStep> = createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ createFlagsQuickPickItem(state.flags, [], { @@ -840,6 +844,6 @@ export class WorktreeGitCommand extends QuickCommand { ); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break; } } diff --git a/src/commands/gitCommands.ts b/src/commands/gitCommands.ts index 1429a5d..0a5d450 100644 --- a/src/commands/gitCommands.ts +++ b/src/commands/gitCommands.ts @@ -31,8 +31,8 @@ import type { SwitchGitCommandArgs } from './git/switch'; import type { TagGitCommandArgs } from './git/tag'; import type { WorktreeGitCommandArgs } from './git/worktree'; 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'; const sanitizeLabel = /\$\(.+?\)|\s/g; @@ -538,7 +538,7 @@ export class GitCommandsCommand extends Command { let activeCommand; if (commandsStep.command == null && quickpick.activeItems.length !== 0) { const active = quickpick.activeItems[0]; - if (QuickCommand.is(active)) { + if (isQuickCommand(active)) { activeCommand = active; } } @@ -657,7 +657,7 @@ export class GitCommandsCommand extends Command { if (commandsStep.command != null || quickpick.activeItems.length === 0) return; const command = quickpick.activeItems[0]; - if (!QuickCommand.is(command)) return; + if (!isQuickCommand(command)) return; quickpick.buttons = this.getButtons(undefined, command); }), @@ -744,7 +744,7 @@ export class GitCommandsCommand extends Command { if (commandsStep.command == null) { const [command] = items; - if (!QuickCommand.is(command)) return; + if (!isQuickCommand(command)) return; commandsStep.setCommand(command, this.startedWith); } diff --git a/src/commands/quickCommand.steps.ts b/src/commands/quickCommand.steps.ts index 39a6dfe..25d112e 100644 --- a/src/commands/quickCommand.steps.ts +++ b/src/commands/quickCommand.steps.ts @@ -99,7 +99,16 @@ import type { StepSelection, StepState, } from './quickCommand'; -import { QuickCommand, QuickCommandButtons, StepResult } from './quickCommand'; +import { + canInputStepContinue, + canPickStepContinue, + canStepContinue, + createInputStep, + createPickStep, + endSteps, + QuickCommandButtons, + StepResult, +} from './quickCommand'; export function appendReposToTitle< State extends { repo: Repository } | { repos: Repository[] }, @@ -485,7 +494,7 @@ export async function* inputBranchNameStep< context: Context, options: { placeholder: string; titleContext?: string; value?: string }, ): AsyncStepResultGenerator { - const step = QuickCommand.createInputStep({ + const step = createInputStep({ title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), placeholder: options.placeholder, value: options.value, @@ -515,10 +524,7 @@ export async function* inputBranchNameStep< }); const value: StepSelection = 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; } @@ -533,7 +539,7 @@ export async function* inputRemoteNameStep< context: Context, options: { placeholder: string; titleContext?: string; value?: string }, ): AsyncStepResultGenerator { - const step = QuickCommand.createInputStep({ + const step = createInputStep({ title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), placeholder: options.placeholder, value: options.value, @@ -559,10 +565,7 @@ export async function* inputRemoteNameStep< }); const value: StepSelection = 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; } @@ -577,7 +580,7 @@ export async function* inputRemoteUrlStep< context: Context, options: { placeholder: string; titleContext?: string; value?: string }, ): AsyncStepResultGenerator { - const step = QuickCommand.createInputStep({ + const step = createInputStep({ title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), placeholder: options.placeholder, value: options.value, @@ -594,10 +597,7 @@ export async function* inputRemoteUrlStep< }); const value: StepSelection = 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; } @@ -612,7 +612,7 @@ export async function* inputTagNameStep< context: Context, options: { placeholder: string; titleContext?: string; value?: string }, ): AsyncStepResultGenerator { - const step = QuickCommand.createInputStep({ + const step = createInputStep({ title: appendReposToTitle(`${context.title}${options.titleContext ?? ''}`, state, context), placeholder: options.placeholder, value: options.value, @@ -642,10 +642,7 @@ export async function* inputTagNameStep< }); const value: StepSelection = 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; } @@ -676,7 +673,7 @@ export async function* pickBranchStep< picked: picked, }); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder, matchOnDetail: true, @@ -701,7 +698,7 @@ export async function* pickBranchStep< }, }); const selection: StepSelection = 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< @@ -731,7 +728,7 @@ export async function* pickBranchesStep< sort: sort, }); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ multiselect: branches.length !== 0, title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: branches.length === 0 ? `No branches found in ${state.repo.formattedName}` : placeholder, @@ -757,7 +754,7 @@ export async function* pickBranchesStep< }, }); const selection: StepSelection = 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< @@ -801,7 +798,7 @@ export async function* pickBranchOrTagStep< }; const branchesAndOrTags = await getBranchesAndOrTagsFn(); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: branchesAndOrTags.length === 0 @@ -872,7 +869,7 @@ export async function* pickBranchOrTagStep< onValidateValue: getValidateGitReferenceFn(state.repo, { ranges: ranges }), }); const selection: StepSelection = 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< @@ -910,7 +907,7 @@ export async function* pickBranchOrTagStepMultiRepo< }; const branchesAndOrTags = await getBranchesAndOrTagsFn(); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: branchesAndOrTags.length === 0 @@ -986,7 +983,7 @@ export async function* pickBranchOrTagStepMultiRepo< }); const selection: StepSelection = 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< @@ -1038,7 +1035,7 @@ export async function* pickCommitStep< ]; } - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log), ignoreFocusOut: ignoreFocusOut, @@ -1111,10 +1108,10 @@ export async function* pickCommitStep< }), }); const selection: StepSelection = yield step; - if (!QuickCommand.canPickStepContinue(step, state, selection)) return StepResult.Break; + if (!canPickStepContinue(step, state, selection)) return StepResult.Break; if (CommandQuickPickItem.is(selection[0])) { - QuickCommand.endSteps(state); + endSteps(state); await selection[0].execute(); return StepResult.Break; @@ -1164,7 +1161,7 @@ export function* pickCommitsStep< ]; } - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), multiselect: log != null, placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log), @@ -1215,7 +1212,7 @@ export function* pickCommitsStep< }, }); const selection: StepSelection = 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< @@ -1228,7 +1225,7 @@ export async function* pickContributorsStep< ): AsyncStepResultGenerator { const message = (await Container.instance.git.getOrOpenScmRepository(state.repo.path))?.inputBox.value; - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(context.title, state, context), allowEmpty: true, multiselect: true, @@ -1256,7 +1253,7 @@ export async function* pickContributorsStep< }, }); const selection: StepSelection = 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< @@ -1283,7 +1280,7 @@ export async function* pickRemoteStep< picked: picked, }); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder, matchOnDetail: true, @@ -1308,7 +1305,7 @@ export async function* pickRemoteStep< }, }); const selection: StepSelection = 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< @@ -1335,7 +1332,7 @@ export async function* pickRemotesStep< picked: picked, }); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ multiselect: remotes.length !== 0, title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: remotes.length === 0 ? `No remotes found in ${state.repo.formattedName}` : placeholder, @@ -1361,7 +1358,7 @@ export async function* pickRemotesStep< }, }); const selection: StepSelection = 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< @@ -1374,7 +1371,7 @@ export async function* pickRepositoryStep< } const active = state.repo ?? (await Container.instance.git.getOrOpenRepositoryForEditor()); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: context.title, placeholder: placeholder, items: @@ -1411,7 +1408,7 @@ export async function* pickRepositoryStep< }, }); const selection: StepSelection = 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< @@ -1439,7 +1436,7 @@ export async function* pickRepositoriesStep< actives = active != null ? [active] : []; } - const step = QuickCommand.createPickStep({ + const step = createPickStep({ multiselect: true, title: context.title, placeholder: options.placeholder, @@ -1481,7 +1478,7 @@ export async function* pickRepositoriesStep< }, }); const selection: StepSelection = 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< @@ -1504,7 +1501,7 @@ export function* pickStashStep< titleContext?: string; }, ): StepResultGenerator { - const step = QuickCommand.createPickStep>({ + const step = createPickStep>({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, stash), ignoreFocusOut: ignoreFocusOut, @@ -1540,7 +1537,7 @@ export function* pickStashStep< }, }); const selection: StepSelection = 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< @@ -1567,7 +1564,7 @@ export async function* pickTagsStep< picked: picked, }); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ multiselect: tags.length !== 0, title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: tags.length === 0 ? `No tags found in ${state.repo.formattedName}` : placeholder, @@ -1597,7 +1594,7 @@ export async function* pickTagsStep< }, }); const selection: StepSelection = 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< @@ -1627,7 +1624,7 @@ export async function* pickWorktreeStep< picked: picked, }); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder, matchOnDetail: true, @@ -1657,7 +1654,7 @@ export async function* pickWorktreeStep< }, }); const selection: StepSelection = 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< @@ -1687,7 +1684,7 @@ export async function* pickWorktreesStep< picked: picked, }); - const step = QuickCommand.createPickStep({ + const step = createPickStep({ multiselect: worktrees.length !== 0, title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context), placeholder: worktrees.length === 0 ? `No worktrees found in ${state.repo.formattedName}` : placeholder, @@ -1718,7 +1715,7 @@ export async function* pickWorktreesStep< }, }); const selection: StepSelection = 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< @@ -1729,7 +1726,7 @@ export async function* showCommitOrStashStep< context: Context, ): AsyncStepResultGenerator { const step: QuickPickStep = - QuickCommand.createPickStep({ + createPickStep({ title: appendReposToTitle( GitReference.toString(state.reference, { capitalize: true, @@ -1779,7 +1776,7 @@ export async function* showCommitOrStashStep< }, }); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break; } async function getShowCommitOrStashStepItems< @@ -2003,7 +2000,7 @@ export function* showCommitOrStashFilesStep< debugger; } - const step: QuickPickStep = QuickCommand.createPickStep({ + const step: QuickPickStep = createPickStep({ title: appendReposToTitle( GitReference.toString(state.reference, { capitalize: true, @@ -2063,7 +2060,7 @@ export function* showCommitOrStashFilesStep< }, }); const selection: StepSelection = 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< @@ -2074,7 +2071,7 @@ export async function* showCommitOrStashFileStep< }, Context extends { repos: Repository[]; title: string }, >(state: State, context: Context): AsyncStepResultGenerator { - const step: QuickPickStep = QuickCommand.createPickStep({ + const step: QuickPickStep = createPickStep({ title: appendReposToTitle( GitReference.toString(state.reference, { capitalize: true, @@ -2130,7 +2127,7 @@ export async function* showCommitOrStashFileStep< }, }); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break; } async function getShowCommitOrStashFileStepItems< @@ -2242,7 +2239,7 @@ export function* showRepositoryStatusStep< >(state: State, context: Context): StepResultGenerator { const upstream = context.status.getUpstreamStatus({ expand: true, separator: ', ' }); const working = context.status.getFormattedDiffStatus({ expand: true, separator: ', ' }); - const step: QuickPickStep = QuickCommand.createPickStep({ + const step: QuickPickStep = createPickStep({ title: appendReposToTitle(context.title, state, context), placeholder: `${upstream ? `${upstream}, ${working}` : working}`, //'Changes to be committed', ignoreFocusOut: true, @@ -2255,7 +2252,7 @@ export function* showRepositoryStatusStep< }, }); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break; + return canPickStepContinue(step, state, selection) ? selection[0] : StepResult.Break; } function getShowRepositoryStatusStepItems< @@ -2415,12 +2412,12 @@ export async function* ensureAccessStep< } } - const step = QuickCommand.createPickStep({ + const step = createPickStep({ title: appendReposToTitle(context.title, state, context), placeholder: placeholder, items: [...directives, createDirectiveQuickPickItem(Directive.Cancel)], }); const selection: StepSelection = yield step; - return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break; + return canPickStepContinue(step, state, selection) ? undefined : StepResult.Break; } diff --git a/src/commands/quickCommand.ts b/src/commands/quickCommand.ts index 4024109..6d62d31 100644 --- a/src/commands/quickCommand.ts +++ b/src/commands/quickCommand.ts @@ -3,7 +3,7 @@ import { configuration } from '../configuration'; import type { Container } from '../container'; import type { Keys } from '../keyboard'; 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.steps'; @@ -243,7 +243,7 @@ export abstract class QuickCommand implements QuickPickItem { cancel?: DirectiveQuickPickItem, options: Partial> = {}, ): QuickPickStep { - return QuickCommand.createConfirmStep(title, confirmations, { title: this.title }, cancel, options); + return createConfirmStep(title, confirmations, { title: this.title }, cancel, options); } protected getStepState(limitBackNavigation: boolean): PartialStepState { @@ -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( + step: T, + state: PartialStepState, + value: Directive | StepItemType, +) { + if (!canStepContinue(step, state, value)) return false; + + const [valid] = (await step.validate?.(value)) ?? [true]; + if (valid) { + state.counter++; + return true; } - export async function canInputStepContinue( - step: T, - state: PartialStepState, - value: Directive | StepItemType, - ) { - 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( + step: T, + state: PartialStepState, + selection: StepItemType | Directive, +): selection is StepItemType { + if (!canStepContinue(step, state, selection)) return false; - return false; + if (step.validate?.(selection) ?? true) { + state.counter++; + return true; } - export function canPickStepContinue( - step: T, - state: PartialStepState, - selection: StepItemType | Directive, - ): selection is StepItemType { - if (!canStepContinue(step, state, selection)) return false; + return false; +} - if (step.validate?.(selection) ?? true) { - state.counter++; - return true; +export function canStepContinue( + step: T, + state: PartialStepState, + result: Directive | StepItemType, +): result is StepItemType { + 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; } - export function canStepContinue( - step: T, - state: PartialStepState, - result: Directive | StepItemType, - ): result is StepItemType { - 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( - title: string, - confirmations: T[], - context: Context, - cancel?: DirectiveQuickPickItem, - options: Partial> = {}, - ): QuickPickStep { - return createPickStep({ - 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( + title: string, + confirmations: T[], + context: Context, + cancel?: DirectiveQuickPickItem, + options: Partial> = {}, +): QuickPickStep { + return createPickStep({ + 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(step: QuickPickStep): QuickPickStep { - return step; - } +export function createPickStep(step: QuickPickStep): QuickPickStep { + return step; +} - export function createCustomStep(step: CustomStep): CustomStep { - return step; - } +export function createCustomStep(step: CustomStep): CustomStep { + return step; +} - export function endSteps(state: PartialStepState) { - state.counter = -1; - } +export function endSteps(state: PartialStepState) { + state.counter = -1; }